Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a81fef3c7d | ||
|
|
365732b5d4 | ||
|
|
98603077e3 | ||
|
|
bc9f847689 | ||
|
|
71cdf2d988 | ||
|
|
4fea3becf6 |
Generated
+2
@@ -81,6 +81,8 @@ dependencies = [
|
|||||||
"asic-rs",
|
"asic-rs",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"measurements",
|
"measurements",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
"wx-rs",
|
"wx-rs",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -17,3 +17,5 @@ asic-rs = "0.8.1"
|
|||||||
measurements = "0.11"
|
measurements = "0.11"
|
||||||
tokio = { version = "1", features = ["rt"] }
|
tokio = { version = "1", features = ["rt"] }
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1"
|
||||||
|
|||||||
@@ -106,6 +106,37 @@ impl Board {
|
|||||||
tuning: self.mining,
|
tuning: self.mining,
|
||||||
firmware_flash,
|
firmware_flash,
|
||||||
},
|
},
|
||||||
|
// Demo values for the round-8 columns (synthetic, so the columns
|
||||||
|
// show variety offline).
|
||||||
|
control_board: if self.model.contains("S17") {
|
||||||
|
"Xilinx".to_string()
|
||||||
|
} else if self.model.contains("S19j") || self.model.contains("S19k") {
|
||||||
|
"AMLogic".to_string()
|
||||||
|
} else if self.model.contains("S19") {
|
||||||
|
"BeagleBone Black".to_string()
|
||||||
|
} else if self.model.contains("S21") {
|
||||||
|
"CVITek".to_string()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
},
|
||||||
|
pic_present: if self.model.contains("S21") {
|
||||||
|
Some(false) // noPIC example
|
||||||
|
} else if self.model.starts_with("Antminer") {
|
||||||
|
Some(true)
|
||||||
|
} else {
|
||||||
|
None // WhatsMiner: unknown over the network
|
||||||
|
},
|
||||||
|
// Access: idle/view-only units (no worker) shown locked; the rest
|
||||||
|
// unlocked. (Live rows infer this from control capabilities.)
|
||||||
|
write_locked: Some(self.worker.is_empty()),
|
||||||
|
errors: if self.model.contains("S21 Pro") {
|
||||||
|
vec![
|
||||||
|
"[Warning] hashrate 70% below expected".to_string(),
|
||||||
|
"[Warning] chip temperature high (HashBoard 2)".to_string(),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
mod credentials;
|
mod credentials;
|
||||||
mod fixtures;
|
mod fixtures;
|
||||||
mod model;
|
mod model;
|
||||||
|
mod presets;
|
||||||
mod scan;
|
mod scan;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
|||||||
@@ -212,6 +212,18 @@ impl MinerCaps {
|
|||||||
pub fn is_empty(self) -> bool {
|
pub fn is_empty(self) -> bool {
|
||||||
self == MinerCaps::default()
|
self == MinerCaps::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the miner exposes any writable control action at all. Used to
|
||||||
|
/// infer the "Access" (locked/unlocked) column: no control -> view-only.
|
||||||
|
pub fn any_control(self) -> bool {
|
||||||
|
self.fault_light
|
||||||
|
|| self.restart
|
||||||
|
|| self.pause
|
||||||
|
|| self.resume
|
||||||
|
|| self.power_limit
|
||||||
|
|| self.tuning
|
||||||
|
|| self.firmware_flash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the
|
/// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the
|
||||||
@@ -231,6 +243,19 @@ pub struct MinerRow {
|
|||||||
pub firmware: String,
|
pub firmware: String,
|
||||||
pub api_version: String,
|
pub api_version: String,
|
||||||
pub control_board: String,
|
pub control_board: String,
|
||||||
|
/// Whether the hashboards carry a PIC MCU. asic-rs does not report this over
|
||||||
|
/// the network, so it is a best-effort inference (model-string heuristic):
|
||||||
|
/// `None` = unknown, `Some(true)` = PIC, `Some(false)` = noPIC. True
|
||||||
|
/// detection needs an on-board SSH/I2C probe (a separate feature).
|
||||||
|
pub pic_present: Option<bool>,
|
||||||
|
/// Whether this miner is locked to view-only (no command writes). Inferred
|
||||||
|
/// from whether any control capability is available: `None` = unknown,
|
||||||
|
/// `Some(true)` = locked, `Some(false)` = unlocked/writable.
|
||||||
|
pub write_locked: Option<bool>,
|
||||||
|
/// Structured error/event lines from the miner (severity + text), most
|
||||||
|
/// severe first. Empty means none. The Error column shows a summary; the
|
||||||
|
/// full list is the hover tooltip (added with the tooltip bridge support).
|
||||||
|
pub errors: Vec<String>,
|
||||||
// performance
|
// performance
|
||||||
pub hashrate_ths: f64,
|
pub hashrate_ths: f64,
|
||||||
pub expected_ths: f64,
|
pub expected_ths: f64,
|
||||||
@@ -320,7 +345,7 @@ pub fn flash_confirmed(input: &str) -> bool {
|
|||||||
/// Model columns. Ip is fixed (always shown first); the rest map 1:1 to a
|
/// Model columns. Ip is fixed (always shown first); the rest map 1:1 to a
|
||||||
/// scannable metric and can be shown/hidden/reordered. Row selection replaces
|
/// scannable metric and can be shown/hidden/reordered. Row selection replaces
|
||||||
/// the old checkbox column.
|
/// the old checkbox column.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum Column {
|
pub enum Column {
|
||||||
Ip,
|
Ip,
|
||||||
Hashrate,
|
Hashrate,
|
||||||
@@ -344,6 +369,9 @@ pub enum Column {
|
|||||||
Serial,
|
Serial,
|
||||||
ApiVersion,
|
ApiVersion,
|
||||||
ControlBoard,
|
ControlBoard,
|
||||||
|
Pic,
|
||||||
|
Locked,
|
||||||
|
Error,
|
||||||
Uptime,
|
Uptime,
|
||||||
Light,
|
Light,
|
||||||
OperatingState,
|
OperatingState,
|
||||||
@@ -361,7 +389,7 @@ pub enum Column {
|
|||||||
|
|
||||||
/// Every column, in registry order. Ip first, then the default-visible set
|
/// Every column, in registry order. Ip first, then the default-visible set
|
||||||
/// (UI-SPEC order), then all remaining metrics.
|
/// (UI-SPEC order), then all remaining metrics.
|
||||||
pub const ALL_COLUMNS: [Column; 35] = [
|
pub const ALL_COLUMNS: [Column; 38] = [
|
||||||
Column::Ip,
|
Column::Ip,
|
||||||
Column::Hashrate,
|
Column::Hashrate,
|
||||||
Column::Power,
|
Column::Power,
|
||||||
@@ -384,6 +412,9 @@ pub const ALL_COLUMNS: [Column; 35] = [
|
|||||||
Column::Serial,
|
Column::Serial,
|
||||||
Column::ApiVersion,
|
Column::ApiVersion,
|
||||||
Column::ControlBoard,
|
Column::ControlBoard,
|
||||||
|
Column::Pic,
|
||||||
|
Column::Locked,
|
||||||
|
Column::Error,
|
||||||
Column::Uptime,
|
Column::Uptime,
|
||||||
Column::Light,
|
Column::Light,
|
||||||
Column::OperatingState,
|
Column::OperatingState,
|
||||||
@@ -436,8 +467,11 @@ impl Column {
|
|||||||
Column::Serial => "Serial",
|
Column::Serial => "Serial",
|
||||||
Column::ApiVersion => "API ver",
|
Column::ApiVersion => "API ver",
|
||||||
Column::ControlBoard => "Control board",
|
Column::ControlBoard => "Control board",
|
||||||
|
Column::Pic => "PIC",
|
||||||
|
Column::Locked => "Access",
|
||||||
|
Column::Error => "Errors",
|
||||||
Column::Uptime => "Uptime",
|
Column::Uptime => "Uptime",
|
||||||
Column::Light => "Fault light",
|
Column::Light => "Light",
|
||||||
Column::OperatingState => "State",
|
Column::OperatingState => "State",
|
||||||
Column::BestShare => "Best share",
|
Column::BestShare => "Best share",
|
||||||
Column::SessionBestShare => "Session best",
|
Column::SessionBestShare => "Session best",
|
||||||
@@ -469,6 +503,9 @@ impl Column {
|
|||||||
Column::Mac | Column::Hostname | Column::Serial => 150,
|
Column::Mac | Column::Hostname | Column::Serial => 150,
|
||||||
Column::ApiVersion | Column::Light => 90,
|
Column::ApiVersion | Column::Light => 90,
|
||||||
Column::ControlBoard => 130,
|
Column::ControlBoard => 130,
|
||||||
|
Column::Pic => 70,
|
||||||
|
Column::Locked => 90,
|
||||||
|
Column::Error => 160,
|
||||||
Column::Uptime => 100,
|
Column::Uptime => 100,
|
||||||
Column::OperatingState => 100,
|
Column::OperatingState => 100,
|
||||||
Column::BestShare | Column::SessionBestShare => 110,
|
Column::BestShare | Column::SessionBestShare => 110,
|
||||||
@@ -607,6 +644,21 @@ impl Column {
|
|||||||
Column::Serial => r.serial.clone(),
|
Column::Serial => r.serial.clone(),
|
||||||
Column::ApiVersion => r.api_version.clone(),
|
Column::ApiVersion => r.api_version.clone(),
|
||||||
Column::ControlBoard => r.control_board.clone(),
|
Column::ControlBoard => r.control_board.clone(),
|
||||||
|
Column::Pic => match r.pic_present {
|
||||||
|
Some(true) => "PIC".to_string(),
|
||||||
|
Some(false) => "noPIC".to_string(),
|
||||||
|
None => "?".to_string(),
|
||||||
|
},
|
||||||
|
Column::Locked => match r.write_locked {
|
||||||
|
Some(true) => "locked".to_string(),
|
||||||
|
Some(false) => "unlocked".to_string(),
|
||||||
|
None => "?".to_string(),
|
||||||
|
},
|
||||||
|
Column::Error => match r.errors.len() {
|
||||||
|
0 => String::new(),
|
||||||
|
1 => r.errors[0].clone(),
|
||||||
|
n => format!("{n} errors"),
|
||||||
|
},
|
||||||
Column::Status => r.status().to_string(),
|
Column::Status => r.status().to_string(),
|
||||||
Column::Uptime => format_uptime(r.uptime_secs),
|
Column::Uptime => format_uptime(r.uptime_secs),
|
||||||
Column::Light => match r.light_flashing {
|
Column::Light => match r.light_flashing {
|
||||||
@@ -636,7 +688,7 @@ pub enum SortKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Text-column filter operators (Excel-style text filters).
|
/// Text-column filter operators (Excel-style text filters).
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum TextOp {
|
pub enum TextOp {
|
||||||
Contains,
|
Contains,
|
||||||
NotContains,
|
NotContains,
|
||||||
@@ -646,7 +698,7 @@ pub enum TextOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Numeric-column filter operators (Excel-style number filters).
|
/// Numeric-column filter operators (Excel-style number filters).
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum NumOp {
|
pub enum NumOp {
|
||||||
Between,
|
Between,
|
||||||
Eq,
|
Eq,
|
||||||
@@ -659,7 +711,7 @@ pub enum NumOp {
|
|||||||
|
|
||||||
/// One column's active filter. Text columns can filter by a value checklist
|
/// One column's active filter. Text columns can filter by a value checklist
|
||||||
/// ("is any of") or a text predicate; numeric columns by a numeric predicate.
|
/// ("is any of") or a text predicate; numeric columns by a numeric predicate.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum ColFilter {
|
pub enum ColFilter {
|
||||||
Values(HashSet<String>),
|
Values(HashSet<String>),
|
||||||
Text { op: TextOp, needle: String },
|
Text { op: TextOp, needle: String },
|
||||||
@@ -700,6 +752,7 @@ impl ColFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Display state: order, visibility, sort, filter.
|
/// Display state: order, visibility, sort, filter.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct ViewState {
|
pub struct ViewState {
|
||||||
/// Model column order as displayed (Ip is always the first visible column).
|
/// Model column order as displayed (Ip is always the first visible column).
|
||||||
pub order: Vec<Column>,
|
pub order: Vec<Column>,
|
||||||
@@ -1134,6 +1187,39 @@ mod tests {
|
|||||||
assert_eq!(format_uptime(90_061), "1d 1h");
|
assert_eq!(format_uptime(90_061), "1d 1h");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pic_locked_error_columns_render() {
|
||||||
|
// PIC (best-effort): known -> PIC/noPIC, unknown -> "?".
|
||||||
|
let pic = MinerRow { pic_present: Some(true), ..Default::default() };
|
||||||
|
let nopic = MinerRow { pic_present: Some(false), ..Default::default() };
|
||||||
|
let pic_unknown = MinerRow { pic_present: None, ..Default::default() };
|
||||||
|
assert_eq!(Column::Pic.cell(&pic), "PIC");
|
||||||
|
assert_eq!(Column::Pic.cell(&nopic), "noPIC");
|
||||||
|
assert_eq!(Column::Pic.cell(&pic_unknown), "?");
|
||||||
|
|
||||||
|
// Access column.
|
||||||
|
let locked = MinerRow { write_locked: Some(true), ..Default::default() };
|
||||||
|
let unlocked = MinerRow { write_locked: Some(false), ..Default::default() };
|
||||||
|
assert_eq!(Column::Locked.cell(&locked), "locked");
|
||||||
|
assert_eq!(Column::Locked.cell(&unlocked), "unlocked");
|
||||||
|
assert_eq!(Column::Locked.cell(&MinerRow::default()), "?");
|
||||||
|
|
||||||
|
// Error column: blank / single message / count.
|
||||||
|
let none = MinerRow { errors: vec![], ..Default::default() };
|
||||||
|
let one = MinerRow { errors: vec!["[Error] boom".into()], ..Default::default() };
|
||||||
|
let many = MinerRow { errors: vec!["a".into(), "b".into(), "c".into()], ..Default::default() };
|
||||||
|
assert_eq!(Column::Error.cell(&none), "");
|
||||||
|
assert_eq!(Column::Error.cell(&one), "[Error] boom");
|
||||||
|
assert_eq!(Column::Error.cell(&many), "3 errors");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn caps_any_control() {
|
||||||
|
assert!(!MinerCaps::default().any_control(), "no caps -> view-only");
|
||||||
|
assert!(MinerCaps { restart: true, ..Default::default() }.any_control());
|
||||||
|
assert!(MinerCaps { firmware_flash: true, ..Default::default() }.any_control());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ip_column_sorts_numerically() {
|
fn ip_column_sorts_numerically() {
|
||||||
// A plain string sort puts "10.255.1.10" before "10.255.1.2"; the IP
|
// A plain string sort puts "10.255.1.10" before "10.255.1.2"; the IP
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
//! Saved view presets: named snapshots of the table's column arrangement,
|
||||||
|
//! visibility, sort, and filters. Persisted as JSON in the config dir. The
|
||||||
|
//! first preset is always a built-in "Default" profile.
|
||||||
|
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::model::{ColFilter, Column, ViewState, ALL_COLUMNS};
|
||||||
|
use crate::scan::config_path;
|
||||||
|
|
||||||
|
pub const PRESETS_FILE: &str = "presets.json";
|
||||||
|
|
||||||
|
/// The built-in default profile's visible columns, in display order (Ip first).
|
||||||
|
const DEFAULT_PROFILE: [Column; 9] = [
|
||||||
|
Column::Ip,
|
||||||
|
Column::Model,
|
||||||
|
Column::Hashrate,
|
||||||
|
Column::Power,
|
||||||
|
Column::ChipTemp,
|
||||||
|
Column::Firmware,
|
||||||
|
Column::ControlBoard,
|
||||||
|
Column::Pic,
|
||||||
|
Column::Status,
|
||||||
|
];
|
||||||
|
|
||||||
|
/// A serializable snapshot of a `ViewState` (Vec-based so JSON has no map keys
|
||||||
|
/// that are enums, and column order within `visible` is preserved).
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct PresetView {
|
||||||
|
pub order: Vec<Column>,
|
||||||
|
pub visible: Vec<Column>,
|
||||||
|
pub sort: Option<(Column, bool)>,
|
||||||
|
pub filters: Vec<(Column, ColFilter)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PresetView {
|
||||||
|
pub fn from_view(v: &ViewState) -> PresetView {
|
||||||
|
PresetView {
|
||||||
|
order: v.order.clone(),
|
||||||
|
// keep the visible columns in display order for stability
|
||||||
|
visible: v.order.iter().copied().filter(|c| v.visible.contains(c)).collect(),
|
||||||
|
sort: v.sort,
|
||||||
|
filters: v.filters.iter().map(|(k, f)| (*k, f.clone())).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rebuild a `ViewState` from this snapshot. Any column missing from a
|
||||||
|
/// loaded (possibly older) preset is appended to `order` and left hidden, so
|
||||||
|
/// the result always covers every `Column`.
|
||||||
|
pub fn to_view(&self) -> ViewState {
|
||||||
|
let mut order = self.order.clone();
|
||||||
|
for c in ALL_COLUMNS {
|
||||||
|
if !order.contains(&c) {
|
||||||
|
order.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut visible: HashSet<Column> = self.visible.iter().copied().collect();
|
||||||
|
visible.insert(Column::Ip); // IP is always shown
|
||||||
|
let filters: HashMap<Column, ColFilter> = self.filters.iter().cloned().collect();
|
||||||
|
ViewState { order, visible, sort: self.sort, filters }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct Preset {
|
||||||
|
pub name: String,
|
||||||
|
pub view: PresetView,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The built-in default profile (always present as the first preset).
|
||||||
|
pub fn default_preset() -> Preset {
|
||||||
|
let mut order: Vec<Column> = DEFAULT_PROFILE.to_vec();
|
||||||
|
for c in ALL_COLUMNS {
|
||||||
|
if !order.contains(&c) {
|
||||||
|
order.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Preset {
|
||||||
|
name: "Default".to_string(),
|
||||||
|
view: PresetView {
|
||||||
|
order,
|
||||||
|
visible: DEFAULT_PROFILE.to_vec(),
|
||||||
|
sort: None,
|
||||||
|
filters: Vec::new(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load saved presets, always with the built-in "Default" first. A missing or
|
||||||
|
/// unreadable file yields just the default.
|
||||||
|
pub fn load_presets() -> Vec<Preset> {
|
||||||
|
let mut presets = std::fs::read_to_string(config_path(PRESETS_FILE))
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| serde_json::from_str::<Vec<Preset>>(&s).ok())
|
||||||
|
.unwrap_or_default();
|
||||||
|
// The default profile is always present and always first.
|
||||||
|
presets.retain(|p| p.name != "Default");
|
||||||
|
presets.insert(0, default_preset());
|
||||||
|
presets
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Persist presets (the built-in "Default" is not written; it is re-seeded on
|
||||||
|
/// load). Best-effort: errors are returned for the caller to surface.
|
||||||
|
pub fn save_presets(presets: &[Preset]) -> std::io::Result<()> {
|
||||||
|
let p = config_path(PRESETS_FILE);
|
||||||
|
if let Some(dir) = p.parent() {
|
||||||
|
std::fs::create_dir_all(dir)?;
|
||||||
|
}
|
||||||
|
let user: Vec<&Preset> = presets.iter().filter(|p| p.name != "Default").collect();
|
||||||
|
let json = serde_json::to_string_pretty(&user)
|
||||||
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
|
||||||
|
std::fs::write(p, json)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn default_preset_round_trips_through_view() {
|
||||||
|
let p = default_preset();
|
||||||
|
let view = p.view.to_view();
|
||||||
|
// IP first + the requested default columns visible.
|
||||||
|
assert!(view.visible.contains(&Column::Ip));
|
||||||
|
assert!(view.visible.contains(&Column::ControlBoard));
|
||||||
|
assert!(view.visible.contains(&Column::Pic));
|
||||||
|
assert!(view.visible.contains(&Column::Status));
|
||||||
|
assert!(!view.visible.contains(&Column::Cooling), "not in the default profile");
|
||||||
|
// to_view covers every column in `order`.
|
||||||
|
assert_eq!(view.order.len(), ALL_COLUMNS.len());
|
||||||
|
// Round-trip a snapshot back out.
|
||||||
|
let snap = PresetView::from_view(&view);
|
||||||
|
assert_eq!(snap.visible.first(), Some(&Column::Ip));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn preset_json_round_trip() {
|
||||||
|
let p = default_preset();
|
||||||
|
let json = serde_json::to_string(&vec![&p]).unwrap();
|
||||||
|
let back: Vec<Preset> = serde_json::from_str(&json).unwrap();
|
||||||
|
assert_eq!(back.len(), 1);
|
||||||
|
assert_eq!(back[0].name, "Default");
|
||||||
|
assert_eq!(back[0].view.visible, DEFAULT_PROFILE.to_vec());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -397,6 +397,34 @@ pub fn start_scan(lines: Vec<String>) -> ScanHandle {
|
|||||||
ScanHandle { rx, cancel }
|
ScanHandle { rx, cancel }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Flatten a miner's structured messages into display lines, most severe first
|
||||||
|
/// ("[Error] text (component)"), for the Errors column + hover tooltip.
|
||||||
|
fn summarize_messages(messages: &[asic_rs::core::data::message::MinerMessage]) -> Vec<String> {
|
||||||
|
use asic_rs::core::data::message::MessageSeverity;
|
||||||
|
let rank = |s: &MessageSeverity| match s {
|
||||||
|
MessageSeverity::Error => 0u8,
|
||||||
|
MessageSeverity::Warning => 1,
|
||||||
|
MessageSeverity::Info => 2,
|
||||||
|
};
|
||||||
|
let mut ranked: Vec<(u8, String)> = messages
|
||||||
|
.iter()
|
||||||
|
.map(|m| {
|
||||||
|
let sev = match m.severity {
|
||||||
|
MessageSeverity::Error => "Error",
|
||||||
|
MessageSeverity::Warning => "Warning",
|
||||||
|
MessageSeverity::Info => "Info",
|
||||||
|
};
|
||||||
|
let line = match &m.component {
|
||||||
|
Some(c) => format!("[{sev}] {} ({c})", m.message),
|
||||||
|
None => format!("[{sev}] {}", m.message),
|
||||||
|
};
|
||||||
|
(rank(&m.severity), line)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
ranked.sort_by_key(|(r, _)| *r);
|
||||||
|
ranked.into_iter().map(|(_, s)| s).collect()
|
||||||
|
}
|
||||||
|
|
||||||
async fn to_row(miner: &dyn Miner) -> MinerRow {
|
async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||||
let data = miner.get_data().await;
|
let data = miner.get_data().await;
|
||||||
let hashrate_ths = data
|
let hashrate_ths = data
|
||||||
@@ -484,10 +512,22 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
|||||||
tuning: miner.supports_set_tuning_percent(),
|
tuning: miner.supports_set_tuning_percent(),
|
||||||
firmware_flash: miner.supports_upgrade_firmware(),
|
firmware_flash: miner.supports_upgrade_firmware(),
|
||||||
};
|
};
|
||||||
|
// PIC vs noPIC is not reported over the network by asic-rs; best-effort
|
||||||
|
// heuristic from the model string, else unknown (true detection needs an
|
||||||
|
// on-board SSH/I2C probe -- a separate feature).
|
||||||
|
let pic_present = if model.to_lowercase().contains("nopic") { Some(false) } else { None };
|
||||||
|
// Access: locked/view-only when the miner exposes no writable control at
|
||||||
|
// all, otherwise unlocked. Inferred from capabilities (asic-rs has no direct
|
||||||
|
// lock-state field).
|
||||||
|
let write_locked = Some(!caps.any_control());
|
||||||
|
let errors = summarize_messages(&data.messages);
|
||||||
MinerRow {
|
MinerRow {
|
||||||
ip: data.ip.to_string(),
|
ip: data.ip.to_string(),
|
||||||
selected: false,
|
selected: false,
|
||||||
caps,
|
caps,
|
||||||
|
pic_present,
|
||||||
|
write_locked,
|
||||||
|
errors,
|
||||||
model,
|
model,
|
||||||
mac: data.mac.map(|m| m.to_string()).unwrap_or_default(),
|
mac: data.mac.map(|m| m.to_string()).unwrap_or_default(),
|
||||||
hostname: data.hostname.clone().unwrap_or_default(),
|
hostname: data.hostname.clone().unwrap_or_default(),
|
||||||
|
|||||||
+259
-19
@@ -16,6 +16,13 @@ pub const ID_PLAY: i32 = 104;
|
|||||||
pub const ID_PAUSE: i32 = 105;
|
pub const ID_PAUSE: i32 = 105;
|
||||||
pub const ID_STOP: i32 = 106;
|
pub const ID_STOP: i32 = 106;
|
||||||
pub const ID_SCAN_CREDS: i32 = 107;
|
pub const ID_SCAN_CREDS: i32 = 107;
|
||||||
|
pub const ID_PRESETS: i32 = 108;
|
||||||
|
// Presets dialog.
|
||||||
|
const ID_PRESET_LOAD: i32 = 770;
|
||||||
|
const ID_PRESET_SAVE: i32 = 771;
|
||||||
|
const ID_PRESET_DELETE: i32 = 772;
|
||||||
|
const ID_PRESET_CLOSE: i32 = 773;
|
||||||
|
const ID_PRESET_CHOICE: i32 = 774;
|
||||||
const ID_RANGES_APPLY: i32 = 201;
|
const ID_RANGES_APPLY: i32 = 201;
|
||||||
const ID_RANGES_CANCEL: i32 = 202;
|
const ID_RANGES_CANCEL: i32 = 202;
|
||||||
const ID_COLUMNS_OK: i32 = 203;
|
const ID_COLUMNS_OK: i32 = 203;
|
||||||
@@ -58,6 +65,12 @@ const ID_FLASH_CANCEL: i32 = 745;
|
|||||||
const ID_CREDS_SAVE: i32 = 746;
|
const ID_CREDS_SAVE: i32 = 746;
|
||||||
const ID_CREDS_CLEAR: i32 = 747;
|
const ID_CREDS_CLEAR: i32 = 747;
|
||||||
const ID_CREDS_CANCEL: i32 = 748;
|
const ID_CREDS_CANCEL: i32 = 748;
|
||||||
|
// Column-header right-click menu (Excel-style).
|
||||||
|
const ID_HDR_SORT_ASC: i32 = 760;
|
||||||
|
const ID_HDR_SORT_DESC: i32 = 761;
|
||||||
|
const ID_HDR_HIDE: i32 = 762;
|
||||||
|
const ID_HDR_AUTOSIZE: i32 = 763;
|
||||||
|
const ID_HDR_COLUMNS: i32 = 764;
|
||||||
// Ticks (~seconds) to keep an action's result on the status bar before the
|
// Ticks (~seconds) to keep an action's result on the status bar before the
|
||||||
// idle/countdown status takes over again.
|
// idle/countdown status takes over again.
|
||||||
const ACTION_RESULT_TICKS: u8 = 8;
|
const ACTION_RESULT_TICKS: u8 = 8;
|
||||||
@@ -82,6 +95,8 @@ struct Palette {
|
|||||||
amber: (u8, u8, u8),
|
amber: (u8, u8, u8),
|
||||||
red: (u8, u8, u8),
|
red: (u8, u8, u8),
|
||||||
accent: (u8, u8, u8),
|
accent: (u8, u8, u8),
|
||||||
|
/// Odd-row (zebra) background: a subtle tint of the window colour.
|
||||||
|
zebra: (u8, u8, u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn luminance(c: (u8, u8, u8)) -> f32 {
|
fn luminance(c: (u8, u8, u8)) -> f32 {
|
||||||
@@ -159,6 +174,12 @@ fn encode_temp_cell(pal: &Palette, plain: &str, temp_c: f64) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Segment-encoded single-colour cell (Access/Errors): `plain` in `color`, or
|
||||||
|
/// the default text colour when `color` is None.
|
||||||
|
fn encode_flag_cell(plain: &str, color: Option<(u8, u8, u8)>) -> String {
|
||||||
|
encode_segments(&[(color, plain.to_string())])
|
||||||
|
}
|
||||||
|
|
||||||
/// Build the segment-encoded cell text for the Cooling column: each fan's RPM
|
/// Build the segment-encoded cell text for the Cooling column: each fan's RPM
|
||||||
/// gets its own grey-to-blue colour by speed, and the "/" separators between
|
/// gets its own grey-to-blue colour by speed, and the "/" separators between
|
||||||
/// them stay in the default text colour.
|
/// them stay in the default text colour.
|
||||||
@@ -230,14 +251,6 @@ fn status_kind_color(pal: &Palette, status: &str) -> (u8, u8, u8) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A miner row's text colour, by status: green = hashing, amber = slow, blue =
|
|
||||||
/// paused, red = not hashing. This both conveys status and separates rows
|
|
||||||
/// visually (GTK's native zebra/alt-row support is unreliable and fights
|
|
||||||
/// selection).
|
|
||||||
fn status_color(pal: &Palette, r: &MinerRow) -> (u8, u8, u8) {
|
|
||||||
status_kind_color(pal, r.status())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn palette() -> Palette {
|
fn palette() -> Palette {
|
||||||
let win = wx_rs::system_color(0); // window background
|
let win = wx_rs::system_color(0); // window background
|
||||||
let text = wx_rs::system_color(1); // window text
|
let text = wx_rs::system_color(1); // window text
|
||||||
@@ -252,6 +265,9 @@ fn palette() -> Palette {
|
|||||||
amber: if dark { (245, 190, 66) } else { (176, 120, 10) },
|
amber: if dark { (245, 190, 66) } else { (176, 120, 10) },
|
||||||
red: if dark { (245, 110, 100) } else { (198, 55, 45) },
|
red: if dark { (245, 110, 100) } else { (198, 55, 45) },
|
||||||
accent: if dark { (108, 168, 250) } else { (40, 100, 170) },
|
accent: if dark { (108, 168, 250) } else { (40, 100, 170) },
|
||||||
|
// Subtle zebra tint of the window: slightly lighter in dark mode, a
|
||||||
|
// touch darker than the light window.
|
||||||
|
zebra: if dark { nudge(win, 12) } else { nudge(win, -10) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,10 +337,18 @@ pub struct App {
|
|||||||
// start while it runs, and it will not start while anything else is running,
|
// start while it runs, and it will not start while anything else is running,
|
||||||
// so no two network operations ever race the same miner mid-upload.
|
// so no two network operations ever race the same miner mid-upload.
|
||||||
flashing: bool,
|
flashing: bool,
|
||||||
|
// The column a header right-click menu targets (remembered across the menu's
|
||||||
|
// nested event loop until an item is chosen).
|
||||||
|
header_menu_col: Option<Column>,
|
||||||
// The "Set scan credentials..." dialog.
|
// The "Set scan credentials..." dialog.
|
||||||
creds_dialog: Widget,
|
creds_dialog: Widget,
|
||||||
creds_user_input: Widget,
|
creds_user_input: Widget,
|
||||||
creds_pass_input: Widget,
|
creds_pass_input: Widget,
|
||||||
|
// Saved view presets + the Presets dialog widgets.
|
||||||
|
presets: Vec<crate::presets::Preset>,
|
||||||
|
presets_dialog: Widget,
|
||||||
|
presets_choice: Widget,
|
||||||
|
presets_name_input: Widget,
|
||||||
// The last action's result, kept on the status bar for a few ticks.
|
// The last action's result, kept on the status bar for a few ticks.
|
||||||
action_result: Option<String>,
|
action_result: Option<String>,
|
||||||
action_result_ticks: u8,
|
action_result_ticks: u8,
|
||||||
@@ -366,8 +390,9 @@ pub fn build(frame: Widget) -> App {
|
|||||||
let vc = kind_color(&pal, kind);
|
let vc = kind_color(&pal, kind);
|
||||||
let card = Widget::panel(panel);
|
let card = Widget::panel(panel);
|
||||||
card.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
|
card.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
|
||||||
// Uniform size so every KPI box is identical regardless of its content.
|
// Uniform size so every KPI box is identical regardless of its content
|
||||||
card.set_min_size(128, 62);
|
// (wide enough for the largest value, e.g. "685 TH/s" / "21.3 kW").
|
||||||
|
card.set_min_size(150, 62);
|
||||||
let cs = Widget::box_sizer(true);
|
let cs = Widget::box_sizer(true);
|
||||||
let value = Widget::static_text(card, "0");
|
let value = Widget::static_text(card, "0");
|
||||||
value.set_font_size(19);
|
value.set_font_size(19);
|
||||||
@@ -433,6 +458,8 @@ pub fn build(frame: Widget) -> App {
|
|||||||
let stop_btn = Widget::media_button(panel, ID_STOP, 2, (226, 72, 60));
|
let stop_btn = Widget::media_button(panel, ID_STOP, 2, (226, 72, 60));
|
||||||
ctl.add(stop_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 2);
|
ctl.add(stop_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 2);
|
||||||
ctl.add_stretch(1);
|
ctl.add_stretch(1);
|
||||||
|
let presets_btn = Widget::button(panel, "Presets", ID_PRESETS);
|
||||||
|
ctl.add(presets_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||||
let filter_btn = Widget::button(panel, "Filter", ID_FILTER);
|
let filter_btn = Widget::button(panel, "Filter", ID_FILTER);
|
||||||
ctl.add(filter_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
ctl.add(filter_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||||
let columns_btn = Widget::button(panel, "Columns", ID_COLUMNS);
|
let columns_btn = Widget::button(panel, "Columns", ID_COLUMNS);
|
||||||
@@ -505,9 +532,14 @@ pub fn build(frame: Widget) -> App {
|
|||||||
flash_confirm_input: frame,
|
flash_confirm_input: frame,
|
||||||
pending_flash: None,
|
pending_flash: None,
|
||||||
flashing: false,
|
flashing: false,
|
||||||
|
header_menu_col: None,
|
||||||
creds_dialog: frame,
|
creds_dialog: frame,
|
||||||
creds_user_input: frame,
|
creds_user_input: frame,
|
||||||
creds_pass_input: frame,
|
creds_pass_input: frame,
|
||||||
|
presets: crate::presets::load_presets(),
|
||||||
|
presets_dialog: frame,
|
||||||
|
presets_choice: frame,
|
||||||
|
presets_name_input: frame,
|
||||||
action_result: None,
|
action_result: None,
|
||||||
action_result_ticks: 0,
|
action_result_ticks: 0,
|
||||||
ranges_dialog: frame,
|
ranges_dialog: frame,
|
||||||
@@ -530,6 +562,10 @@ pub fn build(frame: Widget) -> App {
|
|||||||
filter_pending_op: None,
|
filter_pending_op: None,
|
||||||
filter_working: HashMap::new(),
|
filter_working: HashMap::new(),
|
||||||
};
|
};
|
||||||
|
// Boot with the first (Default) preset's column layout.
|
||||||
|
if let Some(p) = app.presets.first() {
|
||||||
|
app.view = p.view.to_view();
|
||||||
|
}
|
||||||
app.rebuild_table();
|
app.rebuild_table();
|
||||||
Widget::timer(TIMER_SCAN, 1000);
|
Widget::timer(TIMER_SCAN, 1000);
|
||||||
app
|
app
|
||||||
@@ -544,6 +580,9 @@ impl App {
|
|||||||
t.destroy();
|
t.destroy();
|
||||||
}
|
}
|
||||||
let t = Widget::dvlc(self.table_parent);
|
let t = Widget::dvlc(self.table_parent);
|
||||||
|
// Zebra striping (theme-aware) for row separation now that rows are no
|
||||||
|
// longer tinted by status.
|
||||||
|
t.dvlc_set_zebra(Some(self.pal.zebra));
|
||||||
// Creation order == display order. IP is the fixed first column (not
|
// Creation order == display order. IP is the fixed first column (not
|
||||||
// reorderable); the rest are reorderable. The active sort column carries
|
// reorderable); the rest are reorderable. The active sort column carries
|
||||||
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
|
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
|
||||||
@@ -557,7 +596,7 @@ impl App {
|
|||||||
Some((sc, false)) if sc == c => title.push_str(" v"),
|
Some((sc, false)) if sc == c => title.push_str(" v"),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling) {
|
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error | Column::Status) {
|
||||||
// These columns show two-tone / multi-tone text (actual vs.
|
// These columns show two-tone / multi-tone text (actual vs.
|
||||||
// expected, or one colour per fan) via a custom renderer that
|
// expected, or one colour per fan) via a custom renderer that
|
||||||
// parses the segment-encoded cell value fill_rows writes.
|
// parses the segment-encoded cell value fill_rows writes.
|
||||||
@@ -577,6 +616,9 @@ impl App {
|
|||||||
|
|
||||||
pub fn fill_rows(&mut self) {
|
pub fn fill_rows(&mut self) {
|
||||||
let Some(t) = self.table else { return };
|
let Some(t) = self.table else { return };
|
||||||
|
// Hold the scroll position across the full clear+refill so the table
|
||||||
|
// doesn't jump back to the top as new rows stream in during a scan.
|
||||||
|
let top = t.dvlc_get_top_row();
|
||||||
t.dvlc_clear();
|
t.dvlc_clear();
|
||||||
self.view_idx = self.view.view(&self.rows);
|
self.view_idx = self.view.view(&self.rows);
|
||||||
let cols = self.view.display_columns();
|
let cols = self.view.display_columns();
|
||||||
@@ -586,13 +628,12 @@ impl App {
|
|||||||
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
|
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
|
||||||
t.dvlc_append_row(&refs);
|
t.dvlc_append_row(&refs);
|
||||||
}
|
}
|
||||||
// Colour each row's text by status (also separates rows visually).
|
// Rows are NOT tinted by status any more: every cell is the default text
|
||||||
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
// colour except the conditionally-formatted columns below (the Status
|
||||||
t.dvlc_set_row_color(disp, Some(status_color(&self.pal, &self.rows[ri])));
|
// column carries the status colour itself). Zebra striping + gridlines
|
||||||
}
|
// (set at table build) separate rows instead.
|
||||||
// Overwrite the combined actual/expected + cooling-fan cells with
|
// Overwrite the conditionally-coloured cells with segment-encoded text
|
||||||
// segment-encoded coloured text (the custom renderer these columns use
|
// (the custom renderer these columns use parses it back out).
|
||||||
// parses it back out; see encode_combined_cell/encode_cooling_cell).
|
|
||||||
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
||||||
let r = &self.rows[ri];
|
let r = &self.rows[ri];
|
||||||
for (ci, c) in cols.iter().enumerate() {
|
for (ci, c) in cols.iter().enumerate() {
|
||||||
@@ -632,11 +673,36 @@ impl App {
|
|||||||
}
|
}
|
||||||
Column::ChipTemp => encode_temp_cell(&self.pal, &c.cell(r), r.chip_temp_c),
|
Column::ChipTemp => encode_temp_cell(&self.pal, &c.cell(r), r.chip_temp_c),
|
||||||
Column::Cooling => encode_cooling_cell(&self.pal, &r.fan_rpms),
|
Column::Cooling => encode_cooling_cell(&self.pal, &r.fan_rpms),
|
||||||
|
Column::Locked => {
|
||||||
|
// green = unlocked/writable, red = locked/view-only.
|
||||||
|
let color = match r.write_locked {
|
||||||
|
Some(true) => Some(self.pal.red),
|
||||||
|
Some(false) => Some(self.pal.green),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
encode_flag_cell(&c.cell(r), color)
|
||||||
|
}
|
||||||
|
Column::Error => {
|
||||||
|
let color = (!r.errors.is_empty()).then_some(self.pal.red);
|
||||||
|
encode_flag_cell(&c.cell(r), color)
|
||||||
|
}
|
||||||
|
Column::Status => {
|
||||||
|
// Status keeps its status colour on its own cell (the
|
||||||
|
// row is no longer tinted wholesale).
|
||||||
|
encode_flag_cell(&c.cell(r), Some(status_kind_color(&self.pal, r.status())))
|
||||||
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
t.dvlc_set_cell(disp, ci, &encoded);
|
t.dvlc_set_cell(disp, ci, &encoded);
|
||||||
|
// The Errors cell gets the full message list as a hover tooltip.
|
||||||
|
if matches!(c, Column::Error) {
|
||||||
|
t.dvlc_set_cell_tooltip(disp, ci, &r.errors.join("\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(row) = top {
|
||||||
|
t.dvlc_ensure_visible(row.min(self.view_idx.len().saturating_sub(1)));
|
||||||
|
}
|
||||||
// Re-apply the selection (a refresh clears the control's selection).
|
// Re-apply the selection (a refresh clears the control's selection).
|
||||||
let sel: Vec<usize> = self
|
let sel: Vec<usize> = self
|
||||||
.view_idx
|
.view_idx
|
||||||
@@ -675,6 +741,9 @@ impl App {
|
|||||||
caption.set_fg(self.pal.label.0, self.pal.label.1, self.pal.label.2);
|
caption.set_fg(self.pal.label.0, self.pal.label.1, self.pal.label.2);
|
||||||
}
|
}
|
||||||
self.highlight_kpi_filter();
|
self.highlight_kpi_filter();
|
||||||
|
if let Some(t) = self.table {
|
||||||
|
t.dvlc_set_zebra(Some(self.pal.zebra));
|
||||||
|
}
|
||||||
self.fill_rows(); // re-colour rows with the new palette
|
self.fill_rows(); // re-colour rows with the new palette
|
||||||
self.table_parent.layout();
|
self.table_parent.layout();
|
||||||
}
|
}
|
||||||
@@ -845,6 +914,9 @@ impl App {
|
|||||||
/// actions (power limit / tuning %) return a prompt dialog to show modally.
|
/// actions (power limit / tuning %) return a prompt dialog to show modally.
|
||||||
fn on_menu_item(&mut self, id: i32) -> Option<Widget> {
|
fn on_menu_item(&mut self, id: i32) -> Option<Widget> {
|
||||||
match id {
|
match id {
|
||||||
|
ID_HDR_SORT_ASC | ID_HDR_SORT_DESC | ID_HDR_HIDE | ID_HDR_AUTOSIZE | ID_HDR_COLUMNS => {
|
||||||
|
return self.on_header_menu(id)
|
||||||
|
}
|
||||||
ID_CTX_OPEN => {
|
ID_CTX_OPEN => {
|
||||||
for ip in self.selected_ip_list() {
|
for ip in self.selected_ip_list() {
|
||||||
wx_rs::launch_browser(&format!("http://{ip}"));
|
wx_rs::launch_browser(&format!("http://{ip}"));
|
||||||
@@ -1439,6 +1511,58 @@ impl App {
|
|||||||
self.fill_rows();
|
self.fill_rows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Right-click on a column header: Excel-style per-column menu (sort, hide,
|
||||||
|
/// auto-size, and open the full column picker).
|
||||||
|
fn header_context_menu(&mut self, creation_idx: usize) {
|
||||||
|
let Some(t) = self.table else { return };
|
||||||
|
let cols = self.view.display_columns();
|
||||||
|
let Some(&col) = cols.get(creation_idx) else { return };
|
||||||
|
self.header_menu_col = Some(col);
|
||||||
|
let menu = Widget::menu_new();
|
||||||
|
menu.menu_append(ID_HDR_SORT_ASC, &format!("Sort {} ascending", col.title()));
|
||||||
|
menu.menu_append(ID_HDR_SORT_DESC, &format!("Sort {} descending", col.title()));
|
||||||
|
menu.menu_append_separator();
|
||||||
|
menu.menu_append(ID_HDR_AUTOSIZE, "Auto-size this column");
|
||||||
|
// The fixed IP column can't be hidden.
|
||||||
|
if !self.view.is_fixed(col) {
|
||||||
|
menu.menu_append(ID_HDR_HIDE, &format!("Hide {}", col.title()));
|
||||||
|
}
|
||||||
|
menu.menu_append_separator();
|
||||||
|
menu.menu_append(ID_HDR_COLUMNS, "Columns...");
|
||||||
|
self.pending_popup = Some((t, menu));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Apply a header-menu action to the remembered column.
|
||||||
|
fn on_header_menu(&mut self, id: i32) -> Option<Widget> {
|
||||||
|
let Some(col) = self.header_menu_col else { return None };
|
||||||
|
match id {
|
||||||
|
ID_HDR_SORT_ASC => {
|
||||||
|
self.view.sort = Some((col, true));
|
||||||
|
self.update_headers();
|
||||||
|
self.fill_rows();
|
||||||
|
}
|
||||||
|
ID_HDR_SORT_DESC => {
|
||||||
|
self.view.sort = Some((col, false));
|
||||||
|
self.update_headers();
|
||||||
|
self.fill_rows();
|
||||||
|
}
|
||||||
|
ID_HDR_HIDE if !self.view.is_fixed(col) => {
|
||||||
|
self.view.visible.remove(&col);
|
||||||
|
self.rebuild_table();
|
||||||
|
}
|
||||||
|
ID_HDR_AUTOSIZE => {
|
||||||
|
if let (Some(t), Some(pos)) =
|
||||||
|
(self.table, self.view.display_columns().iter().position(|c| *c == col))
|
||||||
|
{
|
||||||
|
t.dvlc_autosize_col(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ID_HDR_COLUMNS => return Some(self.build_columns_dialog()),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Refresh each column header's ASCII sort marker ("^" asc, "v" desc) in
|
/// Refresh each column header's ASCII sort marker ("^" asc, "v" desc) in
|
||||||
/// place, without recreating the table.
|
/// place, without recreating the table.
|
||||||
fn update_headers(&self) {
|
fn update_headers(&self) {
|
||||||
@@ -1547,6 +1671,115 @@ impl App {
|
|||||||
ALL_COLUMNS.iter().copied().filter(|c| *c != Column::Ip).collect()
|
ALL_COLUMNS.iter().copied().filter(|c| *c != Column::Ip).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build (but do not show) the view-presets dialog: load a saved view, save
|
||||||
|
/// the current columns/filters/sort as a named preset, or delete one.
|
||||||
|
fn build_presets_dialog(&mut self) -> Widget {
|
||||||
|
let frame = Widget::main_frame();
|
||||||
|
let dlg = Widget::dialog(frame, "View presets");
|
||||||
|
let root = Widget::box_sizer(true);
|
||||||
|
root.add(
|
||||||
|
Widget::static_text(
|
||||||
|
dlg,
|
||||||
|
"Load a saved view, or save the current columns, filters and sort as a new preset.",
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
sf::BORDER_ALL,
|
||||||
|
8,
|
||||||
|
);
|
||||||
|
let choice = Widget::choice(dlg, ID_PRESET_CHOICE);
|
||||||
|
for p in &self.presets {
|
||||||
|
choice.choice_append(&p.name);
|
||||||
|
}
|
||||||
|
choice.choice_set_selection(0);
|
||||||
|
choice.set_min_size(220, -1);
|
||||||
|
root.add(choice, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 8);
|
||||||
|
let row = Widget::box_sizer(false);
|
||||||
|
row.add(Widget::button(dlg, "Load", ID_PRESET_LOAD), 0, sf::BORDER_ALL, 4);
|
||||||
|
row.add(Widget::button(dlg, "Delete", ID_PRESET_DELETE), 0, sf::BORDER_ALL, 4);
|
||||||
|
root.add_sizer(row, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 8);
|
||||||
|
let saverow = Widget::box_sizer(false);
|
||||||
|
saverow.add(
|
||||||
|
Widget::static_text(dlg, "Save current as:"),
|
||||||
|
0,
|
||||||
|
sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
let name = Widget::text_ctrl(dlg, false);
|
||||||
|
name.set_min_size(150, -1);
|
||||||
|
saverow.add(name, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||||
|
saverow.add(Widget::button(dlg, "Save", ID_PRESET_SAVE), 0, sf::BORDER_ALL, 4);
|
||||||
|
root.add_sizer(saverow, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 8);
|
||||||
|
let btns = Widget::box_sizer(false);
|
||||||
|
btns.add_stretch(1);
|
||||||
|
btns.add(Widget::button(dlg, "Close", ID_PRESET_CLOSE), 0, sf::BORDER_ALL, 6);
|
||||||
|
root.add_sizer(btns, 0, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||||
|
root.set_sizer_on(dlg);
|
||||||
|
dlg.set_min_size(400, 220);
|
||||||
|
dlg.fit(dlg);
|
||||||
|
self.presets_dialog = dlg;
|
||||||
|
self.presets_choice = choice;
|
||||||
|
self.presets_name_input = name;
|
||||||
|
dlg
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load the selected preset, replacing the current view (columns, filters,
|
||||||
|
/// sort) and rebuilding the table.
|
||||||
|
fn apply_preset_load(&mut self) {
|
||||||
|
let sel = self.presets_choice.choice_get_selection();
|
||||||
|
let Some(p) = usize::try_from(sel).ok().and_then(|i| self.presets.get(i)) else { return };
|
||||||
|
self.view = p.view.to_view();
|
||||||
|
self.presets_dialog.close(1);
|
||||||
|
self.rebuild_table();
|
||||||
|
self.update_headers();
|
||||||
|
self.resync_kpi_filter();
|
||||||
|
wx_rs::set_status_text("preset loaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save the current view as a new (or replaced) named preset.
|
||||||
|
fn apply_preset_save(&mut self) {
|
||||||
|
let name = self.presets_name_input.get_value().trim().to_string();
|
||||||
|
if name.is_empty() {
|
||||||
|
wx_rs::set_status_text("enter a preset name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if name == "Default" {
|
||||||
|
wx_rs::set_status_text("\"Default\" is reserved");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let view = crate::presets::PresetView::from_view(&self.view);
|
||||||
|
let preset = crate::presets::Preset { name: name.clone(), view };
|
||||||
|
if let Some(existing) = self.presets.iter_mut().find(|p| p.name == name) {
|
||||||
|
*existing = preset;
|
||||||
|
} else {
|
||||||
|
self.presets.push(preset);
|
||||||
|
}
|
||||||
|
match crate::presets::save_presets(&self.presets) {
|
||||||
|
Ok(()) => {
|
||||||
|
self.presets_dialog.close(1);
|
||||||
|
wx_rs::set_status_text(&format!("saved preset \"{name}\""));
|
||||||
|
}
|
||||||
|
Err(e) => wx_rs::set_status_text(&format!("failed to save preset: {e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete the selected preset (the built-in "Default" can't be deleted).
|
||||||
|
fn apply_preset_delete(&mut self) {
|
||||||
|
let sel = self.presets_choice.choice_get_selection();
|
||||||
|
let Some(i) = usize::try_from(sel).ok().filter(|&i| i < self.presets.len()) else { return };
|
||||||
|
if self.presets[i].name == "Default" {
|
||||||
|
wx_rs::set_status_text("the Default preset can't be deleted");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let name = self.presets.remove(i).name;
|
||||||
|
match crate::presets::save_presets(&self.presets) {
|
||||||
|
Ok(()) => {
|
||||||
|
self.presets_dialog.close(1);
|
||||||
|
wx_rs::set_status_text(&format!("deleted preset \"{name}\""));
|
||||||
|
}
|
||||||
|
Err(e) => wx_rs::set_status_text(&format!("failed to save presets: {e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Build (but do not show) the columns chooser: a rearrangeable checklist of
|
/// Build (but do not show) the columns chooser: a rearrangeable checklist of
|
||||||
/// every scannable metric. Check to show; drag or use the up/down arrows to
|
/// every scannable metric. Check to show; drag or use the up/down arrows to
|
||||||
/// reorder. IP is always the first column and is not listed here.
|
/// reorder. IP is always the first column and is not listed here.
|
||||||
@@ -1927,6 +2160,11 @@ impl App {
|
|||||||
ID_COLUMNS => return Some(self.build_columns_dialog()),
|
ID_COLUMNS => return Some(self.build_columns_dialog()),
|
||||||
ID_COLUMNS_OK => self.apply_columns(),
|
ID_COLUMNS_OK => self.apply_columns(),
|
||||||
ID_COLUMNS_CANCEL => self.columns_dialog.close(0),
|
ID_COLUMNS_CANCEL => self.columns_dialog.close(0),
|
||||||
|
ID_PRESETS => return Some(self.build_presets_dialog()),
|
||||||
|
ID_PRESET_LOAD => self.apply_preset_load(),
|
||||||
|
ID_PRESET_SAVE => self.apply_preset_save(),
|
||||||
|
ID_PRESET_DELETE => self.apply_preset_delete(),
|
||||||
|
ID_PRESET_CLOSE => self.presets_dialog.close(0),
|
||||||
ID_FILTER => return Some(self.build_filter_dialog()),
|
ID_FILTER => return Some(self.build_filter_dialog()),
|
||||||
ID_FILTER_OK => self.apply_filter(),
|
ID_FILTER_OK => self.apply_filter(),
|
||||||
ID_FILTER_CANCEL => self.filter_dialog.close(0),
|
ID_FILTER_CANCEL => self.filter_dialog.close(0),
|
||||||
@@ -1988,6 +2226,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
WxEventKind::DvlcHeaderClick => self.header_click(ev.p1 as usize),
|
WxEventKind::DvlcHeaderClick => self.header_click(ev.p1 as usize),
|
||||||
|
WxEventKind::DvlcHeaderRightClick => self.header_context_menu(ev.p1 as usize),
|
||||||
WxEventKind::DvlcSelectionChanged => self.on_selection_changed(),
|
WxEventKind::DvlcSelectionChanged => self.on_selection_changed(),
|
||||||
WxEventKind::DvlcActivated => self.activate_row(ev.p1 as usize),
|
WxEventKind::DvlcActivated => self.activate_row(ev.p1 as usize),
|
||||||
WxEventKind::DvlcReordered => self.column_reordered(),
|
WxEventKind::DvlcReordered => self.column_reordered(),
|
||||||
@@ -2056,7 +2295,7 @@ impl App {
|
|||||||
for (j, c) in cols.iter().enumerate() {
|
for (j, c) in cols.iter().enumerate() {
|
||||||
let want = c.cell(r);
|
let want = c.cell(r);
|
||||||
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
|
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
|
||||||
let got = if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling) {
|
let got = if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error | Column::Status) {
|
||||||
decode_segments_plain(&raw)
|
decode_segments_plain(&raw)
|
||||||
} else {
|
} else {
|
||||||
raw
|
raw
|
||||||
@@ -2193,6 +2432,7 @@ mod tests {
|
|||||||
amber: (255, 128, 0),
|
amber: (255, 128, 0),
|
||||||
red: (255, 0, 0),
|
red: (255, 0, 0),
|
||||||
accent: (0, 0, 255),
|
accent: (0, 0, 255),
|
||||||
|
zebra: (245, 245, 245),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+41
-1
@@ -10,7 +10,7 @@
|
|||||||
+pub use widgets::*;
|
+pub use widgets::*;
|
||||||
--- a/src/widgets.rs
|
--- a/src/widgets.rs
|
||||||
+++ b/src/widgets.rs
|
+++ b/src/widgets.rs
|
||||||
@@ -0,0 +1,688 @@
|
@@ -0,0 +1,728 @@
|
||||||
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
|
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
|
||||||
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
|
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
|
||||||
+// wxWidgets object tree (parents own children; nothing to free in Rust).
|
+// wxWidgets object tree (parents own children; nothing to free in Rust).
|
||||||
@@ -71,8 +71,10 @@
|
|||||||
+ pub fn wxbr_dvlc_clear(win: *mut c_void);
|
+ pub fn wxbr_dvlc_clear(win: *mut c_void);
|
||||||
+ pub fn wxbr_dvlc_row_count(win: *mut c_void) -> c_int;
|
+ pub fn wxbr_dvlc_row_count(win: *mut c_void) -> c_int;
|
||||||
+ pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
|
+ pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
|
||||||
|
+ pub fn wxbr_dvlc_set_cell_tooltip(win: *mut c_void, row: usize, col: usize, text: *const c_char);
|
||||||
+ pub fn wxbr_dvlc_get_cell(win: *mut c_void, row: usize, col: usize, buf: *mut c_char, cap: c_int) -> c_int;
|
+ pub fn wxbr_dvlc_get_cell(win: *mut c_void, row: usize, col: usize, buf: *mut c_char, cap: c_int) -> c_int;
|
||||||
+ pub fn wxbr_dvlc_col_count(win: *mut c_void) -> c_int;
|
+ pub fn wxbr_dvlc_col_count(win: *mut c_void) -> c_int;
|
||||||
|
+ pub fn wxbr_dvlc_autosize_col(win: *mut c_void, pos: c_int);
|
||||||
+ pub fn wxbr_dvlc_set_col_title(win: *mut c_void, col: c_int, title: *const c_char);
|
+ pub fn wxbr_dvlc_set_col_title(win: *mut c_void, col: c_int, title: *const c_char);
|
||||||
+ pub fn wxbr_dvlc_set_sort_indicator(win: *mut c_void, col: c_int, active: c_int, ascending: c_int);
|
+ pub fn wxbr_dvlc_set_sort_indicator(win: *mut c_void, col: c_int, active: c_int, ascending: c_int);
|
||||||
+ pub fn wxbr_dvlc_col_at_pos(win: *mut c_void, pos: c_int) -> c_int;
|
+ pub fn wxbr_dvlc_col_at_pos(win: *mut c_void, pos: c_int) -> c_int;
|
||||||
@@ -82,6 +84,9 @@
|
|||||||
+ pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
+ pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
||||||
+ pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
+ pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||||
+ pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
|
+ pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
|
||||||
|
+ pub fn wxbr_dvlc_set_zebra(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||||
|
+ pub fn wxbr_dvlc_get_top_row(win: *mut c_void) -> c_int;
|
||||||
|
+ pub fn wxbr_dvlc_ensure_visible(win: *mut c_void, row: usize);
|
||||||
+ pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
+ pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||||
+ pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
+ pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||||
+ pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
+ pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||||
@@ -146,6 +151,7 @@
|
|||||||
+ ChoiceChanged,
|
+ ChoiceChanged,
|
||||||
+ SysColour,
|
+ SysColour,
|
||||||
+ Deferred,
|
+ Deferred,
|
||||||
|
+ DvlcHeaderRightClick,
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+impl WxEventKind {
|
+impl WxEventKind {
|
||||||
@@ -164,6 +170,7 @@
|
|||||||
+ 12 => WxEventKind::ChoiceChanged,
|
+ 12 => WxEventKind::ChoiceChanged,
|
||||||
+ 13 => WxEventKind::SysColour,
|
+ 13 => WxEventKind::SysColour,
|
||||||
+ 14 => WxEventKind::Deferred,
|
+ 14 => WxEventKind::Deferred,
|
||||||
|
+ 15 => WxEventKind::DvlcHeaderRightClick,
|
||||||
+ _ => return None,
|
+ _ => return None,
|
||||||
+ })
|
+ })
|
||||||
+ }
|
+ }
|
||||||
@@ -489,6 +496,13 @@
|
|||||||
+ unsafe { notsafe::wxbr_dvlc_set_cell(self.0, row, col, c.as_ptr()) }
|
+ unsafe { notsafe::wxbr_dvlc_set_cell(self.0, row, col, c.as_ptr()) }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ /// Set the hover tooltip for one cell (empty clears it). GTK only; a no-op
|
||||||
|
+ /// on other platforms until they gain per-cell tooltip support.
|
||||||
|
+ pub fn dvlc_set_cell_tooltip(&self, row: usize, col: usize, text: &str) {
|
||||||
|
+ let c = CString::new(text).unwrap_or_default();
|
||||||
|
+ unsafe { notsafe::wxbr_dvlc_set_cell_tooltip(self.0, row, col, c.as_ptr()) }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ pub fn dvlc_get_cell(&self, row: usize, col: usize) -> Option<String> {
|
+ pub fn dvlc_get_cell(&self, row: usize, col: usize) -> Option<String> {
|
||||||
+ let mut buf = vec![0i8; 4096];
|
+ let mut buf = vec![0i8; 4096];
|
||||||
+ let n = unsafe {
|
+ let n = unsafe {
|
||||||
@@ -505,6 +519,11 @@
|
|||||||
+ unsafe { notsafe::wxbr_dvlc_col_count(self.0).max(0) as usize }
|
+ unsafe { notsafe::wxbr_dvlc_col_count(self.0).max(0) as usize }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ /// Auto-size the column at display position `pos` to fit its content.
|
||||||
|
+ pub fn dvlc_autosize_col(&self, pos: usize) {
|
||||||
|
+ unsafe { notsafe::wxbr_dvlc_autosize_col(self.0, pos as c_int) }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ /// Model column index shown at display position `pos` (after drag reorder).
|
+ /// Model column index shown at display position `pos` (after drag reorder).
|
||||||
+ pub fn dvlc_col_at_pos(&self, pos: usize) -> Option<usize> {
|
+ pub fn dvlc_col_at_pos(&self, pos: usize) -> Option<usize> {
|
||||||
+ let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };
|
+ let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };
|
||||||
@@ -548,6 +567,27 @@
|
|||||||
+ unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
+ unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ /// Set the alternating-row (zebra) background colour applied to odd rows.
|
||||||
|
+ /// Pass `None` to turn zebra striping off.
|
||||||
|
+ pub fn dvlc_set_zebra(&self, color: Option<(u8, u8, u8)>) {
|
||||||
|
+ let (r, g, b) = match color {
|
||||||
|
+ Some((r, g, b)) => (r as c_int, g as c_int, b as c_int),
|
||||||
|
+ None => (-1, -1, -1),
|
||||||
|
+ };
|
||||||
|
+ unsafe { notsafe::wxbr_dvlc_set_zebra(self.0, r, g, b) }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /// The model-row index of the top (first visible) row, or `None` if empty.
|
||||||
|
+ pub fn dvlc_get_top_row(&self) -> Option<usize> {
|
||||||
|
+ let r = unsafe { notsafe::wxbr_dvlc_get_top_row(self.0) };
|
||||||
|
+ (r >= 0).then_some(r as usize)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /// Scroll so `row` is visible (used to restore scroll position after a refill).
|
||||||
|
+ pub fn dvlc_ensure_visible(&self, row: usize) {
|
||||||
|
+ unsafe { notsafe::wxbr_dvlc_ensure_visible(self.0, row) }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ // ---- rearrangeable check-list ----
|
+ // ---- rearrangeable check-list ----
|
||||||
+
|
+
|
||||||
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||||
|
|||||||
+176
-9
@@ -1,6 +1,6 @@
|
|||||||
--- a/cpp_src/widgets_bridge.cpp
|
--- a/cpp_src/widgets_bridge.cpp
|
||||||
+++ b/cpp_src/widgets_bridge.cpp
|
+++ b/cpp_src/widgets_bridge.cpp
|
||||||
@@ -0,0 +1,892 @@
|
@@ -0,0 +1,1059 @@
|
||||||
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
|
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
|
||||||
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
|
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
|
||||||
+// render-callback bridge (which is kept untouched).
|
+// render-callback bridge (which is kept untouched).
|
||||||
@@ -34,11 +34,24 @@
|
|||||||
+#include <wx/filedlg.h>
|
+#include <wx/filedlg.h>
|
||||||
+#include <cstring>
|
+#include <cstring>
|
||||||
+#include <cstdio>
|
+#include <cstdio>
|
||||||
|
+#include <map>
|
||||||
+#include <vector>
|
+#include <vector>
|
||||||
|
+#ifdef __WXGTK__
|
||||||
|
+// For native GtkTreeView rubber-band (click-drag) selection, which wx does not
|
||||||
|
+// enable and which cannot be done via wx mouse events on GTK (the native widget
|
||||||
|
+// grabs the pointer during a drag). Guarded so non-GTK builds are unaffected.
|
||||||
|
+#include <gtk/gtk.h>
|
||||||
|
+#endif
|
||||||
+
|
+
|
||||||
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
||||||
+static WxWidgetEventFn g_widget_event = nullptr;
|
+static WxWidgetEventFn g_widget_event = nullptr;
|
||||||
+
|
+
|
||||||
|
+#ifndef __WXGTK__
|
||||||
|
+// Anchor row per data-view control for the wx-mouse-event rubber-band fallback
|
||||||
|
+// (non-GTK platforms; GTK uses native GtkTreeView rubber-banding instead).
|
||||||
|
+static std::map<wxDataViewCtrl*, int> g_drag_anchor;
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
+// Event kinds (must match Rust WxEventKind in src/widgets.rs)
|
+// Event kinds (must match Rust WxEventKind in src/widgets.rs)
|
||||||
+enum WxWidgetEventKind {
|
+enum WxWidgetEventKind {
|
||||||
+ WxEV_BUTTON_CLICKED = 1,
|
+ WxEV_BUTTON_CLICKED = 1,
|
||||||
@@ -54,23 +67,35 @@
|
|||||||
+ WxEV_CHOICE_CHANGED = 12,
|
+ WxEV_CHOICE_CHANGED = 12,
|
||||||
+ WxEV_SYS_COLOUR = 13,
|
+ WxEV_SYS_COLOUR = 13,
|
||||||
+ WxEV_DEFERRED = 14,
|
+ WxEV_DEFERRED = 14,
|
||||||
|
+ WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
|
||||||
+};
|
+};
|
||||||
+
|
+
|
||||||
+// A list store that carries an optional per-row foreground colour, surfaced to
|
+// A list store that carries an optional per-row foreground colour plus an
|
||||||
+// the native control via GetAttrByRow. This is how the miner table paints each
|
+// alternating-row (zebra) background, surfaced to the native control via
|
||||||
+// row's text by status and separates rows on GTK (where SetAlternateRowColour
|
+// GetAttrByRow. The zebra background is set on odd rows only; because it is a
|
||||||
+// and :nth-child CSS are unreliable and fight the selection highlight).
|
+// BACKGROUND attr (not a foreground one), it does not affect the SegmentRenderer
|
||||||
|
+// "no explicit colour -> default text colour" path, and the native selection
|
||||||
|
+// highlight still paints over it for selected rows.
|
||||||
+class AttrListStore : public wxDataViewListStore {
|
+class AttrListStore : public wxDataViewListStore {
|
||||||
+ public:
|
+ public:
|
||||||
+ std::vector<wxColour> row_fg;
|
+ std::vector<wxColour> row_fg;
|
||||||
|
+ wxColour zebra; // odd-row background; unset (=off) unless the app sets it
|
||||||
|
+ // Per-cell hover tooltip text, keyed by (row, model column). Used for the
|
||||||
|
+ // Errors column's full-message tooltip (see the GTK query-tooltip handler).
|
||||||
|
+ std::map<std::pair<unsigned, unsigned>, wxString> cell_tip;
|
||||||
+ bool GetAttrByRow(unsigned int row, unsigned int col,
|
+ bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||||
+ wxDataViewItemAttr& attr) const override {
|
+ wxDataViewItemAttr& attr) const override {
|
||||||
+ (void)col;
|
+ (void)col;
|
||||||
|
+ bool set = false;
|
||||||
+ if (row < row_fg.size() && row_fg[row].IsOk()) {
|
+ if (row < row_fg.size() && row_fg[row].IsOk()) {
|
||||||
+ attr.SetColour(row_fg[row]);
|
+ attr.SetColour(row_fg[row]);
|
||||||
+ return true;
|
+ set = true;
|
||||||
+ }
|
+ }
|
||||||
+ return false;
|
+ if (zebra.IsOk() && (row % 2 == 1)) {
|
||||||
|
+ attr.SetBackgroundColour(zebra);
|
||||||
|
+ set = true;
|
||||||
|
+ }
|
||||||
|
+ return set;
|
||||||
+ }
|
+ }
|
||||||
+};
|
+};
|
||||||
+
|
+
|
||||||
@@ -191,7 +216,11 @@
|
|||||||
+// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
+// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
||||||
+// set_sizer_on calls as wxbr_box_sizer's result.
|
+// set_sizer_on calls as wxbr_box_sizer's result.
|
||||||
+void* wxbr_wrap_sizer(int vertical) {
|
+void* wxbr_wrap_sizer(int vertical) {
|
||||||
+ return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL);
|
+ // wxREMOVE_LEADING_SPACES only: drop the default wxEXTEND_LAST_ON_EACH_LINE so
|
||||||
|
+ // the last item on a line is NOT stretched to fill the row (keeps fixed-size
|
||||||
|
+ // items -- e.g. the uniform KPI cards -- the same size).
|
||||||
|
+ return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL,
|
||||||
|
+ wxREMOVE_LEADING_SPACES);
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+// flag bits (must match Rust sizer_flags):
|
+// flag bits (must match Rust sizer_flags):
|
||||||
@@ -436,13 +465,44 @@
|
|||||||
+ return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
|
+ return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
|
+#ifdef __WXGTK__
|
||||||
|
+// GtkTreeView "query-tooltip" handler: show the per-cell tooltip stored for the
|
||||||
|
+// (row, model column) under the pointer (used by the Errors column). wx does
|
||||||
|
+// not surface per-cell tooltips on wxDataViewCtrl, and mouse-motion events are
|
||||||
|
+// not delivered to wx handlers on the native GTK control, so this hooks the
|
||||||
|
+// native signal directly.
|
||||||
|
+static gboolean dvlc_query_tooltip(GtkWidget* tv, gint x, gint y, gboolean keyboard,
|
||||||
|
+ GtkTooltip* tooltip, gpointer user_data) {
|
||||||
|
+ (void)keyboard;
|
||||||
|
+ wxDataViewCtrl* dv = static_cast<wxDataViewCtrl*>(user_data);
|
||||||
|
+ gint bx = 0, by = 0;
|
||||||
|
+ gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(tv), x, y, &bx, &by);
|
||||||
|
+ GtkTreePath* path = nullptr;
|
||||||
|
+ GtkTreeViewColumn* gcol = nullptr;
|
||||||
|
+ if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), bx, by, &path, &gcol, nullptr, nullptr))
|
||||||
|
+ return FALSE;
|
||||||
|
+ gint* idx = gtk_tree_path_get_indices(path);
|
||||||
|
+ int row = idx ? idx[0] : -1;
|
||||||
|
+ gtk_tree_path_free(path);
|
||||||
|
+ if (row < 0 || !gcol) return FALSE;
|
||||||
|
+ wxDataViewColumn* wxcol = dv->GTKColumnToWX(gcol);
|
||||||
|
+ if (!wxcol) return FALSE;
|
||||||
|
+ AttrListStore* store = static_cast<AttrListStore*>(dv->GetModel());
|
||||||
|
+ auto it = store->cell_tip.find({(unsigned)row, wxcol->GetModelColumn()});
|
||||||
|
+ if (it == store->cell_tip.end() || it->second.IsEmpty()) return FALSE;
|
||||||
|
+ gtk_tooltip_set_text(tooltip, it->second.utf8_str());
|
||||||
|
+ return TRUE;
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
+void* wxbr_dvlc(void* parent) {
|
+void* wxbr_dvlc(void* parent) {
|
||||||
+ // Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
|
+ // Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
|
||||||
+ // checkbox column. A custom AttrListStore backs it so rows can be coloured by
|
+ // checkbox column. A custom AttrListStore backs it so rows can be coloured by
|
||||||
+ // status while the native selection highlight still shows through.
|
+ // status while the native selection highlight still shows through.
|
||||||
+ wxDataViewCtrl* dv =
|
+ wxDataViewCtrl* dv =
|
||||||
+ new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
+ new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||||
+ wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
|
+ wxSize(-1, -1),
|
||||||
|
+ wxDV_ROW_LINES | wxDV_VERT_RULES | wxDV_MULTIPLE);
|
||||||
+ AttrListStore* store = new AttrListStore();
|
+ AttrListStore* store = new AttrListStore();
|
||||||
+ dv->AssociateModel(store);
|
+ dv->AssociateModel(store);
|
||||||
+ store->DecRef(); // the control owns a reference now
|
+ store->DecRef(); // the control owns a reference now
|
||||||
@@ -465,9 +525,73 @@
|
|||||||
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
|
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
|
||||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
|
+ if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
|
||||||
+ });
|
+ });
|
||||||
|
+ // Right-click on a column header: Excel-style per-column menu (hide/sort/...).
|
||||||
|
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, [](wxDataViewEvent& e) {
|
||||||
|
+ if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_RIGHT_CLICK, (long)e.GetColumn(), 0);
|
||||||
|
+ });
|
||||||
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
|
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
|
||||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
|
+ if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
|
||||||
+ });
|
+ });
|
||||||
|
+ // Rubber-band (click-drag) range selection. wxDataViewCtrl has none natively.
|
||||||
|
+#ifdef __WXGTK__
|
||||||
|
+ // On GTK the control wraps a GtkTreeView, which supports native rubber-band
|
||||||
|
+ // selection -- just not enabled by wx. Enable it directly. (wx delivers no
|
||||||
|
+ // MOTION events during the native drag, so the mouse-event fallback below is
|
||||||
|
+ // inapplicable on GTK.)
|
||||||
|
+ {
|
||||||
|
+ GtkWidget* tv = dv->GtkGetTreeView();
|
||||||
|
+ if (tv) {
|
||||||
|
+ gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
|
||||||
|
+ // Per-cell hover tooltips (Errors column) via the native signal.
|
||||||
|
+ gtk_widget_set_has_tooltip(tv, TRUE);
|
||||||
|
+ g_signal_connect(tv, "query-tooltip", G_CALLBACK(dvlc_query_tooltip), dv);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+#else
|
||||||
|
+ // Non-GTK fallback: track a drag anchor and extend the selection to the row
|
||||||
|
+ // under the cursor. LEFT_DOWN records the anchor (and lets the native handler
|
||||||
|
+ // select it); dragging with the button down selects the inclusive range.
|
||||||
|
+ dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
|
||||||
|
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||||
|
+ if (!dv) { e.Skip(); return; }
|
||||||
|
+ // Leave modifier-clicks to the native ctrl/shift multi-select behaviour.
|
||||||
|
+ if (e.ControlDown() || e.ShiftDown()) { g_drag_anchor.erase(dv); e.Skip(); return; }
|
||||||
|
+ wxDataViewItem item;
|
||||||
|
+ wxDataViewColumn* col = nullptr;
|
||||||
|
+ dv->HitTest(e.GetPosition(), item, col);
|
||||||
|
+ if (item.IsOk()) {
|
||||||
|
+ g_drag_anchor[dv] =
|
||||||
|
+ (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||||
|
+ } else {
|
||||||
|
+ g_drag_anchor.erase(dv);
|
||||||
|
+ }
|
||||||
|
+ e.Skip(); // let the native handler select the anchor row
|
||||||
|
+ });
|
||||||
|
+ dv->Bind(wxEVT_MOTION, [](wxMouseEvent& e) {
|
||||||
|
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||||
|
+ if (!dv || !e.LeftIsDown()) { e.Skip(); return; }
|
||||||
|
+ auto it = g_drag_anchor.find(dv);
|
||||||
|
+ if (it == g_drag_anchor.end()) { e.Skip(); return; }
|
||||||
|
+ wxDataViewItem item;
|
||||||
|
+ wxDataViewColumn* col = nullptr;
|
||||||
|
+ dv->HitTest(e.GetPosition(), item, col);
|
||||||
|
+ if (!item.IsOk()) { e.Skip(); return; }
|
||||||
|
+ wxDataViewIndexListModel* model = (wxDataViewIndexListModel*)dv->GetModel();
|
||||||
|
+ int cur = (int)model->GetRow(item);
|
||||||
|
+ int lo = it->second < cur ? it->second : cur;
|
||||||
|
+ int hi = it->second < cur ? cur : it->second;
|
||||||
|
+ dv->UnselectAll();
|
||||||
|
+ for (int r = lo; r <= hi; ++r) dv->Select(model->GetItem((unsigned)r));
|
||||||
|
+ // Selecting programmatically does not emit SELECTION_CHANGED, so notify.
|
||||||
|
+ if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||||
|
+ e.Skip();
|
||||||
|
+ });
|
||||||
|
+ dv->Bind(wxEVT_LEFT_UP, [](wxMouseEvent& e) {
|
||||||
|
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||||
|
+ if (dv) g_drag_anchor.erase(dv);
|
||||||
|
+ e.Skip();
|
||||||
|
+ });
|
||||||
|
+#endif
|
||||||
+ // Row activation (double-click / Enter): report the row + column so the app
|
+ // Row activation (double-click / Enter): report the row + column so the app
|
||||||
+ // can, e.g., open the miner's IP in a browser.
|
+ // can, e.g., open the miner's IP in a browser.
|
||||||
+ dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
|
+ dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
|
||||||
@@ -539,6 +663,18 @@
|
|||||||
+ AttrListStore* store = dvlc_store(win);
|
+ AttrListStore* store = dvlc_store(win);
|
||||||
+ store->DeleteAllItems();
|
+ store->DeleteAllItems();
|
||||||
+ store->row_fg.clear();
|
+ store->row_fg.clear();
|
||||||
|
+ store->cell_tip.clear();
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+// Set (or clear, with an empty string) the hover tooltip for one cell,
|
||||||
|
+// addressed by (row, model column). Used for the Errors column's full text.
|
||||||
|
+void wxbr_dvlc_set_cell_tooltip(void* win, unsigned row, unsigned col, const char* text) {
|
||||||
|
+ AttrListStore* store = dvlc_store(win);
|
||||||
|
+ if (text && text[0]) {
|
||||||
|
+ store->cell_tip[{row, col}] = wxString::FromUTF8(text);
|
||||||
|
+ } else {
|
||||||
|
+ store->cell_tip.erase({row, col});
|
||||||
|
+ }
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
|
+// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
|
||||||
@@ -549,6 +685,29 @@
|
|||||||
+ store->RowChanged(row);
|
+ store->RowChanged(row);
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
|
+// Set (or clear, when r<0) the alternating-row (zebra) background colour. The
|
||||||
|
+// app passes a theme-aware colour; odd rows get it (see AttrListStore).
|
||||||
|
+void wxbr_dvlc_set_zebra(void* win, int r, int g, int b) {
|
||||||
|
+ dvlc_store(win)->zebra = (r < 0) ? wxColour() : wxColour(r, g, b);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+// The model-row index of the first (top) visible row, or -1 if none. Used to
|
||||||
|
+// hold the scroll position across a full clear+refill during a live scan.
|
||||||
|
+int wxbr_dvlc_get_top_row(void* win) {
|
||||||
|
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||||
|
+ wxDataViewItem item = dv->GetTopItem();
|
||||||
|
+ if (!item.IsOk()) return -1;
|
||||||
|
+ return (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+// Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the
|
||||||
|
+// scroll position after a refill). Out-of-range rows are ignored.
|
||||||
|
+void wxbr_dvlc_ensure_visible(void* win, unsigned row) {
|
||||||
|
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||||
|
+ wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row);
|
||||||
|
+ if (item.IsOk()) dv->EnsureVisible(item);
|
||||||
|
+}
|
||||||
|
+
|
||||||
+int wxbr_dvlc_row_count(void* win) {
|
+int wxbr_dvlc_row_count(void* win) {
|
||||||
+ return (int)dvlc_store(win)->GetItemCount();
|
+ return (int)dvlc_store(win)->GetItemCount();
|
||||||
+}
|
+}
|
||||||
@@ -579,6 +738,14 @@
|
|||||||
+ return (int)((wxDataViewCtrl*)win)->GetColumnCount();
|
+ return (int)((wxDataViewCtrl*)win)->GetColumnCount();
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
|
+// Auto-size a column (by display position) to fit its content + header.
|
||||||
|
+void wxbr_dvlc_autosize_col(void* win, int pos) {
|
||||||
|
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||||
|
+ if (pos < 0 || (unsigned)pos >= dv->GetColumnCount()) return;
|
||||||
|
+ wxDataViewColumn* c = dv->GetColumn((unsigned)pos);
|
||||||
|
+ if (c) c->SetWidth(wxCOL_WIDTH_AUTOSIZE);
|
||||||
|
+}
|
||||||
|
+
|
||||||
+// Update a column's header text in place (creation index) without recreating
|
+// Update a column's header text in place (creation index) without recreating
|
||||||
+// the control -- used to refresh the ASCII sort marker on a sort click.
|
+// the control -- used to refresh the ASCII sort marker on a sort click.
|
||||||
+void wxbr_dvlc_set_col_title(void* win, int col, const char* title) {
|
+void wxbr_dvlc_set_col_title(void* win, int col, const char* title) {
|
||||||
|
|||||||
+175
-8
@@ -31,11 +31,24 @@
|
|||||||
#include <wx/filedlg.h>
|
#include <wx/filedlg.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
// For native GtkTreeView rubber-band (click-drag) selection, which wx does not
|
||||||
|
// enable and which cannot be done via wx mouse events on GTK (the native widget
|
||||||
|
// grabs the pointer during a drag). Guarded so non-GTK builds are unaffected.
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
||||||
static WxWidgetEventFn g_widget_event = nullptr;
|
static WxWidgetEventFn g_widget_event = nullptr;
|
||||||
|
|
||||||
|
#ifndef __WXGTK__
|
||||||
|
// Anchor row per data-view control for the wx-mouse-event rubber-band fallback
|
||||||
|
// (non-GTK platforms; GTK uses native GtkTreeView rubber-banding instead).
|
||||||
|
static std::map<wxDataViewCtrl*, int> g_drag_anchor;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Event kinds (must match Rust WxEventKind in src/widgets.rs)
|
// Event kinds (must match Rust WxEventKind in src/widgets.rs)
|
||||||
enum WxWidgetEventKind {
|
enum WxWidgetEventKind {
|
||||||
WxEV_BUTTON_CLICKED = 1,
|
WxEV_BUTTON_CLICKED = 1,
|
||||||
@@ -51,23 +64,35 @@ enum WxWidgetEventKind {
|
|||||||
WxEV_CHOICE_CHANGED = 12,
|
WxEV_CHOICE_CHANGED = 12,
|
||||||
WxEV_SYS_COLOUR = 13,
|
WxEV_SYS_COLOUR = 13,
|
||||||
WxEV_DEFERRED = 14,
|
WxEV_DEFERRED = 14,
|
||||||
|
WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
|
||||||
};
|
};
|
||||||
|
|
||||||
// A list store that carries an optional per-row foreground colour, surfaced to
|
// A list store that carries an optional per-row foreground colour plus an
|
||||||
// the native control via GetAttrByRow. This is how the miner table paints each
|
// alternating-row (zebra) background, surfaced to the native control via
|
||||||
// row's text by status and separates rows on GTK (where SetAlternateRowColour
|
// GetAttrByRow. The zebra background is set on odd rows only; because it is a
|
||||||
// and :nth-child CSS are unreliable and fight the selection highlight).
|
// BACKGROUND attr (not a foreground one), it does not affect the SegmentRenderer
|
||||||
|
// "no explicit colour -> default text colour" path, and the native selection
|
||||||
|
// highlight still paints over it for selected rows.
|
||||||
class AttrListStore : public wxDataViewListStore {
|
class AttrListStore : public wxDataViewListStore {
|
||||||
public:
|
public:
|
||||||
std::vector<wxColour> row_fg;
|
std::vector<wxColour> row_fg;
|
||||||
|
wxColour zebra; // odd-row background; unset (=off) unless the app sets it
|
||||||
|
// Per-cell hover tooltip text, keyed by (row, model column). Used for the
|
||||||
|
// Errors column's full-message tooltip (see the GTK query-tooltip handler).
|
||||||
|
std::map<std::pair<unsigned, unsigned>, wxString> cell_tip;
|
||||||
bool GetAttrByRow(unsigned int row, unsigned int col,
|
bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||||
wxDataViewItemAttr& attr) const override {
|
wxDataViewItemAttr& attr) const override {
|
||||||
(void)col;
|
(void)col;
|
||||||
|
bool set = false;
|
||||||
if (row < row_fg.size() && row_fg[row].IsOk()) {
|
if (row < row_fg.size() && row_fg[row].IsOk()) {
|
||||||
attr.SetColour(row_fg[row]);
|
attr.SetColour(row_fg[row]);
|
||||||
return true;
|
set = true;
|
||||||
}
|
}
|
||||||
return false;
|
if (zebra.IsOk() && (row % 2 == 1)) {
|
||||||
|
attr.SetBackgroundColour(zebra);
|
||||||
|
set = true;
|
||||||
|
}
|
||||||
|
return set;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,7 +213,11 @@ void* wxbr_box_sizer(int vertical) {
|
|||||||
// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
||||||
// set_sizer_on calls as wxbr_box_sizer's result.
|
// set_sizer_on calls as wxbr_box_sizer's result.
|
||||||
void* wxbr_wrap_sizer(int vertical) {
|
void* wxbr_wrap_sizer(int vertical) {
|
||||||
return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL);
|
// wxREMOVE_LEADING_SPACES only: drop the default wxEXTEND_LAST_ON_EACH_LINE so
|
||||||
|
// the last item on a line is NOT stretched to fill the row (keeps fixed-size
|
||||||
|
// items -- e.g. the uniform KPI cards -- the same size).
|
||||||
|
return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL,
|
||||||
|
wxREMOVE_LEADING_SPACES);
|
||||||
}
|
}
|
||||||
|
|
||||||
// flag bits (must match Rust sizer_flags):
|
// flag bits (must match Rust sizer_flags):
|
||||||
@@ -433,13 +462,44 @@ static AttrListStore* dvlc_store(void* win) {
|
|||||||
return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
|
return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
// GtkTreeView "query-tooltip" handler: show the per-cell tooltip stored for the
|
||||||
|
// (row, model column) under the pointer (used by the Errors column). wx does
|
||||||
|
// not surface per-cell tooltips on wxDataViewCtrl, and mouse-motion events are
|
||||||
|
// not delivered to wx handlers on the native GTK control, so this hooks the
|
||||||
|
// native signal directly.
|
||||||
|
static gboolean dvlc_query_tooltip(GtkWidget* tv, gint x, gint y, gboolean keyboard,
|
||||||
|
GtkTooltip* tooltip, gpointer user_data) {
|
||||||
|
(void)keyboard;
|
||||||
|
wxDataViewCtrl* dv = static_cast<wxDataViewCtrl*>(user_data);
|
||||||
|
gint bx = 0, by = 0;
|
||||||
|
gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(tv), x, y, &bx, &by);
|
||||||
|
GtkTreePath* path = nullptr;
|
||||||
|
GtkTreeViewColumn* gcol = nullptr;
|
||||||
|
if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), bx, by, &path, &gcol, nullptr, nullptr))
|
||||||
|
return FALSE;
|
||||||
|
gint* idx = gtk_tree_path_get_indices(path);
|
||||||
|
int row = idx ? idx[0] : -1;
|
||||||
|
gtk_tree_path_free(path);
|
||||||
|
if (row < 0 || !gcol) return FALSE;
|
||||||
|
wxDataViewColumn* wxcol = dv->GTKColumnToWX(gcol);
|
||||||
|
if (!wxcol) return FALSE;
|
||||||
|
AttrListStore* store = static_cast<AttrListStore*>(dv->GetModel());
|
||||||
|
auto it = store->cell_tip.find({(unsigned)row, wxcol->GetModelColumn()});
|
||||||
|
if (it == store->cell_tip.end() || it->second.IsEmpty()) return FALSE;
|
||||||
|
gtk_tooltip_set_text(tooltip, it->second.utf8_str());
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void* wxbr_dvlc(void* parent) {
|
void* wxbr_dvlc(void* parent) {
|
||||||
// Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
|
// Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
|
||||||
// checkbox column. A custom AttrListStore backs it so rows can be coloured by
|
// checkbox column. A custom AttrListStore backs it so rows can be coloured by
|
||||||
// status while the native selection highlight still shows through.
|
// status while the native selection highlight still shows through.
|
||||||
wxDataViewCtrl* dv =
|
wxDataViewCtrl* dv =
|
||||||
new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||||
wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
|
wxSize(-1, -1),
|
||||||
|
wxDV_ROW_LINES | wxDV_VERT_RULES | wxDV_MULTIPLE);
|
||||||
AttrListStore* store = new AttrListStore();
|
AttrListStore* store = new AttrListStore();
|
||||||
dv->AssociateModel(store);
|
dv->AssociateModel(store);
|
||||||
store->DecRef(); // the control owns a reference now
|
store->DecRef(); // the control owns a reference now
|
||||||
@@ -462,9 +522,73 @@ void* wxbr_dvlc(void* parent) {
|
|||||||
dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
|
dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
|
||||||
if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
|
if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
|
||||||
});
|
});
|
||||||
|
// Right-click on a column header: Excel-style per-column menu (hide/sort/...).
|
||||||
|
dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, [](wxDataViewEvent& e) {
|
||||||
|
if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_RIGHT_CLICK, (long)e.GetColumn(), 0);
|
||||||
|
});
|
||||||
dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
|
dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
|
||||||
if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
|
if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
|
||||||
});
|
});
|
||||||
|
// Rubber-band (click-drag) range selection. wxDataViewCtrl has none natively.
|
||||||
|
#ifdef __WXGTK__
|
||||||
|
// On GTK the control wraps a GtkTreeView, which supports native rubber-band
|
||||||
|
// selection -- just not enabled by wx. Enable it directly. (wx delivers no
|
||||||
|
// MOTION events during the native drag, so the mouse-event fallback below is
|
||||||
|
// inapplicable on GTK.)
|
||||||
|
{
|
||||||
|
GtkWidget* tv = dv->GtkGetTreeView();
|
||||||
|
if (tv) {
|
||||||
|
gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
|
||||||
|
// Per-cell hover tooltips (Errors column) via the native signal.
|
||||||
|
gtk_widget_set_has_tooltip(tv, TRUE);
|
||||||
|
g_signal_connect(tv, "query-tooltip", G_CALLBACK(dvlc_query_tooltip), dv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// Non-GTK fallback: track a drag anchor and extend the selection to the row
|
||||||
|
// under the cursor. LEFT_DOWN records the anchor (and lets the native handler
|
||||||
|
// select it); dragging with the button down selects the inclusive range.
|
||||||
|
dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
|
||||||
|
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||||
|
if (!dv) { e.Skip(); return; }
|
||||||
|
// Leave modifier-clicks to the native ctrl/shift multi-select behaviour.
|
||||||
|
if (e.ControlDown() || e.ShiftDown()) { g_drag_anchor.erase(dv); e.Skip(); return; }
|
||||||
|
wxDataViewItem item;
|
||||||
|
wxDataViewColumn* col = nullptr;
|
||||||
|
dv->HitTest(e.GetPosition(), item, col);
|
||||||
|
if (item.IsOk()) {
|
||||||
|
g_drag_anchor[dv] =
|
||||||
|
(int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||||
|
} else {
|
||||||
|
g_drag_anchor.erase(dv);
|
||||||
|
}
|
||||||
|
e.Skip(); // let the native handler select the anchor row
|
||||||
|
});
|
||||||
|
dv->Bind(wxEVT_MOTION, [](wxMouseEvent& e) {
|
||||||
|
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||||
|
if (!dv || !e.LeftIsDown()) { e.Skip(); return; }
|
||||||
|
auto it = g_drag_anchor.find(dv);
|
||||||
|
if (it == g_drag_anchor.end()) { e.Skip(); return; }
|
||||||
|
wxDataViewItem item;
|
||||||
|
wxDataViewColumn* col = nullptr;
|
||||||
|
dv->HitTest(e.GetPosition(), item, col);
|
||||||
|
if (!item.IsOk()) { e.Skip(); return; }
|
||||||
|
wxDataViewIndexListModel* model = (wxDataViewIndexListModel*)dv->GetModel();
|
||||||
|
int cur = (int)model->GetRow(item);
|
||||||
|
int lo = it->second < cur ? it->second : cur;
|
||||||
|
int hi = it->second < cur ? cur : it->second;
|
||||||
|
dv->UnselectAll();
|
||||||
|
for (int r = lo; r <= hi; ++r) dv->Select(model->GetItem((unsigned)r));
|
||||||
|
// Selecting programmatically does not emit SELECTION_CHANGED, so notify.
|
||||||
|
if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||||
|
e.Skip();
|
||||||
|
});
|
||||||
|
dv->Bind(wxEVT_LEFT_UP, [](wxMouseEvent& e) {
|
||||||
|
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||||
|
if (dv) g_drag_anchor.erase(dv);
|
||||||
|
e.Skip();
|
||||||
|
});
|
||||||
|
#endif
|
||||||
// Row activation (double-click / Enter): report the row + column so the app
|
// Row activation (double-click / Enter): report the row + column so the app
|
||||||
// can, e.g., open the miner's IP in a browser.
|
// can, e.g., open the miner's IP in a browser.
|
||||||
dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
|
dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
|
||||||
@@ -536,6 +660,18 @@ void wxbr_dvlc_clear(void* win) {
|
|||||||
AttrListStore* store = dvlc_store(win);
|
AttrListStore* store = dvlc_store(win);
|
||||||
store->DeleteAllItems();
|
store->DeleteAllItems();
|
||||||
store->row_fg.clear();
|
store->row_fg.clear();
|
||||||
|
store->cell_tip.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set (or clear, with an empty string) the hover tooltip for one cell,
|
||||||
|
// addressed by (row, model column). Used for the Errors column's full text.
|
||||||
|
void wxbr_dvlc_set_cell_tooltip(void* win, unsigned row, unsigned col, const char* text) {
|
||||||
|
AttrListStore* store = dvlc_store(win);
|
||||||
|
if (text && text[0]) {
|
||||||
|
store->cell_tip[{row, col}] = wxString::FromUTF8(text);
|
||||||
|
} else {
|
||||||
|
store->cell_tip.erase({row, col});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
|
// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
|
||||||
@@ -546,6 +682,29 @@ void wxbr_dvlc_set_row_color(void* win, unsigned row, int r, int g, int b) {
|
|||||||
store->RowChanged(row);
|
store->RowChanged(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set (or clear, when r<0) the alternating-row (zebra) background colour. The
|
||||||
|
// app passes a theme-aware colour; odd rows get it (see AttrListStore).
|
||||||
|
void wxbr_dvlc_set_zebra(void* win, int r, int g, int b) {
|
||||||
|
dvlc_store(win)->zebra = (r < 0) ? wxColour() : wxColour(r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The model-row index of the first (top) visible row, or -1 if none. Used to
|
||||||
|
// hold the scroll position across a full clear+refill during a live scan.
|
||||||
|
int wxbr_dvlc_get_top_row(void* win) {
|
||||||
|
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||||
|
wxDataViewItem item = dv->GetTopItem();
|
||||||
|
if (!item.IsOk()) return -1;
|
||||||
|
return (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the
|
||||||
|
// scroll position after a refill). Out-of-range rows are ignored.
|
||||||
|
void wxbr_dvlc_ensure_visible(void* win, unsigned row) {
|
||||||
|
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||||
|
wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row);
|
||||||
|
if (item.IsOk()) dv->EnsureVisible(item);
|
||||||
|
}
|
||||||
|
|
||||||
int wxbr_dvlc_row_count(void* win) {
|
int wxbr_dvlc_row_count(void* win) {
|
||||||
return (int)dvlc_store(win)->GetItemCount();
|
return (int)dvlc_store(win)->GetItemCount();
|
||||||
}
|
}
|
||||||
@@ -576,6 +735,14 @@ int wxbr_dvlc_col_count(void* win) {
|
|||||||
return (int)((wxDataViewCtrl*)win)->GetColumnCount();
|
return (int)((wxDataViewCtrl*)win)->GetColumnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-size a column (by display position) to fit its content + header.
|
||||||
|
void wxbr_dvlc_autosize_col(void* win, int pos) {
|
||||||
|
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||||
|
if (pos < 0 || (unsigned)pos >= dv->GetColumnCount()) return;
|
||||||
|
wxDataViewColumn* c = dv->GetColumn((unsigned)pos);
|
||||||
|
if (c) c->SetWidth(wxCOL_WIDTH_AUTOSIZE);
|
||||||
|
}
|
||||||
|
|
||||||
// Update a column's header text in place (creation index) without recreating
|
// Update a column's header text in place (creation index) without recreating
|
||||||
// the control -- used to refresh the ASCII sort marker on a sort click.
|
// the control -- used to refresh the ASCII sort marker on a sort click.
|
||||||
void wxbr_dvlc_set_col_title(void* win, int col, const char* title) {
|
void wxbr_dvlc_set_col_title(void* win, int col, const char* title) {
|
||||||
|
|||||||
@@ -58,8 +58,10 @@ mod notsafe {
|
|||||||
pub fn wxbr_dvlc_clear(win: *mut c_void);
|
pub fn wxbr_dvlc_clear(win: *mut c_void);
|
||||||
pub fn wxbr_dvlc_row_count(win: *mut c_void) -> c_int;
|
pub fn wxbr_dvlc_row_count(win: *mut c_void) -> c_int;
|
||||||
pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
|
pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
|
||||||
|
pub fn wxbr_dvlc_set_cell_tooltip(win: *mut c_void, row: usize, col: usize, text: *const c_char);
|
||||||
pub fn wxbr_dvlc_get_cell(win: *mut c_void, row: usize, col: usize, buf: *mut c_char, cap: c_int) -> c_int;
|
pub fn wxbr_dvlc_get_cell(win: *mut c_void, row: usize, col: usize, buf: *mut c_char, cap: c_int) -> c_int;
|
||||||
pub fn wxbr_dvlc_col_count(win: *mut c_void) -> c_int;
|
pub fn wxbr_dvlc_col_count(win: *mut c_void) -> c_int;
|
||||||
|
pub fn wxbr_dvlc_autosize_col(win: *mut c_void, pos: c_int);
|
||||||
pub fn wxbr_dvlc_set_col_title(win: *mut c_void, col: c_int, title: *const c_char);
|
pub fn wxbr_dvlc_set_col_title(win: *mut c_void, col: c_int, title: *const c_char);
|
||||||
pub fn wxbr_dvlc_set_sort_indicator(win: *mut c_void, col: c_int, active: c_int, ascending: c_int);
|
pub fn wxbr_dvlc_set_sort_indicator(win: *mut c_void, col: c_int, active: c_int, ascending: c_int);
|
||||||
pub fn wxbr_dvlc_col_at_pos(win: *mut c_void, pos: c_int) -> c_int;
|
pub fn wxbr_dvlc_col_at_pos(win: *mut c_void, pos: c_int) -> c_int;
|
||||||
@@ -69,6 +71,9 @@ mod notsafe {
|
|||||||
pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
||||||
pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||||
pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
|
pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
|
||||||
|
pub fn wxbr_dvlc_set_zebra(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||||
|
pub fn wxbr_dvlc_get_top_row(win: *mut c_void) -> c_int;
|
||||||
|
pub fn wxbr_dvlc_ensure_visible(win: *mut c_void, row: usize);
|
||||||
pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||||
pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||||
pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||||
@@ -133,6 +138,7 @@ pub enum WxEventKind {
|
|||||||
ChoiceChanged,
|
ChoiceChanged,
|
||||||
SysColour,
|
SysColour,
|
||||||
Deferred,
|
Deferred,
|
||||||
|
DvlcHeaderRightClick,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WxEventKind {
|
impl WxEventKind {
|
||||||
@@ -151,6 +157,7 @@ impl WxEventKind {
|
|||||||
12 => WxEventKind::ChoiceChanged,
|
12 => WxEventKind::ChoiceChanged,
|
||||||
13 => WxEventKind::SysColour,
|
13 => WxEventKind::SysColour,
|
||||||
14 => WxEventKind::Deferred,
|
14 => WxEventKind::Deferred,
|
||||||
|
15 => WxEventKind::DvlcHeaderRightClick,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -476,6 +483,13 @@ impl Widget {
|
|||||||
unsafe { notsafe::wxbr_dvlc_set_cell(self.0, row, col, c.as_ptr()) }
|
unsafe { notsafe::wxbr_dvlc_set_cell(self.0, row, col, c.as_ptr()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the hover tooltip for one cell (empty clears it). GTK only; a no-op
|
||||||
|
/// on other platforms until they gain per-cell tooltip support.
|
||||||
|
pub fn dvlc_set_cell_tooltip(&self, row: usize, col: usize, text: &str) {
|
||||||
|
let c = CString::new(text).unwrap_or_default();
|
||||||
|
unsafe { notsafe::wxbr_dvlc_set_cell_tooltip(self.0, row, col, c.as_ptr()) }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dvlc_get_cell(&self, row: usize, col: usize) -> Option<String> {
|
pub fn dvlc_get_cell(&self, row: usize, col: usize) -> Option<String> {
|
||||||
let mut buf = vec![0i8; 4096];
|
let mut buf = vec![0i8; 4096];
|
||||||
let n = unsafe {
|
let n = unsafe {
|
||||||
@@ -492,6 +506,11 @@ impl Widget {
|
|||||||
unsafe { notsafe::wxbr_dvlc_col_count(self.0).max(0) as usize }
|
unsafe { notsafe::wxbr_dvlc_col_count(self.0).max(0) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Auto-size the column at display position `pos` to fit its content.
|
||||||
|
pub fn dvlc_autosize_col(&self, pos: usize) {
|
||||||
|
unsafe { notsafe::wxbr_dvlc_autosize_col(self.0, pos as c_int) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Model column index shown at display position `pos` (after drag reorder).
|
/// Model column index shown at display position `pos` (after drag reorder).
|
||||||
pub fn dvlc_col_at_pos(&self, pos: usize) -> Option<usize> {
|
pub fn dvlc_col_at_pos(&self, pos: usize) -> Option<usize> {
|
||||||
let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };
|
let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };
|
||||||
@@ -535,6 +554,27 @@ impl Widget {
|
|||||||
unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the alternating-row (zebra) background colour applied to odd rows.
|
||||||
|
/// Pass `None` to turn zebra striping off.
|
||||||
|
pub fn dvlc_set_zebra(&self, color: Option<(u8, u8, u8)>) {
|
||||||
|
let (r, g, b) = match color {
|
||||||
|
Some((r, g, b)) => (r as c_int, g as c_int, b as c_int),
|
||||||
|
None => (-1, -1, -1),
|
||||||
|
};
|
||||||
|
unsafe { notsafe::wxbr_dvlc_set_zebra(self.0, r, g, b) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The model-row index of the top (first visible) row, or `None` if empty.
|
||||||
|
pub fn dvlc_get_top_row(&self) -> Option<usize> {
|
||||||
|
let r = unsafe { notsafe::wxbr_dvlc_get_top_row(self.0) };
|
||||||
|
(r >= 0).then_some(r as usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Scroll so `row` is visible (used to restore scroll position after a refill).
|
||||||
|
pub fn dvlc_ensure_visible(&self, row: usize) {
|
||||||
|
unsafe { notsafe::wxbr_dvlc_ensure_visible(self.0, row) }
|
||||||
|
}
|
||||||
|
|
||||||
// ---- rearrangeable check-list ----
|
// ---- rearrangeable check-list ----
|
||||||
|
|
||||||
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||||
|
|||||||
Reference in New Issue
Block a user