GUI round 3: Excel-style filters, status row colours, icon controls, context menu, live theme
build-test-release / release (push) Successful in 7m10s

Addresses the round-3 feedback batch:

- Right-click now works: a context menu (open selected in browser, select all,
  clear) pops up from the table. It was never wired before. (The live-config
  intersection over the selection remains a follow-up; no dead menu items.)
- Selection is readable again in both themes: the alt-row/zebra CSS hack (which
  painted row backgrounds over the native highlight, leaving white-on-white) is
  gone; the native selection highlight shows through.
- Row text is coloured by status (green = hashing, amber = slow, grey = not
  hashing), which also separates rows without fragile GTK zebra striping.
- Dark mode: KPI cards and rows follow the system theme (no more white boxes in
  dark mode); a system-colour-changed event repaints them live if the OS toggles
  light/dark while the app is open.
- Play / Pause / Stop are coloured media icons (green triangle / amber bars /
  red square) instead of text buttons.
- Filter panel redesigned Excel-style: a column dropdown at the top selects the
  column; controls adapt to its type. Text columns: a value checklist ("is any
  of") or a predicate (contains / does not contain / begins with / ends with /
  equals). Numeric columns: between / = / != / > / >= / < / <=. Filters AND
  across columns; edits held in a working copy, committed on Apply.
- Auto-rescan label shortened to "Rescan (s):" so the value field has room.

Table: replaced wxDataViewListCtrl with a raw wxDataViewCtrl + a custom
AttrListStore (per-row foreground via GetAttrByRow), which keeps in-table column
drag while enabling status row colours. New wx-rs bridge primitives: wxChoice
dropdown, coloured media buttons (drawn on a transparent bitmap via
wxGraphicsContext), a wxEVT_SYS_COLOUR_CHANGED event, destroy_children, and
call_after (deferred rebuilds). Patches 0002/0003 regenerated + round-trip
validated.

Model: ColFilter { Values, Text{op}, Num{op} } with TextOp/NumOp and
passes_filters -> ColFilter::matches; Column::num_value for numeric filtering.

Review fixes (one review pass):
- Deferred the two rebuilds that destroyed a control from inside its own event
  (filter op-dropdown change; column drag-reorder) via call_after, avoiding a
  use-after-free.
- num_value returns None for a blank-displaying value-type cell (Hashrate,
  Power, ChipTemp, ...), so "ChipTemp <= 50" no longer matches a miner with no
  temperature reading.
- Value checklist maps a checked entry back to its real value by index, so a
  literal "(blank)" value is not confused with an empty cell.

Verified off-screen: 45 unit tests, headless self-test (14 checks), and
interaction screenshots of selection, right-click, the text/numeric filter, the
comparator swap, and 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-17 09:19:38 -06:00
co-authored by Claude Opus 4.8
parent 47dfa55502
commit d6868d3d40
6 changed files with 1209 additions and 243 deletions
+84 -1
View File
@@ -10,7 +10,7 @@
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
@@ -0,0 +1,561 @@
@@ -0,0 +1,644 @@
+// 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).
@@ -77,6 +77,7 @@
+ pub fn wxbr_dvlc_get_selections(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
+ pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
+ pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
+ pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
+ pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
+ pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
+ pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
@@ -96,7 +97,16 @@
+ 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_choice(parent: *mut c_void, id: c_int) -> *mut c_void;
+ pub fn wxbr_choice_append(win: *mut c_void, label: *const c_char);
+ pub fn wxbr_choice_clear(win: *mut c_void);
+ pub fn wxbr_choice_get_selection(win: *mut c_void) -> c_int;
+ pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int);
+ pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void;
+ pub fn wxbr_bind_sys_colour(win: *mut c_void);
+ pub fn wxbr_destroy(win: *mut c_void);
+ pub fn wxbr_destroy_children(win: *mut c_void);
+ pub fn wxbr_call_after(id: c_int);
+ }
+}
+
@@ -129,6 +139,9 @@
+ DvlcSelectionChanged,
+ DvlcContextMenu,
+ MenuItem,
+ ChoiceChanged,
+ SysColour,
+ Deferred,
+}
+
+impl WxEventKind {
@@ -144,6 +157,9 @@
+ 9 => WxEventKind::DvlcSelectionChanged,
+ 10 => WxEventKind::DvlcContextMenu,
+ 11 => WxEventKind::MenuItem,
+ 12 => WxEventKind::ChoiceChanged,
+ 13 => WxEventKind::SysColour,
+ 14 => WxEventKind::Deferred,
+ _ => return None,
+ })
+ }
@@ -154,6 +170,13 @@
+ unsafe { notsafe::wxbr_apply_zebra_css(r as c_int, g as c_int, b as c_int) }
+}
+
+/// Schedule a deferred action: a `Deferred` event carrying `id` is delivered
+/// from the event loop after the current event finishes. Use this to rebuild or
+/// destroy a control from outside its own event handler.
+pub fn call_after(id: i32) {
+ unsafe { notsafe::wxbr_call_after(id as c_int) }
+}
+
+/// 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();
@@ -472,6 +495,15 @@
+ unsafe { notsafe::wxbr_dvlc_set_alt_row_color(self.0, r as c_int, g as c_int, b as c_int) }
+ }
+
+ /// Set a row's text colour (e.g. by miner status). Pass `None` to clear it.
+ pub fn dvlc_set_row_color(&self, row: usize, 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_row_color(self.0, row, r, g, b) }
+ }
+
+ // ---- rearrangeable check-list ----
+
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
@@ -566,9 +598,60 @@
+ unsafe { notsafe::wxbr_set_fg(self.0, r as c_int, g as c_int, b as c_int) }
+ }
+
+ // ---- choice (dropdown) ----
+
+ /// Create a dropdown; selection changes emit `ChoiceChanged` with this id.
+ pub fn choice(parent: Widget, id: i32) -> Widget {
+ Widget(unsafe { notsafe::wxbr_choice(parent.0, id) })
+ }
+
+ pub fn choice_append(&self, label: &str) {
+ let c = CString::new(label).unwrap_or_default();
+ unsafe { notsafe::wxbr_choice_append(self.0, c.as_ptr()) }
+ }
+
+ pub fn choice_clear(&self) {
+ unsafe { notsafe::wxbr_choice_clear(self.0) }
+ }
+
+ pub fn choice_get_selection(&self) -> i32 {
+ unsafe { notsafe::wxbr_choice_get_selection(self.0) }
+ }
+
+ pub fn choice_set_selection(&self, i: i32) {
+ unsafe { notsafe::wxbr_choice_set_selection(self.0, i) }
+ }
+
+ // ---- media (icon) button ----
+
+ /// A coloured icon button: `kind` 0=play, 1=pause, 2=stop. Clicks emit
+ /// `ButtonClicked` with `id`, like a normal button.
+ pub fn media_button(parent: Widget, id: i32, kind: i32, color: (u8, u8, u8)) -> Widget {
+ Widget(unsafe {
+ notsafe::wxbr_media_button(
+ parent.0,
+ id,
+ kind,
+ color.0 as c_int,
+ color.1 as c_int,
+ color.2 as c_int,
+ )
+ })
+ }
+
+ /// Listen for OS light/dark theme changes on this window (emits `SysColour`).
+ pub fn bind_sys_colour(&self) {
+ unsafe { notsafe::wxbr_bind_sys_colour(self.0) }
+ }
+
+ /// Deferred destruction (safe from event handlers); used to rebuild
+ /// the table when its column set changes.
+ pub fn destroy(&self) {
+ unsafe { notsafe::wxbr_destroy(self.0) }
+ }
+
+ /// Destroy this window's children (to rebuild dynamic panel contents).
+ pub fn destroy_children(&self) {
+ unsafe { notsafe::wxbr_destroy_children(self.0) }
+ }
+}
+206 -62
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,598 @@
@@ -0,0 +1,742 @@
+// 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).
@@ -23,10 +23,19 @@
+#include <wx/app.h>
+#include <wx/rearrangectrl.h>
+#include <wx/menu.h>
+#include <wx/choice.h>
+#include <wx/bmpbuttn.h>
+#include <wx/bitmap.h>
+#include <wx/image.h>
+#include <wx/dcmemory.h>
+#include <wx/dcgraph.h>
+#include <wx/graphics.h>
+#include <cstring>
+#ifdef __WXGTK__
+#include <gtk/gtk.h>
+#endif
+#include <cstdio>
+#include <vector>
+
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
+static WxWidgetEventFn g_widget_event = nullptr;
@@ -43,6 +52,27 @@
+ WxEV_DVLC_SELECTION_CHANGED = 9,
+ WxEV_DVLC_CONTEXT_MENU = 10,
+ WxEV_MENU_ITEM = 11,
+ WxEV_CHOICE_CHANGED = 12,
+ WxEV_SYS_COLOUR = 13,
+ 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).
+class AttrListStore : public wxDataViewListStore {
+ public:
+ std::vector<wxColour> row_fg;
+ bool GetAttrByRow(unsigned int row, unsigned int col,
+ wxDataViewItemAttr& attr) const override {
+ (void)col;
+ if (row < row_fg.size() && row_fg[row].IsOk()) {
+ attr.SetColour(row_fg[row]);
+ return true;
+ }
+ return false;
+ }
+};
+
+extern "C" {
@@ -269,63 +299,73 @@
+
+// ---- data view list ctrl ------------------------------------------------------
+
+static AttrListStore* dvlc_store(void* win) {
+ return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
+}
+
+void* wxbr_dvlc(void* parent) {
+ // Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
+ // checkbox column.
+ wxDataViewListCtrl* lc =
+ new wxDataViewListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
+ wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
+ lc->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
+ // checkbox column. A custom AttrListStore backs it so rows can be coloured by
+ // 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);
+ AttrListStore* store = new AttrListStore();
+ dv->AssociateModel(store);
+ store->DecRef(); // the control owns a reference now
+ dv->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
+ });
+ lc->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent&) {
+ dv->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_CONTEXT_MENU, 0, 0);
+ });
+ lc->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& e) {
+ dv->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& e) {
+ if (g_widget_event) {
+ wxDataViewListCtrl* lc =
+ dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
+ if (!lc) return;
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
+ if (!dv) return;
+ wxDataViewItem item = e.GetItem();
+ if (!item.IsOk()) return;
+ int row = lc->GetStore()->GetRow(item);
+ int row = ((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
+ g_widget_event(WxEV_DVLC_VALUE_CHANGED, row, (long)e.GetColumn());
+ }
+ });
+ lc->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
+ });
+ lc->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
+ });
+ // 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) {
+ dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
+ if (g_widget_event) {
+ wxDataViewListCtrl* lc =
+ dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
+ if (!lc) return;
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
+ if (!dv) return;
+ wxDataViewItem item = e.GetItem();
+ if (!item.IsOk()) return;
+ int row = lc->GetStore()->GetRow(item);
+ int row = ((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
+ g_widget_event(WxEV_DVLC_ACTIVATED, row, (long)e.GetColumn());
+ }
+ });
+ return (void*)lc;
+ return (void*)dv;
+}
+
+void wxbr_dvlc_append_text_col(void* win, const char* title, int width, int reorderable) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ int flags = wxDATAVIEW_COL_RESIZABLE;
+ if (reorderable) flags |= wxDATAVIEW_COL_REORDERABLE;
+ ((wxDataViewListCtrl*)win)
+ ->AppendTextColumn(wxString::FromUTF8(title), wxDATAVIEW_CELL_INERT,
+ width, wxALIGN_NOT, flags);
+ unsigned col = dv->GetColumnCount(); // next model column index
+ dvlc_store(win)->AppendColumn("string");
+ dv->AppendTextColumn(wxString::FromUTF8(title), col, wxDATAVIEW_CELL_INERT,
+ width, wxALIGN_NOT, flags);
+}
+
+void wxbr_dvlc_append_toggle_col(void* win, int width) {
+ ((wxDataViewListCtrl*)win)
+ ->AppendToggleColumn(wxT(""), wxDATAVIEW_CELL_ACTIVATABLE, width,
+ wxALIGN_CENTRE, 0);
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ unsigned col = dv->GetColumnCount();
+ dvlc_store(win)->AppendColumn("bool");
+ dv->AppendToggleColumn(wxT(""), col, wxDATAVIEW_CELL_ACTIVATABLE, width,
+ wxALIGN_CENTRE, 0);
+}
+
+void wxbr_dvlc_append_row(void* win, int nvals, const char** vals) {
@@ -334,28 +374,45 @@
+ for (int i = 0; i < nvals; i++) {
+ values.push_back(wxVariant(vals[i] ? wxString::FromUTF8(vals[i]) : wxString()));
+ }
+ ((wxDataViewListCtrl*)win)->AppendItem(values);
+ AttrListStore* store = dvlc_store(win);
+ store->AppendItem(values);
+ store->row_fg.push_back(wxColour()); // no per-row colour until set
+}
+
+void wxbr_dvlc_delete_row(void* win, unsigned row) {
+ ((wxDataViewListCtrl*)win)->DeleteItem(row);
+ AttrListStore* store = dvlc_store(win);
+ store->DeleteItem(row);
+ if (row < store->row_fg.size()) store->row_fg.erase(store->row_fg.begin() + row);
+}
+
+void wxbr_dvlc_clear(void* win) { ((wxDataViewListCtrl*)win)->DeleteAllItems(); }
+void wxbr_dvlc_clear(void* win) {
+ AttrListStore* store = dvlc_store(win);
+ store->DeleteAllItems();
+ store->row_fg.clear();
+}
+
+// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
+void wxbr_dvlc_set_row_color(void* win, unsigned row, int r, int g, int b) {
+ AttrListStore* store = dvlc_store(win);
+ if (row >= store->row_fg.size()) return;
+ store->row_fg[row] = (r < 0) ? wxColour() : wxColour(r, g, b);
+ store->RowChanged(row);
+}
+
+int wxbr_dvlc_row_count(void* win) {
+ return (int)((wxDataViewListCtrl*)win)->GetStore()->GetItemCount();
+ return (int)dvlc_store(win)->GetItemCount();
+}
+
+void wxbr_dvlc_set_cell(void* win, unsigned row, unsigned col, const char* value) {
+ ((wxDataViewListCtrl*)win)
+ ->SetValue(wxVariant(wxString::FromUTF8(value)), row, col);
+ AttrListStore* store = dvlc_store(win);
+ store->SetValueByRow(wxVariant(wxString::FromUTF8(value)), row, col);
+ store->RowValueChanged(row, col);
+}
+
+int wxbr_dvlc_get_cell(void* win, unsigned row, unsigned col, char* buf, int cap) {
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
+ wxDataViewListStore* store = lc->GetStore();
+ if (row >= store->GetItemCount() || col >= lc->GetColumnCount())
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ AttrListStore* store = dvlc_store(win);
+ if (row >= store->GetItemCount() || (int)col >= (int)dv->GetColumnCount())
+ return 0;
+ wxVariant v;
+ store->GetValueByRow(v, row, col);
@@ -369,7 +426,7 @@
+}
+
+int wxbr_dvlc_col_count(void* win) {
+ return (int)((wxDataViewListCtrl*)win)->GetColumnCount();
+ return (int)((wxDataViewCtrl*)win)->GetColumnCount();
+}
+
+// Update a column's header text in place (creation index) without recreating
@@ -409,58 +466,51 @@
+}
+
+long wxbr_dvlc_selected_row(void* win) {
+ return (long)((wxDataViewListCtrl*)win)->GetSelectedRow();
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ wxDataViewItem it = dv->GetSelection();
+ if (!it.IsOk()) return -1;
+ return (long)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(it);
+}
+
+// Fill `buf` with the selected row indices (multi-select); returns the count.
+int wxbr_dvlc_get_selections(void* win, int* buf, int cap) {
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
+ wxDataViewItemArray items;
+ int n = (int)lc->GetSelections(items);
+ int n = (int)dv->GetSelections(items);
+ int out = 0;
+ for (int i = 0; i < n && out < cap; i++) {
+ int row = lc->GetStore()->GetRow(items[i]);
+ int row = m->GetRow(items[i]);
+ if (row >= 0) buf[out++] = row;
+ }
+ return out;
+}
+
+void wxbr_dvlc_select_rows(void* win, const int* rows, int n) {
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
+ lc->UnselectAll();
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
+ dv->UnselectAll();
+ for (int i = 0; i < n; i++) {
+ if (rows[i] >= 0) lc->SelectRow((unsigned)rows[i]);
+ if (rows[i] >= 0) dv->Select(m->GetItem((unsigned)rows[i]));
+ }
+}
+
+// Retained for ABI; per-row colour is handled by the store (GetAttrByRow) and
+// the native selection highlight, so these row-background hacks are no-ops now
+// (they fought the selection highlight on GTK 3.3).
+void wxbr_dvlc_set_alt_row_color(void* win, int r, int g, int b) {
+ // No-op on GTK (native dataview lacks it); see wxbr_apply_zebra_css.
+ ((wxDataViewListCtrl*)win)->SetAlternateRowColour(wxColour(r, g, b));
+ (void)win; (void)r; (void)g; (void)b;
+}
+
+// GTK's native dataview does not implement SetAlternateRowColour, so apply
+// zebra striping app-wide via a CSS provider (GTK 3.20+ supports :nth-child on
+// treeview rows). No-op off GTK.
+void wxbr_apply_zebra_css(int r, int g, int b) {
+#ifdef __WXGTK__
+ GtkCssProvider* p = gtk_css_provider_new();
+ char css[192];
+ std::snprintf(css, sizeof(css),
+ "treeview.view:nth-child(even){background-color:rgb(%d,%d,%d);}",
+ r, g, b);
+ gtk_css_provider_load_from_data(p, css, -1, NULL);
+ gtk_style_context_add_provider_for_screen(
+ gdk_screen_get_default(), GTK_STYLE_PROVIDER(p),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref(p);
+#else
+ (void)r; (void)g; (void)b;
+#endif
+}
+
+void wxbr_dvlc_select_row(void* win, long row) {
+ if (row < 0) return;
+ ((wxDataViewListCtrl*)win)->SelectRow((unsigned)row);
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
+ dv->Select(m->GetItem((unsigned)row));
+}
+
+// ---- timer -----------------------------------------------------------------
@@ -594,8 +644,102 @@
+ delete m;
+}
+
+// ---- choice (dropdown) ------------------------------------------------------
+
+void* wxbr_choice(void* parent, int id) {
+ wxChoice* c = new wxChoice((wxWindow*)parent, id);
+ c->Bind(wxEVT_CHOICE, [id](wxCommandEvent& e) {
+ if (g_widget_event)
+ g_widget_event(WxEV_CHOICE_CHANGED, id, (long)e.GetSelection());
+ });
+ return (void*)c;
+}
+
+void wxbr_choice_append(void* win, const char* label) {
+ ((wxChoice*)win)->Append(wxString::FromUTF8(label));
+}
+
+void wxbr_choice_clear(void* win) { ((wxChoice*)win)->Clear(); }
+
+int wxbr_choice_get_selection(void* win) {
+ return ((wxChoice*)win)->GetSelection();
+}
+
+void wxbr_choice_set_selection(void* win, int i) {
+ ((wxChoice*)win)->SetSelection(i);
+}
+
+// ---- media (icon) button: play / pause / stop -------------------------------
+
+// kind: 0=play (triangle), 1=pause (two bars), 2=stop (square). Drawn in the
+// given colour on a transparent bitmap so it reads as a coloured glyph on the
+// native button. Emits WxEV_BUTTON_CLICKED with `id`, like a normal button.
+void* wxbr_media_button(void* parent, int id, int kind, int r, int g, int b) {
+ const int sz = 20;
+ wxImage img(sz, sz);
+ img.InitAlpha();
+ unsigned char* a = img.GetAlpha();
+ if (a) memset(a, 0, (size_t)sz * sz); // fully transparent
+ wxBitmap bmp(img);
+ {
+ wxMemoryDC mdc(bmp);
+ wxGraphicsContext* gc = wxGraphicsContext::Create(mdc);
+ if (gc) {
+ gc->SetAntialiasMode(wxANTIALIAS_DEFAULT);
+ wxColour col(r, g, b);
+ gc->SetBrush(wxBrush(col));
+ gc->SetPen(wxPen(col, 1.0));
+ if (kind == 0) {
+ wxGraphicsPath p = gc->CreatePath();
+ p.MoveToPoint(5, 4);
+ p.AddLineToPoint(16, 10);
+ p.AddLineToPoint(5, 16);
+ p.CloseSubpath();
+ gc->FillPath(p);
+ } else if (kind == 1) {
+ gc->DrawRectangle(5, 4, 3.5, 12);
+ gc->DrawRectangle(11.5, 4, 3.5, 12);
+ } else {
+ gc->DrawRectangle(5, 5, 10, 10);
+ }
+ delete gc;
+ }
+ }
+ wxBitmapButton* btn = new wxBitmapButton((wxWindow*)parent, id, bmp);
+ btn->Bind(wxEVT_BUTTON, [id](wxCommandEvent&) {
+ if (g_widget_event) g_widget_event(WxEV_BUTTON_CLICKED, id, 0);
+ });
+ return (void*)btn;
+}
+
+// ---- live theme changes -----------------------------------------------------
+
+// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
+// repaint custom-coloured widgets (KPI cards, table rows).
+void wxbr_bind_sys_colour(void* win) {
+ ((wxWindow*)win)->Bind(wxEVT_SYS_COLOUR_CHANGED, [](wxSysColourChangedEvent& e) {
+ e.Skip();
+ if (g_widget_event) g_widget_event(WxEV_SYS_COLOUR, 0, 0);
+ });
+}
+
+// Run a deferred action after the current event finishes unwinding: emits
+// WxEV_DEFERRED with `id` from the main event loop. Used to rebuild a control
+// from outside its own event handler (destroying a widget mid-event is unsafe).
+void wxbr_call_after(int id) {
+ if (wxTheApp) {
+ wxTheApp->CallAfter([id]() {
+ if (g_widget_event) g_widget_event(WxEV_DEFERRED, id, 0);
+ });
+ }
+}
+
+// ---- deferred destroy (safe from event handlers) ----------------------------
+
+void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
+
+// Destroy a window's children immediately (used to rebuild a panel's dynamic
+// contents in place, e.g. the filter dialog's per-column controls).
+void wxbr_destroy_children(void* win) { ((wxWindow*)win)->DestroyChildren(); }
+
+} // extern "C"
@@ -20,10 +20,19 @@
#include <wx/app.h>
#include <wx/rearrangectrl.h>
#include <wx/menu.h>
#include <wx/choice.h>
#include <wx/bmpbuttn.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/dcmemory.h>
#include <wx/dcgraph.h>
#include <wx/graphics.h>
#include <cstring>
#ifdef __WXGTK__
#include <gtk/gtk.h>
#endif
#include <cstdio>
#include <vector>
typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
static WxWidgetEventFn g_widget_event = nullptr;
@@ -40,6 +49,27 @@ enum WxWidgetEventKind {
WxEV_DVLC_SELECTION_CHANGED = 9,
WxEV_DVLC_CONTEXT_MENU = 10,
WxEV_MENU_ITEM = 11,
WxEV_CHOICE_CHANGED = 12,
WxEV_SYS_COLOUR = 13,
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).
class AttrListStore : public wxDataViewListStore {
public:
std::vector<wxColour> row_fg;
bool GetAttrByRow(unsigned int row, unsigned int col,
wxDataViewItemAttr& attr) const override {
(void)col;
if (row < row_fg.size() && row_fg[row].IsOk()) {
attr.SetColour(row_fg[row]);
return true;
}
return false;
}
};
extern "C" {
@@ -266,63 +296,73 @@ void wxbr_dialog_close(void* win, int code) {
// ---- data view list ctrl ------------------------------------------------------
static AttrListStore* dvlc_store(void* win) {
return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
}
void* wxbr_dvlc(void* parent) {
// Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
// checkbox column.
wxDataViewListCtrl* lc =
new wxDataViewListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
lc->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
// checkbox column. A custom AttrListStore backs it so rows can be coloured by
// 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);
AttrListStore* store = new AttrListStore();
dv->AssociateModel(store);
store->DecRef(); // the control owns a reference now
dv->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
});
lc->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent&) {
dv->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent&) {
if (g_widget_event) g_widget_event(WxEV_DVLC_CONTEXT_MENU, 0, 0);
});
lc->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& e) {
dv->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& e) {
if (g_widget_event) {
wxDataViewListCtrl* lc =
dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
if (!lc) return;
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
if (!dv) return;
wxDataViewItem item = e.GetItem();
if (!item.IsOk()) return;
int row = lc->GetStore()->GetRow(item);
int row = ((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
g_widget_event(WxEV_DVLC_VALUE_CHANGED, row, (long)e.GetColumn());
}
});
lc->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
});
lc->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
});
// 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) {
dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
if (g_widget_event) {
wxDataViewListCtrl* lc =
dynamic_cast<wxDataViewListCtrl*>((wxWindow*)e.GetEventObject());
if (!lc) return;
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
if (!dv) return;
wxDataViewItem item = e.GetItem();
if (!item.IsOk()) return;
int row = lc->GetStore()->GetRow(item);
int row = ((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
g_widget_event(WxEV_DVLC_ACTIVATED, row, (long)e.GetColumn());
}
});
return (void*)lc;
return (void*)dv;
}
void wxbr_dvlc_append_text_col(void* win, const char* title, int width, int reorderable) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
int flags = wxDATAVIEW_COL_RESIZABLE;
if (reorderable) flags |= wxDATAVIEW_COL_REORDERABLE;
((wxDataViewListCtrl*)win)
->AppendTextColumn(wxString::FromUTF8(title), wxDATAVIEW_CELL_INERT,
width, wxALIGN_NOT, flags);
unsigned col = dv->GetColumnCount(); // next model column index
dvlc_store(win)->AppendColumn("string");
dv->AppendTextColumn(wxString::FromUTF8(title), col, wxDATAVIEW_CELL_INERT,
width, wxALIGN_NOT, flags);
}
void wxbr_dvlc_append_toggle_col(void* win, int width) {
((wxDataViewListCtrl*)win)
->AppendToggleColumn(wxT(""), wxDATAVIEW_CELL_ACTIVATABLE, width,
wxALIGN_CENTRE, 0);
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
unsigned col = dv->GetColumnCount();
dvlc_store(win)->AppendColumn("bool");
dv->AppendToggleColumn(wxT(""), col, wxDATAVIEW_CELL_ACTIVATABLE, width,
wxALIGN_CENTRE, 0);
}
void wxbr_dvlc_append_row(void* win, int nvals, const char** vals) {
@@ -331,28 +371,45 @@ void wxbr_dvlc_append_row(void* win, int nvals, const char** vals) {
for (int i = 0; i < nvals; i++) {
values.push_back(wxVariant(vals[i] ? wxString::FromUTF8(vals[i]) : wxString()));
}
((wxDataViewListCtrl*)win)->AppendItem(values);
AttrListStore* store = dvlc_store(win);
store->AppendItem(values);
store->row_fg.push_back(wxColour()); // no per-row colour until set
}
void wxbr_dvlc_delete_row(void* win, unsigned row) {
((wxDataViewListCtrl*)win)->DeleteItem(row);
AttrListStore* store = dvlc_store(win);
store->DeleteItem(row);
if (row < store->row_fg.size()) store->row_fg.erase(store->row_fg.begin() + row);
}
void wxbr_dvlc_clear(void* win) { ((wxDataViewListCtrl*)win)->DeleteAllItems(); }
void wxbr_dvlc_clear(void* win) {
AttrListStore* store = dvlc_store(win);
store->DeleteAllItems();
store->row_fg.clear();
}
// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
void wxbr_dvlc_set_row_color(void* win, unsigned row, int r, int g, int b) {
AttrListStore* store = dvlc_store(win);
if (row >= store->row_fg.size()) return;
store->row_fg[row] = (r < 0) ? wxColour() : wxColour(r, g, b);
store->RowChanged(row);
}
int wxbr_dvlc_row_count(void* win) {
return (int)((wxDataViewListCtrl*)win)->GetStore()->GetItemCount();
return (int)dvlc_store(win)->GetItemCount();
}
void wxbr_dvlc_set_cell(void* win, unsigned row, unsigned col, const char* value) {
((wxDataViewListCtrl*)win)
->SetValue(wxVariant(wxString::FromUTF8(value)), row, col);
AttrListStore* store = dvlc_store(win);
store->SetValueByRow(wxVariant(wxString::FromUTF8(value)), row, col);
store->RowValueChanged(row, col);
}
int wxbr_dvlc_get_cell(void* win, unsigned row, unsigned col, char* buf, int cap) {
wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
wxDataViewListStore* store = lc->GetStore();
if (row >= store->GetItemCount() || col >= lc->GetColumnCount())
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
AttrListStore* store = dvlc_store(win);
if (row >= store->GetItemCount() || (int)col >= (int)dv->GetColumnCount())
return 0;
wxVariant v;
store->GetValueByRow(v, row, col);
@@ -366,7 +423,7 @@ int wxbr_dvlc_get_cell(void* win, unsigned row, unsigned col, char* buf, int cap
}
int wxbr_dvlc_col_count(void* win) {
return (int)((wxDataViewListCtrl*)win)->GetColumnCount();
return (int)((wxDataViewCtrl*)win)->GetColumnCount();
}
// Update a column's header text in place (creation index) without recreating
@@ -406,58 +463,51 @@ int wxbr_dvlc_col_at_pos(void* win, int pos) {
}
long wxbr_dvlc_selected_row(void* win) {
return (long)((wxDataViewListCtrl*)win)->GetSelectedRow();
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
wxDataViewItem it = dv->GetSelection();
if (!it.IsOk()) return -1;
return (long)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(it);
}
// Fill `buf` with the selected row indices (multi-select); returns the count.
int wxbr_dvlc_get_selections(void* win, int* buf, int cap) {
wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
wxDataViewItemArray items;
int n = (int)lc->GetSelections(items);
int n = (int)dv->GetSelections(items);
int out = 0;
for (int i = 0; i < n && out < cap; i++) {
int row = lc->GetStore()->GetRow(items[i]);
int row = m->GetRow(items[i]);
if (row >= 0) buf[out++] = row;
}
return out;
}
void wxbr_dvlc_select_rows(void* win, const int* rows, int n) {
wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
lc->UnselectAll();
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
dv->UnselectAll();
for (int i = 0; i < n; i++) {
if (rows[i] >= 0) lc->SelectRow((unsigned)rows[i]);
if (rows[i] >= 0) dv->Select(m->GetItem((unsigned)rows[i]));
}
}
// Retained for ABI; per-row colour is handled by the store (GetAttrByRow) and
// the native selection highlight, so these row-background hacks are no-ops now
// (they fought the selection highlight on GTK 3.3).
void wxbr_dvlc_set_alt_row_color(void* win, int r, int g, int b) {
// No-op on GTK (native dataview lacks it); see wxbr_apply_zebra_css.
((wxDataViewListCtrl*)win)->SetAlternateRowColour(wxColour(r, g, b));
(void)win; (void)r; (void)g; (void)b;
}
// GTK's native dataview does not implement SetAlternateRowColour, so apply
// zebra striping app-wide via a CSS provider (GTK 3.20+ supports :nth-child on
// treeview rows). No-op off GTK.
void wxbr_apply_zebra_css(int r, int g, int b) {
#ifdef __WXGTK__
GtkCssProvider* p = gtk_css_provider_new();
char css[192];
std::snprintf(css, sizeof(css),
"treeview.view:nth-child(even){background-color:rgb(%d,%d,%d);}",
r, g, b);
gtk_css_provider_load_from_data(p, css, -1, NULL);
gtk_style_context_add_provider_for_screen(
gdk_screen_get_default(), GTK_STYLE_PROVIDER(p),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(p);
#else
(void)r; (void)g; (void)b;
#endif
}
void wxbr_dvlc_select_row(void* win, long row) {
if (row < 0) return;
((wxDataViewListCtrl*)win)->SelectRow((unsigned)row);
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
dv->Select(m->GetItem((unsigned)row));
}
// ---- timer -----------------------------------------------------------------
@@ -591,8 +641,102 @@ void wxbr_popup_menu(void* win, void* menu) {
delete m;
}
// ---- choice (dropdown) ------------------------------------------------------
void* wxbr_choice(void* parent, int id) {
wxChoice* c = new wxChoice((wxWindow*)parent, id);
c->Bind(wxEVT_CHOICE, [id](wxCommandEvent& e) {
if (g_widget_event)
g_widget_event(WxEV_CHOICE_CHANGED, id, (long)e.GetSelection());
});
return (void*)c;
}
void wxbr_choice_append(void* win, const char* label) {
((wxChoice*)win)->Append(wxString::FromUTF8(label));
}
void wxbr_choice_clear(void* win) { ((wxChoice*)win)->Clear(); }
int wxbr_choice_get_selection(void* win) {
return ((wxChoice*)win)->GetSelection();
}
void wxbr_choice_set_selection(void* win, int i) {
((wxChoice*)win)->SetSelection(i);
}
// ---- media (icon) button: play / pause / stop -------------------------------
// kind: 0=play (triangle), 1=pause (two bars), 2=stop (square). Drawn in the
// given colour on a transparent bitmap so it reads as a coloured glyph on the
// native button. Emits WxEV_BUTTON_CLICKED with `id`, like a normal button.
void* wxbr_media_button(void* parent, int id, int kind, int r, int g, int b) {
const int sz = 20;
wxImage img(sz, sz);
img.InitAlpha();
unsigned char* a = img.GetAlpha();
if (a) memset(a, 0, (size_t)sz * sz); // fully transparent
wxBitmap bmp(img);
{
wxMemoryDC mdc(bmp);
wxGraphicsContext* gc = wxGraphicsContext::Create(mdc);
if (gc) {
gc->SetAntialiasMode(wxANTIALIAS_DEFAULT);
wxColour col(r, g, b);
gc->SetBrush(wxBrush(col));
gc->SetPen(wxPen(col, 1.0));
if (kind == 0) {
wxGraphicsPath p = gc->CreatePath();
p.MoveToPoint(5, 4);
p.AddLineToPoint(16, 10);
p.AddLineToPoint(5, 16);
p.CloseSubpath();
gc->FillPath(p);
} else if (kind == 1) {
gc->DrawRectangle(5, 4, 3.5, 12);
gc->DrawRectangle(11.5, 4, 3.5, 12);
} else {
gc->DrawRectangle(5, 5, 10, 10);
}
delete gc;
}
}
wxBitmapButton* btn = new wxBitmapButton((wxWindow*)parent, id, bmp);
btn->Bind(wxEVT_BUTTON, [id](wxCommandEvent&) {
if (g_widget_event) g_widget_event(WxEV_BUTTON_CLICKED, id, 0);
});
return (void*)btn;
}
// ---- live theme changes -----------------------------------------------------
// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
// repaint custom-coloured widgets (KPI cards, table rows).
void wxbr_bind_sys_colour(void* win) {
((wxWindow*)win)->Bind(wxEVT_SYS_COLOUR_CHANGED, [](wxSysColourChangedEvent& e) {
e.Skip();
if (g_widget_event) g_widget_event(WxEV_SYS_COLOUR, 0, 0);
});
}
// Run a deferred action after the current event finishes unwinding: emits
// WxEV_DEFERRED with `id` from the main event loop. Used to rebuild a control
// from outside its own event handler (destroying a widget mid-event is unsafe).
void wxbr_call_after(int id) {
if (wxTheApp) {
wxTheApp->CallAfter([id]() {
if (g_widget_event) g_widget_event(WxEV_DEFERRED, id, 0);
});
}
}
// ---- deferred destroy (safe from event handlers) ----------------------------
void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
// Destroy a window's children immediately (used to rebuild a panel's dynamic
// contents in place, e.g. the filter dialog's per-column controls).
void wxbr_destroy_children(void* win) { ((wxWindow*)win)->DestroyChildren(); }
} // extern "C"
+83
View File
@@ -64,6 +64,7 @@ mod notsafe {
pub fn wxbr_dvlc_get_selections(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
@@ -83,7 +84,16 @@ mod notsafe {
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_choice(parent: *mut c_void, id: c_int) -> *mut c_void;
pub fn wxbr_choice_append(win: *mut c_void, label: *const c_char);
pub fn wxbr_choice_clear(win: *mut c_void);
pub fn wxbr_choice_get_selection(win: *mut c_void) -> c_int;
pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int);
pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void;
pub fn wxbr_bind_sys_colour(win: *mut c_void);
pub fn wxbr_destroy(win: *mut c_void);
pub fn wxbr_destroy_children(win: *mut c_void);
pub fn wxbr_call_after(id: c_int);
}
}
@@ -116,6 +126,9 @@ pub enum WxEventKind {
DvlcSelectionChanged,
DvlcContextMenu,
MenuItem,
ChoiceChanged,
SysColour,
Deferred,
}
impl WxEventKind {
@@ -131,6 +144,9 @@ impl WxEventKind {
9 => WxEventKind::DvlcSelectionChanged,
10 => WxEventKind::DvlcContextMenu,
11 => WxEventKind::MenuItem,
12 => WxEventKind::ChoiceChanged,
13 => WxEventKind::SysColour,
14 => WxEventKind::Deferred,
_ => return None,
})
}
@@ -141,6 +157,13 @@ pub fn apply_zebra_css(r: u8, g: u8, b: u8) {
unsafe { notsafe::wxbr_apply_zebra_css(r as c_int, g as c_int, b as c_int) }
}
/// Schedule a deferred action: a `Deferred` event carrying `id` is delivered
/// from the event loop after the current event finishes. Use this to rebuild or
/// destroy a control from outside its own event handler.
pub fn call_after(id: i32) {
unsafe { notsafe::wxbr_call_after(id as c_int) }
}
/// 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();
@@ -459,6 +482,15 @@ impl Widget {
unsafe { notsafe::wxbr_dvlc_set_alt_row_color(self.0, r as c_int, g as c_int, b as c_int) }
}
/// Set a row's text colour (e.g. by miner status). Pass `None` to clear it.
pub fn dvlc_set_row_color(&self, row: usize, 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_row_color(self.0, row, r, g, b) }
}
// ---- rearrangeable check-list ----
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
@@ -553,9 +585,60 @@ impl Widget {
unsafe { notsafe::wxbr_set_fg(self.0, r as c_int, g as c_int, b as c_int) }
}
// ---- choice (dropdown) ----
/// Create a dropdown; selection changes emit `ChoiceChanged` with this id.
pub fn choice(parent: Widget, id: i32) -> Widget {
Widget(unsafe { notsafe::wxbr_choice(parent.0, id) })
}
pub fn choice_append(&self, label: &str) {
let c = CString::new(label).unwrap_or_default();
unsafe { notsafe::wxbr_choice_append(self.0, c.as_ptr()) }
}
pub fn choice_clear(&self) {
unsafe { notsafe::wxbr_choice_clear(self.0) }
}
pub fn choice_get_selection(&self) -> i32 {
unsafe { notsafe::wxbr_choice_get_selection(self.0) }
}
pub fn choice_set_selection(&self, i: i32) {
unsafe { notsafe::wxbr_choice_set_selection(self.0, i) }
}
// ---- media (icon) button ----
/// A coloured icon button: `kind` 0=play, 1=pause, 2=stop. Clicks emit
/// `ButtonClicked` with `id`, like a normal button.
pub fn media_button(parent: Widget, id: i32, kind: i32, color: (u8, u8, u8)) -> Widget {
Widget(unsafe {
notsafe::wxbr_media_button(
parent.0,
id,
kind,
color.0 as c_int,
color.1 as c_int,
color.2 as c_int,
)
})
}
/// Listen for OS light/dark theme changes on this window (emits `SysColour`).
pub fn bind_sys_colour(&self) {
unsafe { notsafe::wxbr_bind_sys_colour(self.0) }
}
/// Deferred destruction (safe from event handlers); used to rebuild
/// the table when its column set changes.
pub fn destroy(&self) {
unsafe { notsafe::wxbr_destroy(self.0) }
}
/// Destroy this window's children (to rebuild dynamic panel contents).
pub fn destroy_children(&self) {
unsafe { notsafe::wxbr_destroy_children(self.0) }
}
}