GUI round 2: selection, scan loop, column management, dark-mode fix

- Fixed "Scan ranges" button label (no longer grows with the range list).
- Dark-mode KPI cards: derive colours from the live system theme luminance
  instead of is_dark(), which mis-detected some GTK dark themes.
- Removed the checkbox column; the table is multi-select (wxDV_MULTIPLE,
  ctrl/shift-click), with the selection tracked by IP so it survives refreshes.
- Replaced Rescan with Play / Pause / Stop; added an editable auto-rescan
  interval (scan-ranges dialog; ~/.config/alkane-toolkit/auto-rescan-secs.txt)
  with a timer-driven countdown scheduler.
- Status bar shows the last-probed IP during a scan and a countdown to the next
  scan when idle (dropped the "scan complete" text).
- Default sort is IP-ascending with a header chevron; IP is column 0, sortable.
- Choose-columns dialog is a wxRearrangeCtrl (check to show; up/down or drag to
  reorder) exposing every metric, including Pool 1/2/3 URL + worker.
- Column drag-reorder moves the whole column with its data on drop.
- Row separator lines (wxDV_ROW_LINES). GTK3 native has no zebra striping; a
  GTK4-forward zebra-CSS hook and pkg-config gtk cflags are in place.

Scan engine: parse each configured pool's (url, worker); Progress carries the
last-probed IP. Model: Column::Sel removed; Pool1/2/3 columns; default IP sort.

wx-rs bridge: multi-select + selection/context-menu events + get_selections,
alternating-row + zebra-CSS hooks, in-place column title, rearrangeable list,
and popup-menu primitives (for the upcoming right-click config menu). Patches
0001-0003 regenerated and round-trip validated.

Review fixes: scan loop no longer sticks "scanning" if a thread ends without
Done (channel-disconnect handling + Stop force-reset); Play no longer starts a
second scan; stale selections pruned on rescan; column apply order/visibility
applied atomically.

