Fix GUI layout/crash bugs; add operator features, tests, and dev loop

Round 1 (bug fixes + test harness):
- Fix table rendering in the top-left corner: the dvlc was never added to the
  sizer; add it (proportion 1) and re-run layout; drop the space-eating stretch.
- Fix abort on dialog buttons: the dialog root sizers passed ALIGN_CENTRE_VERTICAL
  to a vertical sizer, tripping a wx consistency assert whose handler pumps a
  nested event loop, re-entering dispatch while it held the App RefCell borrow.
  Remove the invalid flags; split dispatch into two phases with try_borrow_mut.
- Fix header-click sort mapping when columns are hidden (use display_columns);
  drag-reorder splices back into the full order without dropping hidden columns.
- Add offline fixtures + ALKANE_FAKE_SCAN and ALKANE_SELFTEST modes; scripts
  ui-selftest.sh and ui-screenshot.sh; AGENTS.md documents the dev loop.

Round 2 (operator requests):
- Redesigned color-coded KPI cards; light/dark mode follows the system theme.
- SI-formatted hashrate/power on the KPIs and columns (685 TH/s, 21.3 kW).
- Scan ranges accept CIDR, single IP, and A.B.C.D-E.F.G.H / A.B.C.D-N ranges;
  oversized ranges (> 1,000,000 addresses) are rejected.
- Scan progress bar over the table + status-bar text; out-of-range miners are
  dropped when a scan starts.
- Columns panel exposes every scannable MinerData metric (All / None / Defaults).
- Excel-style filter panel: per-category value checklists, per-column All/None,
  Apply / Reset / Cancel, blank handling.
- Sort direction marker in the header (updated in place); double-click a row
  opens the miner in the default browser.

wx-rs: extend the widget bridge (gauge, in-place column title, sort indicator,
browser launch, system appearance/colours, widget colours, item-activated);
patches 0002/0003 regenerated and round-trip validated.

