From 5c041a037fd5336b8d1c2b035308ea83dd1c058f Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 17 Sep 2026 17:13:27 -0600 Subject: [PATCH] GUI round 8b.2: column-header menu + rubber-band drag-select Bridge + UI (local wx-rs bridge compile + full cargo check clean). - Column-header right-click menu (#5): right-clicking a column header opens an Excel-style menu -- Sort ascending / descending, Auto-size this column, Hide (not offered for the fixed IP column), and Columns... (the full show/hide picker). New wx event WxEV_DVLC_HEADER_RIGHT_CLICK bound from the native wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, plus a wxbr_dvlc_autosize_col bridge fn (wxCOL_WIDTH_AUTOSIZE). (Sticky/frozen columns are the separate 8c dual-control piece.) - Rubber-band (click-drag) range selection (#10): wxDataViewCtrl has no native drag-to-extend selection (only ctrl/shift-click), so it is tracked in the bridge -- LEFT_DOWN records the anchor row (and lets the native handler select it), dragging with the button down selects the inclusive row range under the cursor, LEFT_UP clears the anchor; modifier-clicks are left to the native multi-select. Reuses the existing Select/UnselectAll primitives and emits SELECTION_CHANGED so the model's selected-IP set stays in sync. - KPI cards widened to 150px so "685 TH/s" / "21.3 kW" are no longer clipped. wx-rs patches 0002/0003 regenerated + round-trip validated. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh --- crates/alkane-gui/src/ui.rs | 71 ++++++++++++++++++- .../wx-rs/patches/0002-widget-bridge-rs.patch | 10 ++- .../patches/0003-widget-bridge-cpp.patch | 63 +++++++++++++++- .../cpp_src/widgets_bridge.cpp | 61 ++++++++++++++++ .../wx-rs/wx-rs-0.2.0-patched/src/widgets.rs | 8 +++ 5 files changed, 209 insertions(+), 4 deletions(-) diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 7bb05d56..d8a3e8a3 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -58,6 +58,12 @@ const ID_FLASH_CANCEL: i32 = 745; const ID_CREDS_SAVE: i32 = 746; const ID_CREDS_CLEAR: i32 = 747; 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 // idle/countdown status takes over again. const ACTION_RESULT_TICKS: u8 = 8; @@ -324,6 +330,9 @@ pub struct App { // 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. 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, // The "Set scan credentials..." dialog. creds_dialog: Widget, creds_user_input: Widget, @@ -369,8 +378,9 @@ pub fn build(frame: Widget) -> App { let vc = kind_color(&pal, kind); let card = Widget::panel(panel); 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. - card.set_min_size(128, 62); + // Uniform size so every KPI box is identical regardless of its content + // (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 value = Widget::static_text(card, "0"); value.set_font_size(19); @@ -508,6 +518,7 @@ pub fn build(frame: Widget) -> App { flash_confirm_input: frame, pending_flash: None, flashing: false, + header_menu_col: None, creds_dialog: frame, creds_user_input: frame, creds_pass_input: frame, @@ -877,6 +888,9 @@ impl App { /// actions (power limit / tuning %) return a prompt dialog to show modally. fn on_menu_item(&mut self, id: i32) -> Option { 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 => { for ip in self.selected_ip_list() { wx_rs::launch_browser(&format!("http://{ip}")); @@ -1471,6 +1485,58 @@ impl App { 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 { + 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 /// place, without recreating the table. fn update_headers(&self) { @@ -2020,6 +2086,7 @@ impl App { } } 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::DvlcActivated => self.activate_row(ev.p1 as usize), WxEventKind::DvlcReordered => self.column_reordered(), diff --git a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch index 082e8d42..95c0e655 100644 --- a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch +++ b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch @@ -10,7 +10,7 @@ +pub use widgets::*; --- a/src/widgets.rs +++ b/src/widgets.rs -@@ -0,0 +1,712 @@ +@@ -0,0 +1,720 @@ +// 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). @@ -73,6 +73,7 @@ + pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *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_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_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; @@ -149,6 +150,7 @@ + ChoiceChanged, + SysColour, + Deferred, ++ DvlcHeaderRightClick, +} + +impl WxEventKind { @@ -167,6 +169,7 @@ + 12 => WxEventKind::ChoiceChanged, + 13 => WxEventKind::SysColour, + 14 => WxEventKind::Deferred, ++ 15 => WxEventKind::DvlcHeaderRightClick, + _ => return None, + }) + } @@ -508,6 +511,11 @@ + 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). + pub fn dvlc_col_at_pos(&self, pos: usize) -> Option { + let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) }; diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index bf23b5f5..42e1685c 100644 --- a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch +++ b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch @@ -1,6 +1,6 @@ --- a/cpp_src/widgets_bridge.cpp +++ b/cpp_src/widgets_bridge.cpp -@@ -0,0 +1,928 @@ +@@ -0,0 +1,989 @@ +// 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). @@ -34,11 +34,15 @@ +#include +#include +#include ++#include +#include + +typedef void (*WxWidgetEventFn)(int kind, long p1, long p2); +static WxWidgetEventFn g_widget_event = nullptr; + ++// Anchor row per data-view control for rubber-band (click-drag) range select. ++static std::map g_drag_anchor; ++ +// Event kinds (must match Rust WxEventKind in src/widgets.rs) +enum WxWidgetEventKind { + WxEV_BUTTON_CLICKED = 1, @@ -54,6 +58,7 @@ + WxEV_CHOICE_CHANGED = 12, + WxEV_SYS_COLOUR = 13, + WxEV_DEFERRED = 14, ++ WxEV_DVLC_HEADER_RIGHT_CLICK = 15, +}; + +// A list store that carries an optional per-row foreground colour plus an @@ -478,9 +483,57 @@ + dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) { + 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&) { + if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0); + }); ++ // Rubber-band (click-drag) range selection: wxDataViewCtrl has none natively ++ // (only ctrl/shift-click), so track it here. LEFT_DOWN records the anchor row ++ // (and lets the native handler select it); dragging with the button down ++ // extends the selection to the row under the cursor. ++ 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(); ++ }); + // Row activation (double-click / Enter): report the row + column so the app + // can, e.g., open the miner's IP in a browser. + dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) { @@ -615,6 +668,14 @@ + 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 +// 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) { diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp index ab0be971..26a341e1 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp @@ -31,11 +31,15 @@ #include #include #include +#include #include typedef void (*WxWidgetEventFn)(int kind, long p1, long p2); static WxWidgetEventFn g_widget_event = nullptr; +// Anchor row per data-view control for rubber-band (click-drag) range select. +static std::map g_drag_anchor; + // Event kinds (must match Rust WxEventKind in src/widgets.rs) enum WxWidgetEventKind { WxEV_BUTTON_CLICKED = 1, @@ -51,6 +55,7 @@ enum WxWidgetEventKind { WxEV_CHOICE_CHANGED = 12, WxEV_SYS_COLOUR = 13, WxEV_DEFERRED = 14, + WxEV_DVLC_HEADER_RIGHT_CLICK = 15, }; // A list store that carries an optional per-row foreground colour plus an @@ -475,9 +480,57 @@ void* wxbr_dvlc(void* parent) { dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) { 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&) { if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0); }); + // Rubber-band (click-drag) range selection: wxDataViewCtrl has none natively + // (only ctrl/shift-click), so track it here. LEFT_DOWN records the anchor row + // (and lets the native handler select it); dragging with the button down + // extends the selection to the row under the cursor. + 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(); + }); // Row activation (double-click / Enter): report the row + column so the app // can, e.g., open the miner's IP in a browser. dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) { @@ -612,6 +665,14 @@ int wxbr_dvlc_col_count(void* win) { 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 // 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) { diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs index 2cd284ae..81cb9953 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs @@ -60,6 +60,7 @@ mod notsafe { pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *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_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_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; @@ -136,6 +137,7 @@ pub enum WxEventKind { ChoiceChanged, SysColour, Deferred, + DvlcHeaderRightClick, } impl WxEventKind { @@ -154,6 +156,7 @@ impl WxEventKind { 12 => WxEventKind::ChoiceChanged, 13 => WxEventKind::SysColour, 14 => WxEventKind::Deferred, + 15 => WxEventKind::DvlcHeaderRightClick, _ => return None, }) } @@ -495,6 +498,11 @@ impl Widget { 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). pub fn dvlc_col_at_pos(&self, pos: usize) -> Option { let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };