Compare commits

...
2 Commits
Author SHA1 Message Date
noahandClaude Opus 4.8 e593548746 GUI round 11 (#4): drag-reorder + multi-select columns dialog (no up/down buttons)
Replaces the columns dialog's wxRearrangeCtrl (checkboxes + up/down buttons)
with a wxListCtrl-based list (new wxbr_reorder_list / Widget::reorder_list):
- No up/down buttons; rows are reordered by dragging.
- Native multi-select: Shift/Ctrl-click and rubber-band drag.
- Keeps per-row checkboxes for show/hide; same [idx | !idx] order encoding, so
  apply_columns is unchanged.

Drag-reorder is implemented by recording the selected rows' base indices on
wxEVT_LIST_BEGIN_DRAG and moving that group to the row under the cursor on the
following mouse-up (no real DnD loop is started, so the mouse-up still arrives).

Verified: the dialog opens without crashing and renders the checkable, button-
free list (headless click test). The drag and shift/ctrl multi-select
interactions are not headlessly simulatable and need interactive confirmation.

Bridge + Rust mirrored into patches 0002 (widgets.rs) and 0003
(widgets_bridge.cpp) per ADR 0003.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-18 18:03:47 -06:00
noahandClaude Opus 4.8 2fd433c3b0 GUI round 11 (#15): drawn icons on the KPI cards
Each KPI card's value now leads with a small vector icon drawn into a
transparent bitmap via wxGraphicsContext (new wxbr_kpi_icon -> Widget::kpi_icon):
rabbit = Hashing, turtle = Slow, broken wine glass = Not hashing, otter =
Paused, hive = SHA-256 Hashrate, lightning bolt = Est. power; Total has none.
The icon takes the card's value colour (amber on the neutral Est. power card so
the bolt reads).

The icons are simple flat silhouettes so they render at ~22px without external
assets (no emoji/pictographs in source). The rabbit, turtle, wine glass, hive,
and lightning read clearly; the otter is the least distinct at this size.

Bridge + Rust mirrored into patches 0002 (widgets.rs) and 0003
(widgets_bridge.cpp) per ADR 0003. Self-test passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-18 17:51:09 -06:00
5 changed files with 505 additions and 14 deletions
+29 -12
View File
@@ -522,7 +522,7 @@ pub fn build(frame: Widget) -> App {
// min size floors them at their largest content's width.
let kpi_row = Widget::box_sizer(false);
let mut kpi_cards: Vec<(Widget, Widget, Widget, ColorKind)> = Vec::new();
let mut mk_card = |label: &str, kind: ColorKind| -> (Widget, Widget) {
let mut mk_card = |label: &str, kind: ColorKind, icon: Option<i32>| -> (Widget, Widget) {
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);
@@ -553,8 +553,23 @@ pub fn build(frame: Widget) -> App {
row.add_stretch(1);
row
};
// The value row optionally leads with a small drawn KPI icon (round 11
// #15). Neutral cards (Est. power) colour the icon amber for pop since
// their value text stays the default (dimming) colour.
let value_row = {
let row = Widget::box_sizer(false);
row.add_stretch(1);
if let Some(ik) = icon {
let icol = if matches!(kind, ColorKind::Neutral) { pal.amber } else { vc };
let ic = Widget::kpi_icon(card, ik, icol);
row.add(ic, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_RIGHT, 5);
}
row.add(value, 0, sf::ALIGN_CENTRE_VERTICAL, 0);
row.add_stretch(1);
row
};
cs.add_stretch(1);
cs.add_sizer(centre(value), 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_TOP | sf::BORDER_RIGHT, 8);
cs.add_sizer(value_row, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_TOP | sf::BORDER_RIGHT, 8);
cs.add_sizer(centre(lbl), 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_BOTTOM | sf::BORDER_RIGHT, 8);
cs.add_stretch(1);
cs.set_sizer_on(card);
@@ -562,13 +577,15 @@ pub fn build(frame: Widget) -> App {
kpi_cards.push((card, value, lbl, kind));
(card, value)
};
let (_card_total, kpi_total) = mk_card("Total", ColorKind::Neutral);
let (card_hashing, kpi_hashing) = mk_card("Hashing", ColorKind::Green);
let (card_slow, kpi_slow) = mk_card("Slow", ColorKind::Amber);
let (card_not, kpi_not) = mk_card("Not hashing", ColorKind::Red);
let (card_paused, kpi_paused) = mk_card("Paused", ColorKind::Blue);
let (card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Accent);
let (_card_power, kpi_power) = mk_card("Est. power", ColorKind::Neutral);
// Icons (round 11 #15): rabbit=hashing, turtle=slow, broken glass=not
// hashing, otter=paused, hive=hashrate, lightning=power; Total has none.
let (_card_total, kpi_total) = mk_card("Total", ColorKind::Neutral, None);
let (card_hashing, kpi_hashing) = mk_card("Hashing", ColorKind::Green, Some(0));
let (card_slow, kpi_slow) = mk_card("Slow", ColorKind::Amber, Some(1));
let (card_not, kpi_not) = mk_card("Not hashing", ColorKind::Red, Some(2));
let (card_paused, kpi_paused) = mk_card("Paused", ColorKind::Blue, Some(3));
let (card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Accent, Some(4));
let (_card_power, kpi_power) = mk_card("Est. power", ColorKind::Neutral, Some(5));
drop(mk_card);
let _ = (card_hashing, card_slow, card_not, card_paused);
// The hashrate card is kpi_cards[5] in build order (Total, Hashing, Slow,
@@ -2357,7 +2374,7 @@ impl App {
let root = Widget::box_sizer(true);
let hint = Widget::static_text(
dlg,
"Check to show a metric; drag or use the arrows to reorder (IP is always first).",
"Check to show a metric; drag rows to reorder (IP is always first). Shift/Ctrl-click or drag to select several.",
);
root.add(hint, 0, sf::BORDER_ALL, 6);
// Base list is registry order; the wx order array lists items in the
@@ -2372,7 +2389,7 @@ impl App {
order.push(if self.view.visible.contains(c) { idx } else { !idx });
}
}
let list = Widget::rearrange_list(dlg, &order, &titles);
let list = Widget::reorder_list(dlg, &order, &titles);
root.add(list, 1, sf::EXPAND | sf::BORDER_ALL, 6);
// Option: hide columns with no scanned value in any row (round 11 #9).
let hide_empty = Widget::check_box(dlg, "Hide columns with no scanned values");
@@ -2395,7 +2412,7 @@ impl App {
// applies it non-destructively when the table is (re)built below.
self.auto_hide_empty = self.columns_hide_empty_cb.is_checked();
let base = Self::selectable_columns();
let order = self.columns_list.rearrange_get_order();
let order = self.columns_list.reorder_get_order();
let mut new_order: Vec<Column> = vec![Column::Ip];
let mut visible: HashSet<Column> = HashSet::from([Column::Ip]);
for entry in order {
+39 -1
View File
@@ -10,7 +10,7 @@
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
@@ -0,0 +1,762 @@
@@ -0,0 +1,800 @@
+// 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).
@@ -92,6 +92,8 @@
+ 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;
+ pub fn wxbr_reorder_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
+ pub fn wxbr_reorder_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
+ pub fn wxbr_menu_new() -> *mut c_void;
+ pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
+ pub fn wxbr_menu_append_separator(menu: *mut c_void);
@@ -114,6 +116,7 @@
+ 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_kpi_icon(parent: *mut c_void, 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);
@@ -643,6 +646,27 @@
+ buf.into_iter().take(n.max(0) as usize).collect()
+ }
+
+ /// A checkable, multi-select, drag-reorderable column list (round 11 #4):
+ /// like `rearrange_list` but with no up/down buttons -- rows are reordered by
+ /// dragging, and selected with shift/ctrl-click or a rubber-band drag. Same
+ /// `[idx | !idx]` order encoding.
+ pub fn reorder_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
+ let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
+ let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
+ Widget(unsafe {
+ notsafe::wxbr_reorder_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
+ })
+ }
+
+ /// Read back the current order from a `reorder_list` (same encoding).
+ pub fn reorder_get_order(&self) -> Vec<i32> {
+ let mut buf = vec![0i32; 4096];
+ let n = unsafe {
+ notsafe::wxbr_reorder_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
+ };
+ buf.into_iter().take(n.max(0) as usize).collect()
+ }
+
+ // ---- popup menu ----
+
+ pub fn menu_new() -> Widget {
@@ -757,6 +781,20 @@
+ })
+ }
+
+ /// A small drawn KPI icon (static bitmap). kind: 0 rabbit, 1 turtle,
+ /// 2 broken wine glass, 3 otter, 4 hive, 5 lightning bolt (round 11 #15).
+ pub fn kpi_icon(parent: Widget, kind: i32, color: (u8, u8, u8)) -> Widget {
+ Widget(unsafe {
+ notsafe::wxbr_kpi_icon(
+ parent.0,
+ 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) }
+200 -1
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,1284 @@
@@ -0,0 +1,1483 @@
+// 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).
@@ -22,6 +22,7 @@
+#include <wx/utils.h>
+#include <wx/app.h>
+#include <wx/rearrangectrl.h>
+#include <wx/listctrl.h>
+#include <wx/menu.h>
+#include <wx/choice.h>
+#include <wx/bmpbuttn.h>
@@ -1113,6 +1114,109 @@
+ return n < cap ? n : cap;
+}
+
+// ---- reorder list: a checkable, multi-select, drag-reorderable column list
+// for the Columns dialog (round 11 #4). Replaces wxRearrangeCtrl (which had
+// up/down buttons and no drag / multi-select). It is a single-column headerless
+// wxListCtrl with native checkboxes; rows carry their base model index as item
+// data, and the check state + row order encode the same [idx | ~idx] contract
+// as wxbr_rearrange_get_order. Selection (shift/ctrl-click, rubber-band drag) is
+// native to wxListCtrl. Drag-reorder: on begin-drag we record the selected rows'
+// base indices, and on the following mouse-up we move that group to the row
+// under the cursor (we never start a real DnD loop, so the mouse-up still
+// arrives).
+static wxVector<long> g_reorder_drag;
+static wxListCtrl* g_reorder_list = nullptr;
+
+void* wxbr_reorder_list(void* parent, int n, const int* order, const char** items) {
+ wxListCtrl* lc = new wxListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
+ wxSize(-1, 240), wxLC_REPORT | wxLC_NO_HEADER);
+ lc->EnableCheckBoxes(true);
+ lc->InsertColumn(0, wxT("Column"), wxLIST_FORMAT_LEFT, 260);
+ for (int i = 0; i < n; i++) {
+ int enc = order[i];
+ int idx = enc < 0 ? ~enc : enc;
+ long row = lc->InsertItem(i, wxString::FromUTF8(items[idx]));
+ lc->SetItemData(row, (long)idx);
+ lc->CheckItem(row, enc >= 0);
+ }
+ lc->Bind(wxEVT_LIST_BEGIN_DRAG, [lc](wxListEvent&) {
+ g_reorder_drag.clear();
+ g_reorder_list = lc;
+ long it = -1;
+ for (;;) {
+ it = lc->GetNextItem(it, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (it == -1) break;
+ g_reorder_drag.push_back(lc->GetItemData(it));
+ }
+ });
+ lc->Bind(wxEVT_LEFT_UP, [lc](wxMouseEvent& e) {
+ e.Skip();
+ if (g_reorder_list != lc || g_reorder_drag.empty()) return;
+ struct Row {
+ long data;
+ bool checked;
+ wxString text;
+ };
+ int count = lc->GetItemCount();
+ wxVector<Row> rows;
+ for (int i = 0; i < count; i++) {
+ Row r;
+ r.data = lc->GetItemData(i);
+ r.checked = lc->IsItemChecked(i);
+ r.text = lc->GetItemText(i);
+ rows.push_back(r);
+ }
+ auto isDragged = [](long d) {
+ for (size_t i = 0; i < g_reorder_drag.size(); i++)
+ if (g_reorder_drag[i] == d) return true;
+ return false;
+ };
+ int flags = 0;
+ long targetRow = lc->HitTest(e.GetPosition(), flags);
+ long anchor = (targetRow >= 0 && targetRow < count) ? rows[targetRow].data : -1;
+ if (anchor >= 0 && isDragged(anchor)) anchor = -1;
+ wxVector<Row> remaining, moved;
+ for (size_t i = 0; i < rows.size(); i++) {
+ if (isDragged(rows[i].data))
+ moved.push_back(rows[i]);
+ else
+ remaining.push_back(rows[i]);
+ }
+ int insertAt = (int)remaining.size();
+ if (anchor >= 0) {
+ for (size_t i = 0; i < remaining.size(); i++)
+ if (remaining[i].data == anchor) {
+ insertAt = (int)i;
+ break;
+ }
+ }
+ wxVector<Row> result;
+ for (int i = 0; i < insertAt; i++) result.push_back(remaining[i]);
+ for (size_t i = 0; i < moved.size(); i++) result.push_back(moved[i]);
+ for (int i = insertAt; i < (int)remaining.size(); i++) result.push_back(remaining[i]);
+ lc->DeleteAllItems();
+ for (size_t i = 0; i < result.size(); i++) {
+ long row = lc->InsertItem((long)i, result[i].text);
+ lc->SetItemData(row, result[i].data);
+ lc->CheckItem(row, result[i].checked);
+ }
+ g_reorder_drag.clear();
+ g_reorder_list = nullptr;
+ });
+ return (void*)lc;
+}
+
+int wxbr_reorder_get_order(void* win, int* buf, int cap) {
+ wxListCtrl* lc = (wxListCtrl*)win;
+ int count = lc->GetItemCount();
+ int n = 0;
+ for (int i = 0; i < count && n < cap; i++) {
+ int idx = (int)lc->GetItemData(i);
+ buf[n++] = lc->IsItemChecked(i) ? idx : ~idx;
+ }
+ return n;
+}
+
+// ---- popup menu (right-click context menu) ----------------------------------
+
+void* wxbr_menu_new() { return (void*)new wxMenu(); }
@@ -1205,6 +1309,101 @@
+ return (void*)btn;
+}
+
+// A small vector icon drawn into a transparent bitmap and wrapped in a
+// wxStaticBitmap, for the KPI cards (round 11 #15). kind: 0 rabbit (hashing),
+// 1 turtle (slow), 2 broken wine glass (not hashing), 3 otter (paused),
+// 4 hive (hashrate), 5 lightning bolt (power). Drawn as simple silhouettes so
+// they read at ~22px; the colour matches the card's value colour.
+void* wxbr_kpi_icon(void* parent, int kind, int r, int g, int b) {
+ const int sz = 22;
+ wxImage img(sz, sz);
+ img.InitAlpha();
+ unsigned char* a = img.GetAlpha();
+ if (a) memset(a, 0, (size_t)sz * sz);
+ wxBitmap bmp(img);
+ {
+ wxMemoryDC mdc(bmp);
+ wxGraphicsContext* gc = wxGraphicsContext::Create(mdc);
+ if (gc) {
+ gc->SetAntialiasMode(wxANTIALIAS_DEFAULT);
+ wxColour col(r, g, b);
+ wxColour dark((unsigned char)(r * 0.5), (unsigned char)(g * 0.5), (unsigned char)(b * 0.5));
+ gc->SetBrush(wxBrush(col));
+ gc->SetPen(wxPen(col, 1.0));
+ switch (kind) {
+ case 0: { // rabbit: low haunch body + head + two long spread ears
+ gc->DrawEllipse(4, 12, 14, 8); // haunch (low, wide)
+ gc->DrawEllipse(6.5, 7, 8, 8); // head
+ gc->DrawEllipse(6, 0, 2.6, 9); // left ear (long)
+ gc->DrawEllipse(12, 0, 2.6, 9); // right ear (long, spread)
+ break;
+ }
+ case 1: { // turtle: wide shell + head + two visible legs
+ gc->DrawEllipse(4, 6, 13, 9);
+ gc->DrawEllipse(15.5, 8, 4.5, 4.5); // head
+ gc->DrawEllipse(4.5, 12.5, 4, 4); // front leg
+ gc->DrawEllipse(11, 12.5, 4, 4); // back leg
+ break;
+ }
+ case 2: { // broken wine glass: bowl + stem + base, with a crack
+ wxGraphicsPath bowl = gc->CreatePath();
+ bowl.MoveToPoint(5, 3);
+ bowl.AddLineToPoint(17, 3);
+ bowl.AddLineToPoint(11, 12);
+ bowl.CloseSubpath();
+ gc->FillPath(bowl);
+ gc->DrawRectangle(10.2, 12, 1.6, 6);
+ gc->DrawRoundedRectangle(7, 18, 8, 2, 1);
+ wxGraphicsPath crack = gc->CreatePath(); // jagged crack across the bowl
+ crack.MoveToPoint(11, 3);
+ crack.AddLineToPoint(9, 6);
+ crack.AddLineToPoint(12.5, 8);
+ crack.AddLineToPoint(10.5, 11.5);
+ gc->SetPen(wxPen(dark, 1.4));
+ gc->StrokePath(crack);
+ break;
+ }
+ case 3: { // otter: upright tapered body + head + small ears + thick tail
+ wxGraphicsPath tail = gc->CreatePath(); // thick tapering tail curving right
+ tail.MoveToPoint(13, 17);
+ tail.AddCurveToPoint(19, 16, 21, 20, 19, 21);
+ tail.AddCurveToPoint(17, 21, 15, 20, 12, 19);
+ tail.CloseSubpath();
+ gc->FillPath(tail);
+ gc->DrawEllipse(6, 8, 10, 13); // body (tapered upright)
+ gc->DrawEllipse(7, 3, 8, 8); // head (wide)
+ gc->DrawEllipse(7, 2.5, 2.6, 2.6); // ear L
+ gc->DrawEllipse(12.4, 2.5, 2.6, 2.6);// ear R
+ break;
+ }
+ case 4: { // hive (skep): three stacked bands narrowing upward + entrance
+ gc->DrawRoundedRectangle(6, 2.5, 10, 4, 2);
+ gc->DrawRoundedRectangle(4, 7, 14, 4, 2);
+ gc->DrawRoundedRectangle(2.5, 11.5, 17, 5, 2.5);
+ gc->SetBrush(wxBrush(dark));
+ gc->SetPen(wxPen(dark, 1.0));
+ gc->DrawEllipse(9.3, 13, 3.4, 3.6);
+ break;
+ }
+ default: { // 5 lightning bolt
+ wxGraphicsPath p = gc->CreatePath();
+ p.MoveToPoint(13, 2);
+ p.AddLineToPoint(5, 12);
+ p.AddLineToPoint(10, 12);
+ p.AddLineToPoint(8, 20);
+ p.AddLineToPoint(17, 9);
+ p.AddLineToPoint(11, 9);
+ p.CloseSubpath();
+ gc->FillPath(p);
+ break;
+ }
+ }
+ delete gc;
+ }
+ }
+ return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp);
+}
+
+// ---- live theme changes -----------------------------------------------------
+
+// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
@@ -19,6 +19,7 @@
#include <wx/utils.h>
#include <wx/app.h>
#include <wx/rearrangectrl.h>
#include <wx/listctrl.h>
#include <wx/menu.h>
#include <wx/choice.h>
#include <wx/bmpbuttn.h>
@@ -1110,6 +1111,109 @@ int wxbr_rearrange_get_order(void* win, int* buf, int cap) {
return n < cap ? n : cap;
}
// ---- reorder list: a checkable, multi-select, drag-reorderable column list
// for the Columns dialog (round 11 #4). Replaces wxRearrangeCtrl (which had
// up/down buttons and no drag / multi-select). It is a single-column headerless
// wxListCtrl with native checkboxes; rows carry their base model index as item
// data, and the check state + row order encode the same [idx | ~idx] contract
// as wxbr_rearrange_get_order. Selection (shift/ctrl-click, rubber-band drag) is
// native to wxListCtrl. Drag-reorder: on begin-drag we record the selected rows'
// base indices, and on the following mouse-up we move that group to the row
// under the cursor (we never start a real DnD loop, so the mouse-up still
// arrives).
static wxVector<long> g_reorder_drag;
static wxListCtrl* g_reorder_list = nullptr;
void* wxbr_reorder_list(void* parent, int n, const int* order, const char** items) {
wxListCtrl* lc = new wxListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
wxSize(-1, 240), wxLC_REPORT | wxLC_NO_HEADER);
lc->EnableCheckBoxes(true);
lc->InsertColumn(0, wxT("Column"), wxLIST_FORMAT_LEFT, 260);
for (int i = 0; i < n; i++) {
int enc = order[i];
int idx = enc < 0 ? ~enc : enc;
long row = lc->InsertItem(i, wxString::FromUTF8(items[idx]));
lc->SetItemData(row, (long)idx);
lc->CheckItem(row, enc >= 0);
}
lc->Bind(wxEVT_LIST_BEGIN_DRAG, [lc](wxListEvent&) {
g_reorder_drag.clear();
g_reorder_list = lc;
long it = -1;
for (;;) {
it = lc->GetNextItem(it, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (it == -1) break;
g_reorder_drag.push_back(lc->GetItemData(it));
}
});
lc->Bind(wxEVT_LEFT_UP, [lc](wxMouseEvent& e) {
e.Skip();
if (g_reorder_list != lc || g_reorder_drag.empty()) return;
struct Row {
long data;
bool checked;
wxString text;
};
int count = lc->GetItemCount();
wxVector<Row> rows;
for (int i = 0; i < count; i++) {
Row r;
r.data = lc->GetItemData(i);
r.checked = lc->IsItemChecked(i);
r.text = lc->GetItemText(i);
rows.push_back(r);
}
auto isDragged = [](long d) {
for (size_t i = 0; i < g_reorder_drag.size(); i++)
if (g_reorder_drag[i] == d) return true;
return false;
};
int flags = 0;
long targetRow = lc->HitTest(e.GetPosition(), flags);
long anchor = (targetRow >= 0 && targetRow < count) ? rows[targetRow].data : -1;
if (anchor >= 0 && isDragged(anchor)) anchor = -1;
wxVector<Row> remaining, moved;
for (size_t i = 0; i < rows.size(); i++) {
if (isDragged(rows[i].data))
moved.push_back(rows[i]);
else
remaining.push_back(rows[i]);
}
int insertAt = (int)remaining.size();
if (anchor >= 0) {
for (size_t i = 0; i < remaining.size(); i++)
if (remaining[i].data == anchor) {
insertAt = (int)i;
break;
}
}
wxVector<Row> result;
for (int i = 0; i < insertAt; i++) result.push_back(remaining[i]);
for (size_t i = 0; i < moved.size(); i++) result.push_back(moved[i]);
for (int i = insertAt; i < (int)remaining.size(); i++) result.push_back(remaining[i]);
lc->DeleteAllItems();
for (size_t i = 0; i < result.size(); i++) {
long row = lc->InsertItem((long)i, result[i].text);
lc->SetItemData(row, result[i].data);
lc->CheckItem(row, result[i].checked);
}
g_reorder_drag.clear();
g_reorder_list = nullptr;
});
return (void*)lc;
}
int wxbr_reorder_get_order(void* win, int* buf, int cap) {
wxListCtrl* lc = (wxListCtrl*)win;
int count = lc->GetItemCount();
int n = 0;
for (int i = 0; i < count && n < cap; i++) {
int idx = (int)lc->GetItemData(i);
buf[n++] = lc->IsItemChecked(i) ? idx : ~idx;
}
return n;
}
// ---- popup menu (right-click context menu) ----------------------------------
void* wxbr_menu_new() { return (void*)new wxMenu(); }
@@ -1202,6 +1306,101 @@ void* wxbr_media_button(void* parent, int id, int kind, int r, int g, int b) {
return (void*)btn;
}
// A small vector icon drawn into a transparent bitmap and wrapped in a
// wxStaticBitmap, for the KPI cards (round 11 #15). kind: 0 rabbit (hashing),
// 1 turtle (slow), 2 broken wine glass (not hashing), 3 otter (paused),
// 4 hive (hashrate), 5 lightning bolt (power). Drawn as simple silhouettes so
// they read at ~22px; the colour matches the card's value colour.
void* wxbr_kpi_icon(void* parent, int kind, int r, int g, int b) {
const int sz = 22;
wxImage img(sz, sz);
img.InitAlpha();
unsigned char* a = img.GetAlpha();
if (a) memset(a, 0, (size_t)sz * sz);
wxBitmap bmp(img);
{
wxMemoryDC mdc(bmp);
wxGraphicsContext* gc = wxGraphicsContext::Create(mdc);
if (gc) {
gc->SetAntialiasMode(wxANTIALIAS_DEFAULT);
wxColour col(r, g, b);
wxColour dark((unsigned char)(r * 0.5), (unsigned char)(g * 0.5), (unsigned char)(b * 0.5));
gc->SetBrush(wxBrush(col));
gc->SetPen(wxPen(col, 1.0));
switch (kind) {
case 0: { // rabbit: low haunch body + head + two long spread ears
gc->DrawEllipse(4, 12, 14, 8); // haunch (low, wide)
gc->DrawEllipse(6.5, 7, 8, 8); // head
gc->DrawEllipse(6, 0, 2.6, 9); // left ear (long)
gc->DrawEllipse(12, 0, 2.6, 9); // right ear (long, spread)
break;
}
case 1: { // turtle: wide shell + head + two visible legs
gc->DrawEllipse(4, 6, 13, 9);
gc->DrawEllipse(15.5, 8, 4.5, 4.5); // head
gc->DrawEllipse(4.5, 12.5, 4, 4); // front leg
gc->DrawEllipse(11, 12.5, 4, 4); // back leg
break;
}
case 2: { // broken wine glass: bowl + stem + base, with a crack
wxGraphicsPath bowl = gc->CreatePath();
bowl.MoveToPoint(5, 3);
bowl.AddLineToPoint(17, 3);
bowl.AddLineToPoint(11, 12);
bowl.CloseSubpath();
gc->FillPath(bowl);
gc->DrawRectangle(10.2, 12, 1.6, 6);
gc->DrawRoundedRectangle(7, 18, 8, 2, 1);
wxGraphicsPath crack = gc->CreatePath(); // jagged crack across the bowl
crack.MoveToPoint(11, 3);
crack.AddLineToPoint(9, 6);
crack.AddLineToPoint(12.5, 8);
crack.AddLineToPoint(10.5, 11.5);
gc->SetPen(wxPen(dark, 1.4));
gc->StrokePath(crack);
break;
}
case 3: { // otter: upright tapered body + head + small ears + thick tail
wxGraphicsPath tail = gc->CreatePath(); // thick tapering tail curving right
tail.MoveToPoint(13, 17);
tail.AddCurveToPoint(19, 16, 21, 20, 19, 21);
tail.AddCurveToPoint(17, 21, 15, 20, 12, 19);
tail.CloseSubpath();
gc->FillPath(tail);
gc->DrawEllipse(6, 8, 10, 13); // body (tapered upright)
gc->DrawEllipse(7, 3, 8, 8); // head (wide)
gc->DrawEllipse(7, 2.5, 2.6, 2.6); // ear L
gc->DrawEllipse(12.4, 2.5, 2.6, 2.6);// ear R
break;
}
case 4: { // hive (skep): three stacked bands narrowing upward + entrance
gc->DrawRoundedRectangle(6, 2.5, 10, 4, 2);
gc->DrawRoundedRectangle(4, 7, 14, 4, 2);
gc->DrawRoundedRectangle(2.5, 11.5, 17, 5, 2.5);
gc->SetBrush(wxBrush(dark));
gc->SetPen(wxPen(dark, 1.0));
gc->DrawEllipse(9.3, 13, 3.4, 3.6);
break;
}
default: { // 5 lightning bolt
wxGraphicsPath p = gc->CreatePath();
p.MoveToPoint(13, 2);
p.AddLineToPoint(5, 12);
p.AddLineToPoint(10, 12);
p.AddLineToPoint(8, 20);
p.AddLineToPoint(17, 9);
p.AddLineToPoint(11, 9);
p.CloseSubpath();
gc->FillPath(p);
break;
}
}
delete gc;
}
}
return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp);
}
// ---- live theme changes -----------------------------------------------------
// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
+38
View File
@@ -79,6 +79,8 @@ mod notsafe {
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;
pub fn wxbr_reorder_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
pub fn wxbr_reorder_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
pub fn wxbr_menu_new() -> *mut c_void;
pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
pub fn wxbr_menu_append_separator(menu: *mut c_void);
@@ -101,6 +103,7 @@ mod notsafe {
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_kpi_icon(parent: *mut c_void, 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);
@@ -630,6 +633,27 @@ impl Widget {
buf.into_iter().take(n.max(0) as usize).collect()
}
/// A checkable, multi-select, drag-reorderable column list (round 11 #4):
/// like `rearrange_list` but with no up/down buttons -- rows are reordered by
/// dragging, and selected with shift/ctrl-click or a rubber-band drag. Same
/// `[idx | !idx]` order encoding.
pub fn reorder_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
Widget(unsafe {
notsafe::wxbr_reorder_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
})
}
/// Read back the current order from a `reorder_list` (same encoding).
pub fn reorder_get_order(&self) -> Vec<i32> {
let mut buf = vec![0i32; 4096];
let n = unsafe {
notsafe::wxbr_reorder_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
};
buf.into_iter().take(n.max(0) as usize).collect()
}
// ---- popup menu ----
pub fn menu_new() -> Widget {
@@ -744,6 +768,20 @@ impl Widget {
})
}
/// A small drawn KPI icon (static bitmap). kind: 0 rabbit, 1 turtle,
/// 2 broken wine glass, 3 otter, 4 hive, 5 lightning bolt (round 11 #15).
pub fn kpi_icon(parent: Widget, kind: i32, color: (u8, u8, u8)) -> Widget {
Widget(unsafe {
notsafe::wxbr_kpi_icon(
parent.0,
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) }