Compare commits

...
2 Commits
Author SHA1 Message Date
noahandClaude Opus 4.8 71cdf2d988 GUI round 8b.1: scroll-hold, zebra striping + vertical gridlines, default-colour text
Bridge + rendering rework (validated with a local wx-rs bridge compile + full
cargo check; CI is the build oracle).

- Scroll position hold (#2): the table no longer jumps to the top as new rows
  stream in during a scan. fill_rows captures the top visible row before the
  clear+refill and restores it after (new wx-rs bridge fns dvlc_get_top_row /
  dvlc_ensure_visible, wrapping wxDataViewCtrl::GetTopItem / EnsureVisible).
- Default-colour text (#3b): rows are no longer tinted wholesale by status. Every
  cell is now the default text colour (black in light mode, white in dark -- the
  SegmentRenderer falls back to wxSYS_COLOUR_WINDOWTEXT for any run with no
  explicit colour), so IP addresses, slashes, expected/target values and all
  non-conditional cells read in the default colour. Only the conditionally-
  formatted columns carry colour: Hashrate/Boards/Chips actual (ratio scale),
  Chip temp (blue-red), fans (grey-blue), Access (red/green), Errors (red), and
  the Status column keeps its own status colour on its own cell.
- Zebra striping (#8): odd rows get a subtle theme-aware background via the
  AttrListStore (a per-row BACKGROUND attr, so it does not disturb the
  default-foreground fallback and the native selection highlight still shows
  through). This replaces the status row-tint as the row separator. (The earlier
  abandoned attempt used SetAlternateRowColour / GTK CSS against the status
  foreground tint; removing that tint is what makes the background approach
  clean now.)
- Vertical gridlines (#8): wxDV_VERT_RULES added to the table style (row lines
  were already on), so columns have borders.
- KPI cards: wxWrapSizer now drops wxEXTEND_LAST_ON_EACH_LINE, so the last card
  on a line is no longer stretched -- the uniform-size KPI boxes stay uniform.

wx-rs patches 0002/0003 regenerated and round-trip-validated against the source.
cargo check --release --tests is clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-17 16:55:27 -06:00
noahandClaude Opus 4.8 4fea3becf6 GUI round 8a.2: PIC, Access (locked), and Errors columns
Adds the round-8 columns that asic-rs either already exposes or that we infer.
Control board type (#9) and identify-light state (#4b) were already scannable
columns; this adds the three new ones:

- PIC (#9): asic-rs does not report PIC-vs-noPIC over the network (it needs an
  on-board SSH/I2C probe -- a separate feature), so this is a best-effort
  inference from the model string ("NoPIC" variants), showing "?" when unknown.
  New MinerRow.pic_present.
- Access (#13): locked (view-only) vs unlocked (writable), inferred from whether
  the miner exposes any writable control capability (asic-rs has no direct
  lock-state field). Red = locked, green = unlocked. New MinerRow.write_locked
  and MinerCaps::any_control().
- Errors (#12): wires asic-rs's structured MinerData.messages (previously
  dropped) into MinerRow.errors as "[Severity] text (component)" lines, most
  severe first. The column shows a summary (blank / the single message / "N
  errors") in red when non-empty; the full list becomes a hover tooltip once the
  tooltip bridge support lands in 8b.

The identify-light column header is relabelled "Light" (from "Fault light") to
match the round-8 terminology. Fixtures populated with demo values so all new
columns render offline. Unit tests for the three cell renderers + any_control.

cargo check --release --tests is clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-17 16:37:21 -06:00
8 changed files with 346 additions and 37 deletions
+31
View File
@@ -106,6 +106,37 @@ impl Board {
tuning: self.mining,
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()
}
}
+87 -2
View File
@@ -212,6 +212,18 @@ impl MinerCaps {
pub fn is_empty(self) -> bool {
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
@@ -231,6 +243,19 @@ pub struct MinerRow {
pub firmware: String,
pub api_version: 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
pub hashrate_ths: f64,
pub expected_ths: f64,
@@ -344,6 +369,9 @@ pub enum Column {
Serial,
ApiVersion,
ControlBoard,
Pic,
Locked,
Error,
Uptime,
Light,
OperatingState,
@@ -361,7 +389,7 @@ pub enum Column {
/// Every column, in registry order. Ip first, then the default-visible set
/// (UI-SPEC order), then all remaining metrics.
pub const ALL_COLUMNS: [Column; 35] = [
pub const ALL_COLUMNS: [Column; 38] = [
Column::Ip,
Column::Hashrate,
Column::Power,
@@ -384,6 +412,9 @@ pub const ALL_COLUMNS: [Column; 35] = [
Column::Serial,
Column::ApiVersion,
Column::ControlBoard,
Column::Pic,
Column::Locked,
Column::Error,
Column::Uptime,
Column::Light,
Column::OperatingState,
@@ -436,8 +467,11 @@ impl Column {
Column::Serial => "Serial",
Column::ApiVersion => "API ver",
Column::ControlBoard => "Control board",
Column::Pic => "PIC",
Column::Locked => "Access",
Column::Error => "Errors",
Column::Uptime => "Uptime",
Column::Light => "Fault light",
Column::Light => "Light",
Column::OperatingState => "State",
Column::BestShare => "Best share",
Column::SessionBestShare => "Session best",
@@ -469,6 +503,9 @@ impl Column {
Column::Mac | Column::Hostname | Column::Serial => 150,
Column::ApiVersion | Column::Light => 90,
Column::ControlBoard => 130,
Column::Pic => 70,
Column::Locked => 90,
Column::Error => 160,
Column::Uptime => 100,
Column::OperatingState => 100,
Column::BestShare | Column::SessionBestShare => 110,
@@ -607,6 +644,21 @@ impl Column {
Column::Serial => r.serial.clone(),
Column::ApiVersion => r.api_version.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::Uptime => format_uptime(r.uptime_secs),
Column::Light => match r.light_flashing {
@@ -1134,6 +1186,39 @@ mod tests {
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]
fn ip_column_sorts_numerically() {
// A plain string sort puts "10.255.1.10" before "10.255.1.2"; the IP
+40
View File
@@ -397,6 +397,34 @@ pub fn start_scan(lines: Vec<String>) -> ScanHandle {
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 {
let data = miner.get_data().await;
let hashrate_ths = data
@@ -484,10 +512,22 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
tuning: miner.supports_set_tuning_percent(),
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 {
ip: data.ip.to_string(),
selected: false,
caps,
pic_present,
write_locked,
errors,
model,
mac: data.mac.map(|m| m.to_string()).unwrap_or_default(),
hostname: data.hostname.clone().unwrap_or_default(),
+50 -17
View File
@@ -82,6 +82,8 @@ struct Palette {
amber: (u8, u8, u8),
red: (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 {
@@ -159,6 +161,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
/// gets its own grey-to-blue colour by speed, and the "/" separators between
/// them stay in the default text colour.
@@ -230,14 +238,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 {
let win = wx_rs::system_color(0); // window background
let text = wx_rs::system_color(1); // window text
@@ -252,6 +252,9 @@ fn palette() -> Palette {
amber: if dark { (245, 190, 66) } else { (176, 120, 10) },
red: if dark { (245, 110, 100) } else { (198, 55, 45) },
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) },
}
}
@@ -544,6 +547,9 @@ impl App {
t.destroy();
}
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
// reorderable); the rest are reorderable. The active sort column carries
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
@@ -557,7 +563,7 @@ impl App {
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.
// expected, or one colour per fan) via a custom renderer that
// parses the segment-encoded cell value fill_rows writes.
@@ -577,6 +583,9 @@ impl App {
pub fn fill_rows(&mut self) {
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();
self.view_idx = self.view.view(&self.rows);
let cols = self.view.display_columns();
@@ -586,13 +595,12 @@ impl App {
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
t.dvlc_append_row(&refs);
}
// Colour each row's text by status (also separates rows visually).
for (disp, &ri) in self.view_idx.iter().enumerate() {
t.dvlc_set_row_color(disp, Some(status_color(&self.pal, &self.rows[ri])));
}
// Overwrite the combined actual/expected + cooling-fan cells with
// segment-encoded coloured text (the custom renderer these columns use
// parses it back out; see encode_combined_cell/encode_cooling_cell).
// Rows are NOT tinted by status any more: every cell is the default text
// colour except the conditionally-formatted columns below (the Status
// column carries the status colour itself). Zebra striping + gridlines
// (set at table build) separate rows instead.
// Overwrite the conditionally-coloured cells with segment-encoded text
// (the custom renderer these columns use parses it back out).
for (disp, &ri) in self.view_idx.iter().enumerate() {
let r = &self.rows[ri];
for (ci, c) in cols.iter().enumerate() {
@@ -632,11 +640,32 @@ impl App {
}
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::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,
};
t.dvlc_set_cell(disp, ci, &encoded);
}
}
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).
let sel: Vec<usize> = self
.view_idx
@@ -675,6 +704,9 @@ impl App {
caption.set_fg(self.pal.label.0, self.pal.label.1, self.pal.label.2);
}
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.table_parent.layout();
}
@@ -2056,7 +2088,7 @@ impl App {
for (j, c) in cols.iter().enumerate() {
let want = c.cell(r);
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)
} else {
raw
@@ -2193,6 +2225,7 @@ mod tests {
amber: (255, 128, 0),
red: (255, 0, 0),
accent: (0, 0, 255),
zebra: (245, 245, 245),
}
}
+25 -1
View File
@@ -10,7 +10,7 @@
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
@@ -0,0 +1,688 @@
@@ -0,0 +1,712 @@
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
+// wxWidgets object tree (parents own children; nothing to free in Rust).
@@ -82,6 +82,9 @@
+ 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_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_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;
@@ -548,6 +551,27 @@
+ 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 ----
+
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
+45 -9
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,892 @@
@@ -0,0 +1,928 @@
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
+// render-callback bridge (which is kept untouched).
@@ -56,21 +56,29 @@
+ WxEV_DEFERRED = 14,
+};
+
+// A list store that carries an optional per-row foreground colour, surfaced to
+// the native control via GetAttrByRow. This is how the miner table paints each
+// row's text by status and separates rows on GTK (where SetAlternateRowColour
+// and :nth-child CSS are unreliable and fight the selection highlight).
+// A list store that carries an optional per-row foreground colour plus an
+// alternating-row (zebra) background, surfaced to the native control via
+// GetAttrByRow. The zebra background is set on odd rows only; because it is a
+// 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 {
+ public:
+ std::vector<wxColour> row_fg;
+ wxColour zebra; // odd-row background; unset (=off) unless the app sets it
+ bool GetAttrByRow(unsigned int row, unsigned int col,
+ wxDataViewItemAttr& attr) const override {
+ (void)col;
+ bool set = false;
+ if (row < row_fg.size() && row_fg[row].IsOk()) {
+ 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 +199,11 @@
+// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
+// set_sizer_on calls as wxbr_box_sizer's result.
+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):
@@ -442,7 +454,8 @@
+ // status while the native selection highlight still shows through.
+ wxDataViewCtrl* dv =
+ 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();
+ dv->AssociateModel(store);
+ store->DecRef(); // the control owns a reference now
@@ -549,6 +562,29 @@
+ 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) {
+ return (int)dvlc_store(win)->GetItemCount();
+}
@@ -53,21 +53,29 @@ enum WxWidgetEventKind {
WxEV_DEFERRED = 14,
};
// A list store that carries an optional per-row foreground colour, surfaced to
// the native control via GetAttrByRow. This is how the miner table paints each
// row's text by status and separates rows on GTK (where SetAlternateRowColour
// and :nth-child CSS are unreliable and fight the selection highlight).
// A list store that carries an optional per-row foreground colour plus an
// alternating-row (zebra) background, surfaced to the native control via
// GetAttrByRow. The zebra background is set on odd rows only; because it is a
// 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 {
public:
std::vector<wxColour> row_fg;
wxColour zebra; // odd-row background; unset (=off) unless the app sets it
bool GetAttrByRow(unsigned int row, unsigned int col,
wxDataViewItemAttr& attr) const override {
(void)col;
bool set = false;
if (row < row_fg.size() && row_fg[row].IsOk()) {
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 +196,11 @@ void* wxbr_box_sizer(int vertical) {
// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
// set_sizer_on calls as wxbr_box_sizer's result.
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):
@@ -439,7 +451,8 @@ void* wxbr_dvlc(void* parent) {
// status while the native selection highlight still shows through.
wxDataViewCtrl* dv =
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();
dv->AssociateModel(store);
store->DecRef(); // the control owns a reference now
@@ -546,6 +559,29 @@ void wxbr_dvlc_set_row_color(void* win, unsigned row, int r, int g, int b) {
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) {
return (int)dvlc_store(win)->GetItemCount();
}
+24
View File
@@ -69,6 +69,9 @@ mod notsafe {
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_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_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;
@@ -535,6 +538,27 @@ impl Widget {
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 ----
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`