Verified: 22 unit tests + a 13-check headless UI self-test, plus a live scan
against the bench fleet.

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 16:24:05 -06:00
co-authored by Claude Opus 4.8
parent 53ee49e90a
commit d1ab6aa72a
13 changed files with 2136 additions and 251 deletions
+109 -3
View File
@@ -1,6 +1,5 @@
--- a/src/lib.rs
+++ b/src/lib.rs
+++ wx-rs-0.2.0-patched/src/lib.rs 2026-09-15 12:27:16.559261300 -0600
@@ -3,3 +3,7 @@
mod menu;
@@ -11,8 +10,7 @@
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
+++ wx-rs-0.2.0-patched/src/widgets.rs 2026-09-15 13:05:24.616388500 -0600
@@ -0,0 +1,365 @@
@@ -0,0 +1,473 @@
+// 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).
@@ -35,10 +33,13 @@
+ pub fn wxbr_sizer_add_spacer(sizer: *mut c_void, px: c_int);
+ pub fn wxbr_sizer_add_stretch(sizer: *mut c_void, proportion: c_int);
+ pub fn wxbr_set_sizer(win: *mut c_void, sizer: *mut c_void);
+ pub fn wxbr_layout(win: *mut c_void);
+ pub fn wxbr_sizer_detach(sizer: *mut c_void, win: *mut c_void);
+ pub fn wxbr_fit(win: *mut c_void);
+ pub fn wxbr_set_min_size(win: *mut c_void, w: c_int, h: c_int);
+ pub fn wxbr_static_text(parent: *mut c_void, label: *const c_char) -> *mut c_void;
+ pub fn wxbr_set_label(win: *mut c_void, label: *const c_char);
+ pub fn wxbr_get_label(win: *mut c_void, buf: *mut c_char, cap: c_int) -> c_int;
+ pub fn wxbr_set_bold(win: *mut c_void);
+ pub fn wxbr_set_font_size(win: *mut c_void, pts: c_int);
+ pub fn wxbr_button(parent: *mut c_void, label: *const c_char, id: c_int) -> *mut c_void;
@@ -68,10 +69,22 @@
+ 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_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_selected_row(win: *mut c_void) -> c_long;
+ pub fn wxbr_dvlc_select_row(win: *mut c_void, row: c_long);
+ pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
+ pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
+ pub fn wxbr_gauge_set_range(win: *mut c_void, range: c_int);
+ pub fn wxbr_gauge_set_value(win: *mut c_void, value: c_int);
+ pub fn wxbr_gauge_pulse(win: *mut c_void);
+ pub fn wxbr_show(win: *mut c_void, shown: c_int);
+ pub fn wxbr_launch_browser(url: *const c_char) -> c_int;
+ pub fn wxbr_set_appearance_system();
+ pub fn wxbr_is_dark() -> c_int;
+ pub fn wxbr_system_color(which: c_int, r: *mut u8, g: *mut u8, b: *mut u8);
+ pub fn wxbr_set_bg(win: *mut c_void, r: c_int, g: c_int, b: c_int);
+ pub fn wxbr_set_fg(win: *mut c_void, r: c_int, g: c_int, b: c_int);
+ pub fn wxbr_destroy(win: *mut c_void);
+ }
+}
@@ -101,6 +114,7 @@
+ DvlcHeaderClick,
+ DvlcReordered,
+ TimerTick,
+ DvlcActivated,
+}
+
+impl WxEventKind {
@@ -112,11 +126,36 @@
+ 5 => WxEventKind::DvlcHeaderClick,
+ 6 => WxEventKind::DvlcReordered,
+ 7 => WxEventKind::TimerTick,
+ 8 => WxEventKind::DvlcActivated,
+ _ => return None,
+ })
+ }
+}
+
+/// Open a URL in the system default browser. Returns true on success.
+pub fn launch_browser(url: &str) -> bool {
+ let c = CString::new(url).unwrap_or_default();
+ unsafe { notsafe::wxbr_launch_browser(c.as_ptr()) != 0 }
+}
+
+/// Ask wx to follow the system light/dark appearance (no-op before 3.3).
+pub fn set_appearance_system() {
+ unsafe { notsafe::wxbr_set_appearance_system() }
+}
+
+/// True if the current system appearance is dark.
+pub fn is_dark() -> bool {
+ unsafe { notsafe::wxbr_is_dark() != 0 }
+}
+
+/// A theme colour. `which`: 0=window bg, 1=window text, 2=highlight,
+/// 3=button face, 4=grey text. Returns (r, g, b).
+pub fn system_color(which: i32) -> (u8, u8, u8) {
+ let (mut r, mut g, mut b) = (0u8, 0u8, 0u8);
+ unsafe { notsafe::wxbr_system_color(which, &mut r, &mut g, &mut b) }
+ (r, g, b)
+}
+
+/// A widget event: kind plus two payload words.
+/// ButtonClicked: p1 = button id.
+/// ClbToggled: p1 = control handle, p2 = item index.
@@ -189,6 +228,18 @@
+ unsafe { notsafe::wxbr_set_sizer(win.0, self.0) }
+ }
+
+ /// Re-run this window's sizer (self = a window). Call after adding a child
+ /// window to an already-installed sizer, or after rebuilding the table.
+ pub fn layout(&self) {
+ unsafe { notsafe::wxbr_layout(self.0) }
+ }
+
+ /// Detach a child window from this sizer (self = a sizer) without
+ /// destroying it. Use before destroying a sizer-managed window.
+ pub fn detach(&self, win: Widget) {
+ unsafe { notsafe::wxbr_sizer_detach(self.0, win.0) }
+ }
+
+ pub fn fit(&self, win: Widget) {
+ unsafe { notsafe::wxbr_fit(win.0) }
+ }
@@ -207,6 +258,18 @@
+ unsafe { notsafe::wxbr_set_label(self.0, c.as_ptr()) }
+ }
+
+ /// Read back a control's current label text (self-test uses this to verify
+ /// what a KPI actually displays).
+ pub fn get_label(&self) -> String {
+ let mut buf = vec![0i8; 4096];
+ let n = unsafe { notsafe::wxbr_get_label(self.0, buf.as_mut_ptr(), buf.len() as c_int) };
+ if n <= 0 {
+ return String::new();
+ }
+ let bytes: Vec<u8> = buf[..(n - 1) as usize].iter().map(|&b| b as u8).collect();
+ String::from_utf8_lossy(&bytes).into_owned()
+ }
+
+ pub fn set_bold(&self) {
+ unsafe { notsafe::wxbr_set_bold(self.0) }
+ }
@@ -368,10 +431,53 @@
+ unsafe { notsafe::wxbr_dvlc_select_row(self.0, row as c_long) }
+ }
+
+ /// Show or clear the native sort arrow on a column (creation index).
+ pub fn dvlc_set_sort_indicator(&self, col: usize, active: bool, ascending: bool) {
+ unsafe {
+ notsafe::wxbr_dvlc_set_sort_indicator(
+ self.0,
+ col as c_int,
+ active as c_int,
+ ascending as c_int,
+ )
+ }
+ }
+
+ pub fn timer(id: i32, ms: i32) -> Widget {
+ Widget(unsafe { notsafe::wxbr_timer(id, ms) })
+ }
+
+ // ---- gauge (progress bar) ----
+
+ pub fn gauge(parent: Widget, range: i32) -> Widget {
+ Widget(unsafe { notsafe::wxbr_gauge(parent.0, range) })
+ }
+
+ pub fn gauge_set_range(&self, range: i32) {
+ unsafe { notsafe::wxbr_gauge_set_range(self.0, range) }
+ }
+
+ pub fn gauge_set_value(&self, value: i32) {
+ unsafe { notsafe::wxbr_gauge_set_value(self.0, value) }
+ }
+
+ pub fn gauge_pulse(&self) {
+ unsafe { notsafe::wxbr_gauge_pulse(self.0) }
+ }
+
+ /// Show or hide this window.
+ pub fn show(&self, shown: bool) {
+ unsafe { notsafe::wxbr_show(self.0, shown as c_int) }
+ }
+
+ pub fn set_bg(&self, r: u8, g: u8, b: u8) {
+ unsafe { notsafe::wxbr_set_bg(self.0, r as c_int, g as c_int, b as c_int) }
+ }
+
+ pub fn set_fg(&self, r: u8, g: u8, b: u8) {
+ unsafe { notsafe::wxbr_set_fg(self.0, r as c_int, g as c_int, b as c_int) }
+ }
+
+ /// Deferred destruction (safe from event handlers); used to rebuild
+ /// the table when its column set changes.
+ pub fn destroy(&self) {
+132 -3
View File
@@ -1,7 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
+++ wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp 2026-09-15 13:14:21.288485800 -0600
@@ -0,0 +1,352 @@
@@ -0,0 +1,482 @@
+// 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).
@@ -18,6 +17,10 @@
+#include <wx/dialog.h>
+#include <wx/timer.h>
+#include <wx/vector.h>
+#include <wx/gauge.h>
+#include <wx/settings.h>
+#include <wx/utils.h>
+#include <wx/app.h>
+
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
+static WxWidgetEventFn g_widget_event = nullptr;
@@ -30,6 +33,7 @@
+ WxEV_DVLC_HEADER_CLICK = 5,
+ WxEV_DVLC_REORDERED = 6,
+ WxEV_TIMER_TICK = 7,
+ WxEV_DVLC_ACTIVATED = 8,
+};
+
+extern "C" {
@@ -87,6 +91,17 @@
+ ((wxWindow*)win)->SetSizer((wxSizer*)sizer);
+}
+
+// Re-run this window's sizer to (re)position its children. Needed after a
+// child window is added to an already-installed sizer (e.g. the table, which
+// is created after the frame's sizer is set and rebuilt on column changes).
+void wxbr_layout(void* win) { ((wxWindow*)win)->Layout(); }
+
+// Remove a child window from a sizer without destroying the window. Call this
+// before destroying a sizer-managed window so the sizer keeps no dangling item.
+void wxbr_sizer_detach(void* sizer, void* win) {
+ ((wxSizer*)sizer)->Detach((wxWindow*)win);
+}
+
+void wxbr_fit(void* win) { ((wxWindow*)win)->Fit(); }
+
+void wxbr_set_min_size(void* win, int w, int h) {
@@ -106,6 +121,20 @@
+ else ((wxWindow*)win)->SetLabel(wxString::FromUTF8(label));
+}
+
+// Read a control's current label text (used by the headless self-test to read
+// back what a KPI static text actually displays).
+int wxbr_get_label(void* win, char* buf, int cap) {
+ wxWindow* w = (wxWindow*)win;
+ wxStaticText* st = dynamic_cast<wxStaticText*>(w);
+ wxString s = st ? st->GetLabel() : w->GetLabel();
+ wxCharBuffer b = s.ToUTF8();
+ int n = (int)strlen(b.data());
+ if (n >= cap) n = cap - 1;
+ memcpy(buf, b.data(), n);
+ buf[n] = 0;
+ return n + 1;
+}
+
+void wxbr_set_bold(void* win) {
+ wxWindow* w = (wxWindow*)win;
+ wxFont f = w->GetFont();
@@ -252,6 +281,19 @@
+ lc->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
+ });
+ // Row activation (double-click / Enter): report the row + column so the app
+ // can, e.g., open the miner's IP in a browser.
+ lc->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
+ if (g_widget_event) {
+ wxDataViewListCtrl* lc =
+ dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
+ if (!lc) return;
+ wxDataViewItem item = e.GetItem();
+ if (!item.IsOk()) return;
+ int row = lc->GetStore()->GetRow(item);
+ g_widget_event(WxEV_DVLC_ACTIVATED, row, (long)e.GetColumn());
+ }
+ });
+ return (void*)lc;
+}
+
@@ -273,7 +315,9 @@
+ wxVector<wxVariant> values;
+ for (int i = 0; i < nvals; i++) {
+ if (i == 0)
+ values.push_back(wxVariant(false)); // toggle column (checkbox)
+ // toggle column (checkbox): vals[0] carries the checked state as "1"/"0"
+ // so a refresh preserves the row selection instead of clearing it.
+ values.push_back(wxVariant(vals[0] && vals[0][0] == '1'));
+ else if (vals[i])
+ values.push_back(wxVariant(wxString::FromUTF8(vals[i])));
+ else
@@ -317,6 +361,21 @@
+ return (int)((wxDataViewListCtrl*)win)->GetColumnCount();
+}
+
+// Show/clear the native sort arrow on a column (creation index). The app does
+// its own sorting; this only draws the indicator so the header shows which
+// column is the sort key and in which direction.
+void wxbr_dvlc_set_sort_indicator(void* win, int col, int active, int ascending) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ if (col < 0 || (unsigned)col >= dv->GetColumnCount()) return;
+ wxDataViewColumn* c = dv->GetColumn(col);
+ if (!c) return;
+ if (active) {
+ c->SetSortOrder(ascending != 0);
+ } else if (c->IsSortKey()) {
+ c->UnsetAsSortKey();
+ }
+}
+
+// model column index (creation order) currently shown at display position pos
+int wxbr_dvlc_col_at_pos(void* win, int pos) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
@@ -349,6 +408,76 @@
+ return (void*)t;
+}
+
+// ---- gauge (progress bar) ---------------------------------------------------
+
+void* wxbr_gauge(void* parent, int range) {
+ wxGauge* g = new wxGauge((wxWindow*)parent, wxID_ANY, range < 1 ? 1 : range,
+ wxDefaultPosition, wxSize(-1, 6),
+ wxGA_HORIZONTAL | wxGA_SMOOTH);
+ return (void*)g;
+}
+
+void wxbr_gauge_set_range(void* win, int range) {
+ ((wxGauge*)win)->SetRange(range < 1 ? 1 : range);
+}
+
+void wxbr_gauge_set_value(void* win, int value) {
+ ((wxGauge*)win)->SetValue(value);
+}
+
+void wxbr_gauge_pulse(void* win) { ((wxGauge*)win)->Pulse(); }
+
+// ---- show / hide any window -------------------------------------------------
+
+void wxbr_show(void* win, int shown) { ((wxWindow*)win)->Show(shown != 0); }
+
+// ---- open a URL in the default browser --------------------------------------
+
+int wxbr_launch_browser(const char* url) {
+ return wxLaunchDefaultBrowser(wxString::FromUTF8(url)) ? 1 : 0;
+}
+
+// ---- appearance / dark mode -------------------------------------------------
+
+void wxbr_set_appearance_system() {
+#if wxCHECK_VERSION(3, 3, 0)
+ if (wxTheApp) wxTheApp->SetAppearance(wxApp::Appearance::System);
+#endif
+}
+
+int wxbr_is_dark() {
+ return wxSystemSettings::GetAppearance().IsDark() ? 1 : 0;
+}
+
+// Fetch a theme colour so custom widgets follow light/dark. which:
+// 0=window bg, 1=window text, 2=highlight, 3=button face, 4=grey text.
+void wxbr_system_color(int which, unsigned char* r, unsigned char* g,
+ unsigned char* b) {
+ wxSystemColour idx = wxSYS_COLOUR_WINDOW;
+ switch (which) {
+ case 0: idx = wxSYS_COLOUR_WINDOW; break;
+ case 1: idx = wxSYS_COLOUR_WINDOWTEXT; break;
+ case 2: idx = wxSYS_COLOUR_HIGHLIGHT; break;
+ case 3: idx = wxSYS_COLOUR_BTNFACE; break;
+ case 4: idx = wxSYS_COLOUR_GRAYTEXT; break;
+ default: idx = wxSYS_COLOUR_WINDOW; break;
+ }
+ wxColour c = wxSystemSettings::GetColour(idx);
+ *r = c.Red();
+ *g = c.Green();
+ *b = c.Blue();
+}
+
+// ---- widget colours (for the KPI cards) -------------------------------------
+
+void wxbr_set_bg(void* win, int r, int g, int b) {
+ ((wxWindow*)win)->SetBackgroundColour(wxColour(r, g, b));
+}
+
+void wxbr_set_fg(void* win, int r, int g, int b) {
+ ((wxWindow*)win)->SetForegroundColour(wxColour(r, g, b));
+}
+
+// ---- deferred destroy (safe from event handlers) ----------------------------
+
+void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
@@ -14,6 +14,10 @@
#include <wx/dialog.h>
#include <wx/timer.h>
#include <wx/vector.h>
#include <wx/gauge.h>
#include <wx/settings.h>
#include <wx/utils.h>
#include <wx/app.h>
typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
static WxWidgetEventFn g_widget_event = nullptr;
@@ -26,6 +30,7 @@ enum WxWidgetEventKind {
WxEV_DVLC_HEADER_CLICK = 5,
WxEV_DVLC_REORDERED = 6,
WxEV_TIMER_TICK = 7,
WxEV_DVLC_ACTIVATED = 8,
};
extern "C" {
@@ -83,6 +88,17 @@ void wxbr_set_sizer(void* win, void* sizer) {
((wxWindow*)win)->SetSizer((wxSizer*)sizer);
}
// Re-run this window's sizer to (re)position its children. Needed after a
// child window is added to an already-installed sizer (e.g. the table, which
// is created after the frame's sizer is set and rebuilt on column changes).
void wxbr_layout(void* win) { ((wxWindow*)win)->Layout(); }
// Remove a child window from a sizer without destroying the window. Call this
// before destroying a sizer-managed window so the sizer keeps no dangling item.
void wxbr_sizer_detach(void* sizer, void* win) {
((wxSizer*)sizer)->Detach((wxWindow*)win);
}
void wxbr_fit(void* win) { ((wxWindow*)win)->Fit(); }
void wxbr_set_min_size(void* win, int w, int h) {
@@ -102,6 +118,20 @@ void wxbr_set_label(void* win, const char* label) {
else ((wxWindow*)win)->SetLabel(wxString::FromUTF8(label));
}
// Read a control's current label text (used by the headless self-test to read
// back what a KPI static text actually displays).
int wxbr_get_label(void* win, char* buf, int cap) {
wxWindow* w = (wxWindow*)win;
wxStaticText* st = dynamic_cast<wxStaticText*>(w);
wxString s = st ? st->GetLabel() : w->GetLabel();
wxCharBuffer b = s.ToUTF8();
int n = (int)strlen(b.data());
if (n >= cap) n = cap - 1;
memcpy(buf, b.data(), n);
buf[n] = 0;
return n + 1;
}
void wxbr_set_bold(void* win) {
wxWindow* w = (wxWindow*)win;
wxFont f = w->GetFont();
@@ -248,6 +278,19 @@ void* wxbr_dvlc(void* parent) {
lc->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
});
// Row activation (double-click / Enter): report the row + column so the app
// can, e.g., open the miner's IP in a browser.
lc->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
if (g_widget_event) {
wxDataViewListCtrl* lc =
dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
if (!lc) return;
wxDataViewItem item = e.GetItem();
if (!item.IsOk()) return;
int row = lc->GetStore()->GetRow(item);
g_widget_event(WxEV_DVLC_ACTIVATED, row, (long)e.GetColumn());
}
});
return (void*)lc;
}
@@ -269,7 +312,9 @@ void wxbr_dvlc_append_row(void* win, int nvals, const char** vals) {
wxVector<wxVariant> values;
for (int i = 0; i < nvals; i++) {
if (i == 0)
values.push_back(wxVariant(false)); // toggle column (checkbox)
// toggle column (checkbox): vals[0] carries the checked state as "1"/"0"
// so a refresh preserves the row selection instead of clearing it.
values.push_back(wxVariant(vals[0] && vals[0][0] == '1'));
else if (vals[i])
values.push_back(wxVariant(wxString::FromUTF8(vals[i])));
else
@@ -313,6 +358,30 @@ int wxbr_dvlc_col_count(void* win) {
return (int)((wxDataViewListCtrl*)win)->GetColumnCount();
}
// 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) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
if (col < 0 || (unsigned)col >= dv->GetColumnCount()) return;
wxDataViewColumn* c = dv->GetColumn(col);
if (c) c->SetTitle(wxString::FromUTF8(title));
}
// Show/clear the native sort arrow on a column (creation index). The app does
// its own sorting; this only draws the indicator so the header shows which
// column is the sort key and in which direction.
void wxbr_dvlc_set_sort_indicator(void* win, int col, int active, int ascending) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
if (col < 0 || (unsigned)col >= dv->GetColumnCount()) return;
wxDataViewColumn* c = dv->GetColumn(col);
if (!c) return;
if (active) {
c->SetSortOrder(ascending != 0);
} else if (c->IsSortKey()) {
c->UnsetAsSortKey();
}
}
// model column index (creation order) currently shown at display position pos
int wxbr_dvlc_col_at_pos(void* win, int pos) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
@@ -345,6 +414,76 @@ void* wxbr_timer(int id, int ms) {
return (void*)t;
}
// ---- gauge (progress bar) ---------------------------------------------------
void* wxbr_gauge(void* parent, int range) {
wxGauge* g = new wxGauge((wxWindow*)parent, wxID_ANY, range < 1 ? 1 : range,
wxDefaultPosition, wxSize(-1, 6),
wxGA_HORIZONTAL | wxGA_SMOOTH);
return (void*)g;
}
void wxbr_gauge_set_range(void* win, int range) {
((wxGauge*)win)->SetRange(range < 1 ? 1 : range);
}
void wxbr_gauge_set_value(void* win, int value) {
((wxGauge*)win)->SetValue(value);
}
void wxbr_gauge_pulse(void* win) { ((wxGauge*)win)->Pulse(); }
// ---- show / hide any window -------------------------------------------------
void wxbr_show(void* win, int shown) { ((wxWindow*)win)->Show(shown != 0); }
// ---- open a URL in the default browser --------------------------------------
int wxbr_launch_browser(const char* url) {
return wxLaunchDefaultBrowser(wxString::FromUTF8(url)) ? 1 : 0;
}
// ---- appearance / dark mode -------------------------------------------------
void wxbr_set_appearance_system() {
#if wxCHECK_VERSION(3, 3, 0)
if (wxTheApp) wxTheApp->SetAppearance(wxApp::Appearance::System);
#endif
}
int wxbr_is_dark() {
return wxSystemSettings::GetAppearance().IsDark() ? 1 : 0;
}
// Fetch a theme colour so custom widgets follow light/dark. which:
// 0=window bg, 1=window text, 2=highlight, 3=button face, 4=grey text.
void wxbr_system_color(int which, unsigned char* r, unsigned char* g,
unsigned char* b) {
wxSystemColour idx = wxSYS_COLOUR_WINDOW;
switch (which) {
case 0: idx = wxSYS_COLOUR_WINDOW; break;
case 1: idx = wxSYS_COLOUR_WINDOWTEXT; break;
case 2: idx = wxSYS_COLOUR_HIGHLIGHT; break;
case 3: idx = wxSYS_COLOUR_BTNFACE; break;
case 4: idx = wxSYS_COLOUR_GRAYTEXT; break;
default: idx = wxSYS_COLOUR_WINDOW; break;
}
wxColour c = wxSystemSettings::GetColour(idx);
*r = c.Red();
*g = c.Green();
*b = c.Blue();
}
// ---- widget colours (for the KPI cards) -------------------------------------
void wxbr_set_bg(void* win, int r, int g, int b) {
((wxWindow*)win)->SetBackgroundColour(wxColour(r, g, b));
}
void wxbr_set_fg(void* win, int r, int g, int b) {
((wxWindow*)win)->SetForegroundColour(wxColour(r, g, b));
}
// ---- deferred destroy (safe from event handlers) ----------------------------
void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
+115
View File
@@ -20,10 +20,13 @@ mod notsafe {
pub fn wxbr_sizer_add_spacer(sizer: *mut c_void, px: c_int);
pub fn wxbr_sizer_add_stretch(sizer: *mut c_void, proportion: c_int);
pub fn wxbr_set_sizer(win: *mut c_void, sizer: *mut c_void);
pub fn wxbr_layout(win: *mut c_void);
pub fn wxbr_sizer_detach(sizer: *mut c_void, win: *mut c_void);
pub fn wxbr_fit(win: *mut c_void);
pub fn wxbr_set_min_size(win: *mut c_void, w: c_int, h: c_int);
pub fn wxbr_static_text(parent: *mut c_void, label: *const c_char) -> *mut c_void;
pub fn wxbr_set_label(win: *mut c_void, label: *const c_char);
pub fn wxbr_get_label(win: *mut c_void, buf: *mut c_char, cap: c_int) -> c_int;
pub fn wxbr_set_bold(win: *mut c_void);
pub fn wxbr_set_font_size(win: *mut c_void, pts: c_int);
pub fn wxbr_button(parent: *mut c_void, label: *const c_char, id: c_int) -> *mut c_void;
@@ -53,10 +56,23 @@ 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_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;
pub fn wxbr_dvlc_selected_row(win: *mut c_void) -> c_long;
pub fn wxbr_dvlc_select_row(win: *mut c_void, row: c_long);
pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
pub fn wxbr_gauge_set_range(win: *mut c_void, range: c_int);
pub fn wxbr_gauge_set_value(win: *mut c_void, value: c_int);
pub fn wxbr_gauge_pulse(win: *mut c_void);
pub fn wxbr_show(win: *mut c_void, shown: c_int);
pub fn wxbr_launch_browser(url: *const c_char) -> c_int;
pub fn wxbr_set_appearance_system();
pub fn wxbr_is_dark() -> c_int;
pub fn wxbr_system_color(which: c_int, r: *mut u8, g: *mut u8, b: *mut u8);
pub fn wxbr_set_bg(win: *mut c_void, r: c_int, g: c_int, b: c_int);
pub fn wxbr_set_fg(win: *mut c_void, r: c_int, g: c_int, b: c_int);
pub fn wxbr_destroy(win: *mut c_void);
}
}
@@ -86,6 +102,7 @@ pub enum WxEventKind {
DvlcHeaderClick,
DvlcReordered,
TimerTick,
DvlcActivated,
}
impl WxEventKind {
@@ -97,11 +114,36 @@ impl WxEventKind {
5 => WxEventKind::DvlcHeaderClick,
6 => WxEventKind::DvlcReordered,
7 => WxEventKind::TimerTick,
8 => WxEventKind::DvlcActivated,
_ => return None,
})
}
}
/// Open a URL in the system default browser. Returns true on success.
pub fn launch_browser(url: &str) -> bool {
let c = CString::new(url).unwrap_or_default();
unsafe { notsafe::wxbr_launch_browser(c.as_ptr()) != 0 }
}
/// Ask wx to follow the system light/dark appearance (no-op before 3.3).
pub fn set_appearance_system() {
unsafe { notsafe::wxbr_set_appearance_system() }
}
/// True if the current system appearance is dark.
pub fn is_dark() -> bool {
unsafe { notsafe::wxbr_is_dark() != 0 }
}
/// A theme colour. `which`: 0=window bg, 1=window text, 2=highlight,
/// 3=button face, 4=grey text. Returns (r, g, b).
pub fn system_color(which: i32) -> (u8, u8, u8) {
let (mut r, mut g, mut b) = (0u8, 0u8, 0u8);
unsafe { notsafe::wxbr_system_color(which, &mut r, &mut g, &mut b) }
(r, g, b)
}
/// A widget event: kind plus two payload words.
/// ButtonClicked: p1 = button id.
/// ClbToggled: p1 = control handle, p2 = item index.
@@ -174,6 +216,18 @@ impl Widget {
unsafe { notsafe::wxbr_set_sizer(win.0, self.0) }
}
/// Re-run this window's sizer (self = a window). Call after adding a child
/// window to an already-installed sizer, or after rebuilding the table.
pub fn layout(&self) {
unsafe { notsafe::wxbr_layout(self.0) }
}
/// Detach a child window from this sizer (self = a sizer) without
/// destroying it. Use before destroying a sizer-managed window.
pub fn detach(&self, win: Widget) {
unsafe { notsafe::wxbr_sizer_detach(self.0, win.0) }
}
pub fn fit(&self, win: Widget) {
unsafe { notsafe::wxbr_fit(win.0) }
}
@@ -192,6 +246,18 @@ impl Widget {
unsafe { notsafe::wxbr_set_label(self.0, c.as_ptr()) }
}
/// Read back a control's current label text (self-test uses this to verify
/// what a KPI actually displays).
pub fn get_label(&self) -> String {
let mut buf = vec![0i8; 4096];
let n = unsafe { notsafe::wxbr_get_label(self.0, buf.as_mut_ptr(), buf.len() as c_int) };
if n <= 0 {
return String::new();
}
let bytes: Vec<u8> = buf[..(n - 1) as usize].iter().map(|&b| b as u8).collect();
String::from_utf8_lossy(&bytes).into_owned()
}
pub fn set_bold(&self) {
unsafe { notsafe::wxbr_set_bold(self.0) }
}
@@ -353,10 +419,59 @@ impl Widget {
unsafe { notsafe::wxbr_dvlc_select_row(self.0, row as c_long) }
}
/// Update a column's header text in place (creation index).
pub fn dvlc_set_col_title(&self, col: usize, title: &str) {
let c = CString::new(title).unwrap_or_default();
unsafe { notsafe::wxbr_dvlc_set_col_title(self.0, col as c_int, c.as_ptr()) }
}
/// Show or clear the native sort arrow on a column (creation index).
pub fn dvlc_set_sort_indicator(&self, col: usize, active: bool, ascending: bool) {
unsafe {
notsafe::wxbr_dvlc_set_sort_indicator(
self.0,
col as c_int,
active as c_int,
ascending as c_int,
)
}
}
pub fn timer(id: i32, ms: i32) -> Widget {
Widget(unsafe { notsafe::wxbr_timer(id, ms) })
}
// ---- gauge (progress bar) ----
pub fn gauge(parent: Widget, range: i32) -> Widget {
Widget(unsafe { notsafe::wxbr_gauge(parent.0, range) })
}
pub fn gauge_set_range(&self, range: i32) {
unsafe { notsafe::wxbr_gauge_set_range(self.0, range) }
}
pub fn gauge_set_value(&self, value: i32) {
unsafe { notsafe::wxbr_gauge_set_value(self.0, value) }
}
pub fn gauge_pulse(&self) {
unsafe { notsafe::wxbr_gauge_pulse(self.0) }
}
/// Show or hide this window.
pub fn show(&self, shown: bool) {
unsafe { notsafe::wxbr_show(self.0, shown as c_int) }
}
pub fn set_bg(&self, r: u8, g: u8, b: u8) {
unsafe { notsafe::wxbr_set_bg(self.0, r as c_int, g as c_int, b as c_int) }
}
pub fn set_fg(&self, r: u8, g: u8, b: u8) {
unsafe { notsafe::wxbr_set_fg(self.0, r as c_int, g as c_int, b as c_int) }
}
/// Deferred destruction (safe from event handlers); used to rebuild
/// the table when its column set changes.
pub fn destroy(&self) {