GUI round 11 (#2): collapse the two wide KPI cards when the window is too narrow

When the window is narrowed past the width needed to fit all seven KPI cards at
their minimum size, the two wide cards (SHA-256 Hashrate, Est. power) are hidden
so the five miner-count cards fill the row; they return when there is room again.
The five count cards still floor the window's minimum width (unchanged).

Adds a resize event to the wx-rs bridge (WxEV_SIZE -> WxEventKind::Sized, p1 =
client width) and a wxbr_sizer_show helper to hide/restore a sizer child and
reclaim its space. The main panel binds it; App::on_resize toggles the two cards
on a state change only (no per-drag relayout thrash). Bridge + Rust changes
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
This commit is contained in:
2026-09-18 17:39:56 -06:00
co-authored by Claude Opus 4.8
parent fc7c665166
commit 6b4961d7bc
5 changed files with 109 additions and 2 deletions
+18 -1
View File
@@ -10,7 +10,7 @@
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
@@ -0,0 +1,745 @@
@@ -0,0 +1,762 @@
+// 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).
@@ -36,6 +36,8 @@
+ 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_sizer_show(sizer: *mut c_void, win: *mut c_void, show: c_int);
+ pub fn wxbr_bind_size(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;
@@ -154,6 +156,8 @@
+ SysColour,
+ Deferred,
+ DvlcHeaderRightClick,
+ /// Window resized; p1 = new client width, p2 = new client height.
+ Sized,
+}
+
+impl WxEventKind {
@@ -173,6 +177,7 @@
+ 13 => WxEventKind::SysColour,
+ 14 => WxEventKind::Deferred,
+ 15 => WxEventKind::DvlcHeaderRightClick,
+ 16 => WxEventKind::Sized,
+ _ => return None,
+ })
+ }
@@ -321,6 +326,18 @@
+ unsafe { notsafe::wxbr_sizer_detach(self.0, win.0) }
+ }
+
+ /// Show or hide a child window in this sizer (self = a sizer), reclaiming or
+ /// restoring its space on the next `layout()`.
+ pub fn sizer_show(&self, win: Widget, show: bool) {
+ unsafe { notsafe::wxbr_sizer_show(self.0, win.0, show as c_int) }
+ }
+
+ /// Emit `WxEventKind::Sized` (p1 = width, p2 = height) whenever this window
+ /// is resized.
+ pub fn bind_size(&self) {
+ unsafe { notsafe::wxbr_bind_size(self.0) }
+ }
+
+ pub fn fit(&self, win: Widget) {
+ unsafe { notsafe::wxbr_fit(win.0) }
+ }
+19 -1
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,1266 @@
@@ -0,0 +1,1284 @@
+// 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).
@@ -69,6 +69,7 @@
+ WxEV_SYS_COLOUR = 13,
+ WxEV_DEFERRED = 14,
+ WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
+ WxEV_SIZE = 16, // p1 = new client width, p2 = new client height
+};
+
+// A list store that carries an optional per-row foreground colour plus an
@@ -407,6 +408,23 @@
+ ((wxSizer*)sizer)->Detach((wxWindow*)win);
+}
+
+// Show or hide a sizer-managed child window AND reclaim (or restore) its space
+// on the next Layout(). Used to collapse the wide KPI cards when the window is
+// too narrow (round 11 #2).
+void wxbr_sizer_show(void* sizer, void* win, int show) {
+ ((wxSizer*)sizer)->Show((wxWindow*)win, show != 0);
+}
+
+// Emit WxEV_SIZE (p1 = new client width, p2 = height) whenever this window is
+// resized. e.Skip() keeps the normal sizer layout running (round 11 #2).
+void wxbr_bind_size(void* win) {
+ ((wxWindow*)win)->Bind(wxEVT_SIZE, [](wxSizeEvent& e) {
+ if (g_widget_event) g_widget_event(WxEV_SIZE, (long)e.GetSize().GetWidth(),
+ (long)e.GetSize().GetHeight());
+ e.Skip();
+ });
+}
+
+void wxbr_fit(void* win) { ((wxWindow*)win)->Fit(); }
+
+void wxbr_set_min_size(void* win, int w, int h) {
@@ -66,6 +66,7 @@ enum WxWidgetEventKind {
WxEV_SYS_COLOUR = 13,
WxEV_DEFERRED = 14,
WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
WxEV_SIZE = 16, // p1 = new client width, p2 = new client height
};
// A list store that carries an optional per-row foreground colour plus an
@@ -404,6 +405,23 @@ void wxbr_sizer_detach(void* sizer, void* win) {
((wxSizer*)sizer)->Detach((wxWindow*)win);
}
// Show or hide a sizer-managed child window AND reclaim (or restore) its space
// on the next Layout(). Used to collapse the wide KPI cards when the window is
// too narrow (round 11 #2).
void wxbr_sizer_show(void* sizer, void* win, int show) {
((wxSizer*)sizer)->Show((wxWindow*)win, show != 0);
}
// Emit WxEV_SIZE (p1 = new client width, p2 = height) whenever this window is
// resized. e.Skip() keeps the normal sizer layout running (round 11 #2).
void wxbr_bind_size(void* win) {
((wxWindow*)win)->Bind(wxEVT_SIZE, [](wxSizeEvent& e) {
if (g_widget_event) g_widget_event(WxEV_SIZE, (long)e.GetSize().GetWidth(),
(long)e.GetSize().GetHeight());
e.Skip();
});
}
void wxbr_fit(void* win) { ((wxWindow*)win)->Fit(); }
void wxbr_set_min_size(void* win, int w, int h) {
+17
View File
@@ -23,6 +23,8 @@ mod notsafe {
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_sizer_show(sizer: *mut c_void, win: *mut c_void, show: c_int);
pub fn wxbr_bind_size(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;
@@ -141,6 +143,8 @@ pub enum WxEventKind {
SysColour,
Deferred,
DvlcHeaderRightClick,
/// Window resized; p1 = new client width, p2 = new client height.
Sized,
}
impl WxEventKind {
@@ -160,6 +164,7 @@ impl WxEventKind {
13 => WxEventKind::SysColour,
14 => WxEventKind::Deferred,
15 => WxEventKind::DvlcHeaderRightClick,
16 => WxEventKind::Sized,
_ => return None,
})
}
@@ -308,6 +313,18 @@ impl Widget {
unsafe { notsafe::wxbr_sizer_detach(self.0, win.0) }
}
/// Show or hide a child window in this sizer (self = a sizer), reclaiming or
/// restoring its space on the next `layout()`.
pub fn sizer_show(&self, win: Widget, show: bool) {
unsafe { notsafe::wxbr_sizer_show(self.0, win.0, show as c_int) }
}
/// Emit `WxEventKind::Sized` (p1 = width, p2 = height) whenever this window
/// is resized.
pub fn bind_size(&self) {
unsafe { notsafe::wxbr_bind_size(self.0) }
}
pub fn fit(&self, win: Widget) {
unsafe { notsafe::wxbr_fit(win.0) }
}