Verified: 22 unit tests, a 14-check headless UI self-test, and interaction
checks (multi-select, column rearrange/drag, play/pause/stop, dark mode).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
2026-09-16 17:27:20 -06:00
co-authored by Claude Opus 4.8
parent d1ab6aa72a
commit bd17a33ea1
11 changed files with 821 additions and 206 deletions
+255 -137
View File
@@ -11,14 +11,13 @@ use wx_rs::{Widget, WxEvent, WxEventKind, sizer_flags as sf};
pub const ID_RANGES: i32 = 101;
pub const ID_FILTER: i32 = 102;
pub const ID_COLUMNS: i32 = 103;
pub const ID_RESCAN: i32 = 104;
pub const ID_PLAY: i32 = 104;
pub const ID_PAUSE: i32 = 105;
pub const ID_STOP: i32 = 106;
const ID_RANGES_APPLY: i32 = 201;
const ID_RANGES_CANCEL: i32 = 202;
const ID_COLUMNS_OK: i32 = 203;
const ID_COLUMNS_CANCEL: i32 = 204;
const ID_COLUMNS_ALL: i32 = 207;
const ID_COLUMNS_NONE: i32 = 208;
const ID_COLUMNS_RESET: i32 = 209;
const ID_FILTER_OK: i32 = 205;
const ID_FILTER_CANCEL: i32 = 206;
const ID_FILTER_RESET: i32 = 210;
@@ -29,7 +28,9 @@ const ID_FILTER_NONE_BASE: i32 = 500;
const TIMER_SCAN: i32 = 1;
/// Theme-aware palette for the KPI cards. Health is encoded in colour so a red
/// "Not hashing" or amber "Slow" draws the eye immediately.
/// "Not hashing" or amber "Slow" draws the eye immediately. Colours derive from
/// the live system theme so the cards follow light/dark correctly (relying on
/// wxAppearance alone left the cards white under some GTK dark themes).
struct Palette {
card_bg: (u8, u8, u8),
label: (u8, u8, u8),
@@ -40,27 +41,38 @@ struct Palette {
accent: (u8, u8, u8),
}
fn palette(dark: bool) -> Palette {
if dark {
Palette {
card_bg: (44, 46, 51),
label: (150, 156, 164),
neutral: (228, 230, 234),
green: (74, 222, 128),
amber: (245, 190, 66),
red: (245, 110, 100),
accent: (108, 168, 250),
}
fn luminance(c: (u8, u8, u8)) -> f32 {
0.299 * c.0 as f32 + 0.587 * c.1 as f32 + 0.114 * c.2 as f32
}
fn nudge(c: (u8, u8, u8), d: i32) -> (u8, u8, u8) {
let f = |v: u8| (v as i32 + d).clamp(0, 255) as u8;
(f(c.0), f(c.1), f(c.2))
}
/// Short mm:ss-ish duration for the rescan countdown ("4m 12s", "45s").
fn fmt_secs(s: u64) -> String {
if s >= 60 {
format!("{}m {:02}s", s / 60, s % 60)
} else {
Palette {
card_bg: (255, 255, 255),
label: (108, 114, 122),
neutral: (28, 32, 38),
green: (33, 140, 80),
amber: (176, 120, 10),
red: (198, 55, 45),
accent: (40, 100, 170),
}
format!("{s}s")
}
}
fn palette() -> Palette {
let win = wx_rs::system_color(0); // window background
let text = wx_rs::system_color(1); // window text
let dark = luminance(win) < 128.0;
Palette {
// Cards read as slightly elevated vs the window: lighter in dark mode,
// pure white on a light-grey window.
card_bg: if dark { nudge(win, 14) } else { (255, 255, 255) },
label: if dark { (150, 156, 164) } else { (108, 114, 122) },
neutral: text,
green: if dark { (74, 222, 128) } else { (33, 140, 80) },
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) },
}
}
@@ -74,7 +86,6 @@ pub struct App {
kpi_not: Widget,
kpi_hashrate: Widget,
kpi_power: Widget,
ranges_btn: Widget,
progress: Widget,
pub table: Option<Widget>,
table_parent: Widget,
@@ -83,8 +94,17 @@ pub struct App {
pub scanning: bool,
scan_total: usize,
target_ips: HashSet<String>,
// scan loop (play/pause/stop + auto-rescan)
playing: bool,
auto_secs: u64,
countdown: u64,
// selection (replaces the old checkbox column), tracked by IP so it
// survives table refreshes during a scan.
selected_ips: HashSet<String>,
alt_row: (u8, u8, u8),
ranges_dialog: Widget,
ranges_edit: Widget,
ranges_auto: Widget,
columns_dialog: Widget,
columns_list: Widget,
filter_dialog: Widget,
@@ -92,8 +112,12 @@ pub struct App {
}
pub fn build(frame: Widget) -> App {
let dark = wx_rs::is_dark();
let pal = palette(dark);
let pal = palette();
// Subtle alternating-row tint derived from the theme. GTK's native dataview
// ignores SetAlternateRowColour, so also install an app-wide zebra CSS.
let win = wx_rs::system_color(0);
let alt_row = if luminance(win) < 128.0 { nudge(win, 12) } else { nudge(win, -12) };
wx_rs::apply_zebra_css(alt_row.0, alt_row.1, alt_row.2);
let panel = Widget::panel(frame);
let root = Widget::box_sizer(true);
@@ -128,18 +152,23 @@ pub fn build(frame: Widget) -> App {
let kpi_power = mk_card("Est. power", pal.neutral);
root.add_sizer(kpi_row, 0, sf::EXPAND | sf::BORDER_ALL, 6);
// Controls row: scan-ranges button on the left; Filter / Columns / Rescan
// Controls row: scan-ranges + play/pause/stop on the left; Filter / Columns
// pushed to the right.
let ctl = Widget::box_sizer(false);
let ranges_btn = Widget::button(panel, "Scan ranges", ID_RANGES);
ctl.add(ranges_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
ctl.add_spacer(8);
let play_btn = Widget::button(panel, "Play", ID_PLAY);
ctl.add(play_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let pause_btn = Widget::button(panel, "Pause", ID_PAUSE);
ctl.add(pause_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let stop_btn = Widget::button(panel, "Stop", ID_STOP);
ctl.add(stop_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
ctl.add_stretch(1);
let filter_btn = Widget::button(panel, "Filter", ID_FILTER);
ctl.add(filter_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let columns_btn = Widget::button(panel, "Columns", ID_COLUMNS);
ctl.add(columns_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let rescan_btn = Widget::button(panel, "Rescan", ID_RESCAN);
ctl.add(rescan_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
root.add_sizer(ctl, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 4);
// Scan-progress bar across the top of the table (hidden when idle).
@@ -171,7 +200,6 @@ pub fn build(frame: Widget) -> App {
kpi_not,
kpi_hashrate,
kpi_power,
ranges_btn,
progress,
table: None,
table_parent,
@@ -180,14 +208,19 @@ pub fn build(frame: Widget) -> App {
scanning: true,
scan_total: 0,
target_ips: HashSet::new(),
playing: true,
auto_secs: scan::load_auto_secs(),
countdown: 0,
selected_ips: HashSet::new(),
alt_row,
ranges_dialog: frame,
ranges_edit: frame,
ranges_auto: frame,
columns_dialog: frame,
columns_list: frame,
filter_dialog: frame,
filter_lists: Vec::new(),
};
app.ranges_btn.set_label(&format!("Scan ranges: {}", ranges.join(", ")));
app.rebuild_table();
Widget::timer(TIMER_SCAN, 1000);
app
@@ -202,26 +235,25 @@ impl App {
t.destroy();
}
let t = Widget::dvlc(self.table_parent);
// creation order == display order: Sel toggle column first (fixed),
// then Ip (fixed), then the reorderable statistics columns. The active
// sort column carries an ASCII direction marker in its header ("^" asc,
// "v" desc) -- wx's native SetSortOrder re-sorts the store lexically and
// would fight our numeric sort, so we mark the header text instead.
t.dvlc_append_toggle_col(28);
for c in self.view.display_columns().iter().skip(1) {
let fixed = self.view.is_fixed(*c);
// 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
// native SetSortOrder re-sorts the store lexically and would fight our
// numeric sort, so we mark the header text instead.
for c in self.view.display_columns() {
let fixed = self.view.is_fixed(c);
let mut title = c.title().to_string();
match self.view.sort {
Some((sc, true)) if sc == *c => title.push_str(" ^"),
Some((sc, false)) if sc == *c => title.push_str(" v"),
Some((sc, true)) if sc == c => title.push_str(" ^"),
Some((sc, false)) if sc == c => title.push_str(" v"),
_ => {}
}
t.dvlc_append_text_col(&title, c.width(), !fixed);
}
t.dvlc_set_alt_row_color(self.alt_row.0, self.alt_row.1, self.alt_row.2);
// Add the table to the root sizer (proportion 1 => fills the area under
// the KPI + controls rows) and re-run the panel's layout so it is
// positioned, not left floating at (0,0). This was the "table in the
// top-left corner" bug: the control was created but never sized.
// positioned, not left floating at (0,0).
self.root_sizer.add(t, 1, sf::EXPAND | sf::BORDER_ALL, 4);
self.table = Some(t);
self.table_parent.layout();
@@ -235,18 +267,21 @@ impl App {
let cols = self.view.display_columns();
for &ri in &self.view_idx {
let r = &self.rows[ri];
// The toggle column carries the checked state ("1"/"0") so a refresh
// preserves selection; other columns carry their text.
let cells: Vec<String> = cols
.iter()
.map(|c| match c {
Column::Sel => if r.selected { "1".to_string() } else { "0".to_string() },
_ => c.cell(r),
})
.collect();
let cells: Vec<String> = cols.iter().map(|c| c.cell(r)).collect();
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
t.dvlc_append_row(&refs);
}
// Re-apply the selection (a refresh clears the control's selection).
let sel: Vec<usize> = self
.view_idx
.iter()
.enumerate()
.filter(|(_, &ri)| self.selected_ips.contains(&self.rows[ri].ip))
.map(|(disp, _)| disp)
.collect();
if !sel.is_empty() {
t.dvlc_select_rows(&sel);
}
self.refresh_kpis();
}
@@ -271,6 +306,9 @@ impl App {
self.rows.retain(|r| targets.contains(&r.ip));
changed |= self.rows.len() != before;
self.target_ips = targets;
// Drop selections that are no longer in range.
let keep = std::mem::take(&mut self.selected_ips);
self.selected_ips = keep.into_iter().filter(|ip| self.target_ips.contains(ip)).collect();
self.scan_total = total;
self.scanning = true;
self.progress.gauge_set_range(total.max(1) as i32);
@@ -279,11 +317,12 @@ impl App {
self.table_parent.layout();
wx_rs::set_status_text(&format!("scanning {total} addresses..."));
}
Ok(ScanMsg::Progress { done, total }) => {
Ok(ScanMsg::Progress { done, total, ip }) => {
self.scan_total = total;
self.progress.gauge_set_value(done.min(total) as i32);
let where_ = if ip.is_empty() { String::new() } else { format!(" - scanning {ip}") };
wx_rs::set_status_text(&format!(
"scanning {done}/{total} - {} found",
"{done}/{total}{where_} ({} found)",
self.rows.len()
));
}
@@ -294,20 +333,35 @@ impl App {
changed = true;
}
}
Ok(ScanMsg::Done(s)) => {
Ok(ScanMsg::Done(_s)) => {
self.scanning = false;
self.progress.gauge_set_value(self.scan_total.max(1) as i32);
self.progress.show(false);
self.table_parent.layout();
wx_rs::set_status_text(&format!("scan complete: {} found in {s}", self.rows.len()));
// Arm the next automatic scan (if the loop is running).
self.countdown = if self.playing { self.auto_secs } else { 0 };
}
Ok(ScanMsg::Failed(e)) => {
self.scanning = false;
self.progress.show(false);
self.table_parent.layout();
wx_rs::set_status_text(&format!("scan failed: {e}"));
self.countdown = if self.playing { self.auto_secs } else { 0 };
}
Err(std::sync::mpsc::TryRecvError::Empty) => break,
Err(std::sync::mpsc::TryRecvError::Disconnected) => {
// The scan thread ended. Normally this follows Done/Failed
// (handled above); if it ended without either (panic/hang
// recovery), don't leave the loop stuck "scanning".
if self.scanning {
self.scanning = false;
self.progress.show(false);
self.table_parent.layout();
self.countdown = if self.playing { self.auto_secs } else { 0 };
}
self.scan_rx = None;
break;
}
Err(_) => break,
}
}
if changed {
@@ -315,14 +369,54 @@ impl App {
}
}
fn toggle_select(&mut self, store_row: usize, _col: usize) {
// The toggle renderer + list store update themselves visually; we
// flip the model and refresh the KPIs (selection is not a KPI, but
// keep state coherent for future bulk actions).
if let Some(&ri) = self.view_idx.get(store_row) {
if let Some(r) = self.rows.get_mut(ri) {
r.selected = !r.selected;
/// Called every second by the scan timer: drain scan messages, then run the
/// scan-loop scheduler (countdown to the next automatic rescan, or idle).
fn tick(&mut self) {
self.drain_scan();
if self.scanning {
return; // status already shows scan progress
}
if self.playing && self.auto_secs > 0 {
if self.countdown > 1 {
self.countdown -= 1;
wx_rs::set_status_text(&format!(
"{} miners - next scan in {}",
self.rows.len(),
fmt_secs(self.countdown)
));
} else {
self.start_new_scan();
}
} else {
wx_rs::set_status_text(&format!(
"{} miners - {}",
self.rows.len(),
if self.playing { "auto-rescan off" } else { "paused" }
));
}
}
/// Start a fresh scan of the saved ranges.
fn start_new_scan(&mut self) {
self.scan_rx = Some(scan::start_scan(scan::load_ranges()));
self.scanning = true;
self.countdown = 0;
wx_rs::set_status_text("scanning...");
}
/// The table's selection changed (ctrl/shift-click). Mirror it into the
/// model, tracked by IP so it survives table refreshes during a scan.
fn on_selection_changed(&mut self) {
let Some(t) = self.table else { return };
let rows_sel = t.dvlc_get_selections();
self.selected_ips.clear();
for disp in rows_sel {
if let Some(&ri) = self.view_idx.get(disp) {
self.selected_ips.insert(self.rows[ri].ip.clone());
}
}
for r in &mut self.rows {
r.selected = self.selected_ips.contains(&r.ip);
}
}
@@ -339,13 +433,12 @@ impl App {
}
fn header_click(&mut self, creation_idx: usize) {
// Columns are appended to the table in display order (toggle col first,
// then each visible column). Map the clicked creation index back to a
// model column through display_columns(), not view.order, so hidden
// columns don't shift the mapping.
// Columns are appended in display order; map the clicked creation index
// back to a model column through display_columns() (hidden columns don't
// shift the mapping). Every column, including IP at index 0, is sortable.
let cols = self.view.display_columns();
if creation_idx == 0 || creation_idx >= cols.len() {
return; // toggle column (idx 0) is not sortable
if creation_idx >= cols.len() {
return;
}
let col = cols[creation_idx];
self.view.sort = match self.view.sort {
@@ -364,9 +457,6 @@ impl App {
fn update_headers(&self) {
let Some(t) = self.table else { return };
for (i, c) in self.view.display_columns().iter().enumerate() {
if i == 0 {
continue; // toggle column has no title
}
let mut title = c.title().to_string();
match self.view.sort {
Some((sc, true)) if sc == *c => title.push_str(" ^"),
@@ -409,18 +499,24 @@ impl App {
let edit = Widget::text_ctrl(dlg, true);
edit.set_value(&scan::load_ranges().join("\n"));
root.add(edit, 1, sf::EXPAND | sf::BORDER_ALL, 6);
// Auto-rescan interval (seconds; 0 = off).
let auto_row = Widget::box_sizer(false);
let auto_lbl = Widget::static_text(dlg, "Auto-rescan every (seconds, 0 = off):");
auto_row.add(auto_lbl, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
let auto_edit = Widget::text_ctrl(dlg, false);
auto_edit.set_value(&self.auto_secs.to_string());
auto_row.add(auto_edit, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
root.add_sizer(auto_row, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
let btns = Widget::box_sizer(false);
let apply = Widget::button(dlg, "Apply", ID_RANGES_APPLY);
btns.add(apply, 0, sf::BORDER_ALL, 6);
let cancel = Widget::button(dlg, "Cancel", ID_RANGES_CANCEL);
btns.add(cancel, 0, sf::BORDER_ALL, 6);
// `root` is a vertical sizer: only border flags are valid here. Using
// ALIGN_CENTRE_VERTICAL trips a wxWidgets consistency assert whose
// handler pumps a nested event loop -> re-entrant dispatch -> crash.
root.add_sizer(btns, 0, sf::BORDER_ALL, 6);
root.set_sizer_on(dlg);
self.ranges_dialog = dlg;
self.ranges_edit = edit;
self.ranges_auto = auto_edit;
dlg
}
@@ -441,82 +537,85 @@ impl App {
wx_rs::set_status_text(&format!("invalid range: {e}"));
return; // keep dialog open
}
// Save the auto-rescan interval too.
if let Ok(secs) = self.ranges_auto.get_value().trim().parse::<u64>() {
self.auto_secs = secs;
let _ = scan::save_auto_secs(secs);
}
let _ = scan::save_ranges(&lines);
self.scan_rx = Some(scan::start_scan(lines.clone()));
self.scanning = true;
self.countdown = 0;
wx_rs::set_status_text("scanning...");
self.ranges_btn.set_label(&format!("Scan ranges: {}", lines.join(", ")));
self.ranges_dialog.close(1);
}
/// The columns available to show/hide: every metric except the fixed
/// Sel + Ip columns, in registry order (matches the check-list order).
/// The columns available to show/hide: every metric except the fixed IP
/// column, in registry order (the rearrange-list's item index space).
fn selectable_columns() -> Vec<Column> {
ALL_COLUMNS
.iter()
.copied()
.filter(|c| *c != Column::Sel && *c != Column::Ip)
.collect()
ALL_COLUMNS.iter().copied().filter(|c| *c != Column::Ip).collect()
}
/// Build (but do not show) the columns chooser. Every scannable metric is
/// listed, so any of them can be shown.
/// 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
/// reorder. IP is always the first column and is not listed here.
fn build_columns_dialog(&mut self) -> Widget {
let frame = Widget::main_frame();
let dlg = Widget::dialog(frame, "Choose columns");
let root = Widget::box_sizer(true);
let hint = Widget::static_text(dlg, "Show any scannable metric (IP is always shown):");
let hint = Widget::static_text(
dlg,
"Check to show a metric; drag or use the arrows to reorder (IP is always first).",
);
root.add(hint, 0, sf::BORDER_ALL, 6);
let list = Widget::check_list_box(dlg);
for c in Self::selectable_columns() {
list.clb_append(c.title());
list.clb_set_checked(list.clb_count() - 1, self.view.visible.contains(&c));
// Base list is registry order; the wx order array lists items in the
// current arranged order, encoding checked = visible (a negative value
// ~idx means item idx unchecked).
let base = Self::selectable_columns();
let titles: Vec<&str> = base.iter().map(|c| c.title()).collect();
let mut order: Vec<i32> = Vec::with_capacity(base.len());
for c in self.view.order.iter().filter(|c| **c != Column::Ip) {
if let Some(idx) = base.iter().position(|b| b == c) {
let idx = idx as i32;
order.push(if self.view.visible.contains(c) { idx } else { !idx });
}
}
let list = Widget::rearrange_list(dlg, &order, &titles);
root.add(list, 1, sf::EXPAND | sf::BORDER_ALL, 6);
// quick actions
let quick = Widget::box_sizer(false);
quick.add(Widget::button(dlg, "All", ID_COLUMNS_ALL), 0, sf::BORDER_ALL, 4);
quick.add(Widget::button(dlg, "None", ID_COLUMNS_NONE), 0, sf::BORDER_ALL, 4);
quick.add(Widget::button(dlg, "Defaults", ID_COLUMNS_RESET), 0, sf::BORDER_ALL, 4);
root.add_sizer(quick, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 4);
let btns = Widget::box_sizer(false);
btns.add(Widget::button(dlg, "OK", ID_COLUMNS_OK), 0, sf::BORDER_ALL, 6);
btns.add(Widget::button(dlg, "Cancel", ID_COLUMNS_CANCEL), 0, sf::BORDER_ALL, 6);
root.add_sizer(btns, 0, sf::BORDER_ALL, 6);
root.set_sizer_on(dlg);
dlg.fit(dlg);
self.columns_dialog = dlg;
self.columns_list = list;
dlg
}
/// Check or uncheck every item in the columns list (visual only).
fn columns_check_all(&self, checked: bool) {
let list = self.columns_list;
for i in 0..list.clb_count() {
list.clb_set_checked(i, checked);
}
}
/// Reset the columns list to the default-visible set (visual only).
fn columns_reset_defaults(&self) {
let list = self.columns_list;
for (i, c) in Self::selectable_columns().iter().enumerate() {
list.clb_set_checked(i, DEFAULT_VISIBLE.contains(c));
}
}
fn apply_columns(&mut self) {
let list = self.columns_list;
for (i, c) in Self::selectable_columns().iter().enumerate() {
if list.clb_checked(i) {
self.view.visible.insert(*c);
} else {
self.view.visible.remove(c);
let base = Self::selectable_columns();
let order = self.columns_list.rearrange_get_order();
let mut new_order: Vec<Column> = vec![Column::Ip];
let mut visible: HashSet<Column> = HashSet::from([Column::Ip]);
for entry in order {
let (idx, checked) = if entry < 0 { ((!entry) as usize, false) } else { (entry as usize, true) };
if let Some(&c) = base.get(idx) {
new_order.push(c);
if checked {
visible.insert(c);
}
}
}
// keep sort column visible-ish: drop sort if hidden
// Only accept a full permutation (no dropped/duplicated columns); apply
// order + visibility together so they never desync.
if new_order.len() == self.view.order.len() {
self.view.order = new_order;
self.view.visible = visible;
}
// Drop the sort if its column was hidden (IP is always shown).
if let Some((c, _)) = self.view.sort {
if !self.view.visible.contains(&c) {
if c != Column::Ip && !self.view.visible.contains(&c) {
self.view.sort = None;
}
}
@@ -536,8 +635,8 @@ impl App {
let mut lists = Vec::new();
for c in self.view.display_columns() {
// Value checklists only make sense for categorical columns; skip the
// checkbox column and continuous numeric metrics.
if c == Column::Sel || c.is_numeric() {
// continuous numeric metrics.
if c.is_numeric() {
continue;
}
let mut values: Vec<String> = self.rows.iter().map(|r| c.cell(r)).collect();
@@ -640,18 +739,32 @@ impl App {
ID_COLUMNS => return Some(self.build_columns_dialog()),
ID_COLUMNS_OK => self.apply_columns(),
ID_COLUMNS_CANCEL => self.columns_dialog.close(0),
ID_COLUMNS_ALL => self.columns_check_all(true),
ID_COLUMNS_NONE => self.columns_check_all(false),
ID_COLUMNS_RESET => self.columns_reset_defaults(),
ID_FILTER => return Some(self.build_filter_dialog()),
ID_FILTER_OK => self.apply_filter(),
ID_FILTER_CANCEL => self.filter_dialog.close(0),
ID_FILTER_RESET => self.reset_filters(),
ID_RESCAN => {
let ranges = scan::load_ranges();
self.scan_rx = Some(scan::start_scan(ranges));
self.scanning = true;
wx_rs::set_status_text("scanning...");
ID_PLAY => {
// Resume/start the scan loop: scan now (unless one is
// already running) + auto-rescan on.
self.playing = true;
if !self.scanning {
self.start_new_scan();
}
}
ID_PAUSE => {
// Stop the auto-rescan loop (a scan in flight finishes).
self.playing = false;
wx_rs::set_status_text(&format!("{} miners - paused", self.rows.len()));
}
ID_STOP => {
// Halt the loop and drop any in-flight scan.
self.playing = false;
self.countdown = 0;
self.scanning = false;
self.scan_rx = None;
self.progress.show(false);
self.table_parent.layout();
wx_rs::set_status_text(&format!("{} miners - stopped", self.rows.len()));
}
_ if (ID_FILTER_ALL_BASE..ID_FILTER_NONE_BASE).contains(&id) => {
self.filter_check_all((id - ID_FILTER_ALL_BASE) as usize, true);
@@ -663,10 +776,10 @@ impl App {
}
}
WxEventKind::DvlcHeaderClick => self.header_click(ev.p1 as usize),
WxEventKind::DvlcValueChanged => self.toggle_select(ev.p1 as usize, ev.p2 as usize),
WxEventKind::DvlcSelectionChanged => self.on_selection_changed(),
WxEventKind::DvlcActivated => self.activate_row(ev.p1 as usize),
WxEventKind::DvlcReordered => self.column_reordered(),
WxEventKind::TimerTick if ev.p1 as i32 == TIMER_SCAN => self.drain_scan(),
WxEventKind::TimerTick if ev.p1 as i32 == TIMER_SCAN => self.tick(),
_ => {}
}
None
@@ -720,7 +833,7 @@ impl App {
let mut mismatches = 0;
for (disp_row, &ri) in self.view_idx.iter().enumerate() {
let r = &self.rows[ri];
for (j, c) in cols.iter().enumerate().skip(1) {
for (j, c) in cols.iter().enumerate() {
let want = c.cell(r);
let got = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
if got != want {
@@ -760,8 +873,13 @@ impl App {
} else {
check("S17 (.112) present", false, "row not found".into());
}
check("IP is the first text column", ip_col == Some(1),
check("IP is the first column", ip_col == Some(0),
format!("ip col index = {ip_col:?}"));
// default view is IP-ascending
let ips: Vec<String> = self.view_idx.iter().map(|&ri| self.rows[ri].ip.clone()).collect();
let mut sorted = ips.clone();
sorted.sort();
check("default sort is IP ascending", ips == sorted, String::new());
ok
}