diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 0a3ab9c5..b63b5583 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -416,6 +416,12 @@ pub struct App { // so both can be repainted when the system light/dark theme changes. pal: Palette, kpi_cards: Vec<(Widget, Widget, Widget, ColorKind)>, + /// The main content panel and the KPI card row sizer, plus whether the two + /// wide KPI cards (Hashrate, Est. power) are currently collapsed because the + /// window is too narrow to fit all seven cards (round 11 #2). + panel: Widget, + kpi_row: Widget, + kpi_collapsed: bool, // The 4 status KPI cards that double as quick-filters: (status text, its // ButtonClicked id, card panel, value text, label text). The three widgets // are all painted for the active-filter highlight (so the whole box tints, @@ -630,6 +636,9 @@ pub fn build(frame: Widget) -> App { let table_parent = panel; root.set_sizer_on(panel); + // Collapse the two wide KPI cards when the window is too narrow to fit all + // seven (round 11 #2): listen for panel resizes. + panel.bind_size(); let frame_sizer = Widget::box_sizer(true); frame_sizer.add(panel, 1, sf::EXPAND, 0); frame_sizer.set_sizer_on(frame); @@ -674,6 +683,9 @@ pub fn build(frame: Widget) -> App { selected_ips: HashSet::new(), pal, kpi_cards, + panel, + kpi_row, + kpi_collapsed: false, kpi_filter_cards, active_kpi_filter: None, pending_popup: None, @@ -761,6 +773,30 @@ impl App { cols } + /// Collapse or restore the two wide KPI cards (Hashrate, Est. power) as the + /// window is resized (round 11 #2). When the panel is too narrow to fit all + /// seven cards at their minimum width, the two wide cards are hidden so the + /// five miner-count cards fill the row; they return when there is room again. + fn on_resize(&mut self, width: i32) { + // Each card is a ~116px min + BORDER_ALL*2 (8px); the row itself is + // inset by the root border. Below the width needed for all seven, drop + // the two wide cards. + const CARD_SLOT: i32 = 116 + 8; + let need_all = CARD_SLOT * 7 + 12; + let want_collapsed = width < need_all; + if want_collapsed == self.kpi_collapsed { + return; + } + self.kpi_collapsed = want_collapsed; + let show = !want_collapsed; + // kpi_cards[5] = Hashrate card, [6] = Est. power card (build order). + let hashrate_card = self.kpi_cards[5].0; + let power_card = self.kpi_cards[6].0; + self.kpi_row.sizer_show(hashrate_card, show); + self.kpi_row.sizer_show(power_card, show); + self.panel.layout(); + } + pub fn rebuild_table(&mut self) { // Detach the old table from the sizer before destroying it, so the // sizer never holds a dangling item, then drop it. @@ -2782,6 +2818,7 @@ impl App { WxEventKind::MenuItem => return self.on_menu_item(ev.p1 as i32), WxEventKind::ChoiceChanged => self.on_choice_changed(ev.p1 as i32, ev.p2 as i32), WxEventKind::SysColour => self.repaint_theme(), + WxEventKind::Sized => self.on_resize(ev.p1 as i32), WxEventKind::Deferred => self.on_deferred(ev.p1 as i32), WxEventKind::TimerTick if ev.p1 as i32 == TIMER_SCAN => self.tick(), _ => {} diff --git a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch index 62c403bd..586a70c3 100644 --- a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch +++ b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch @@ -10,7 +10,7 @@ +pub use widgets::*; --- a/src/widgets.rs +++ b/src/widgets.rs -@@ -0,0 +1,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) } + } diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index 27c77bc9..9e0d95da 100644 --- a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch +++ b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch @@ -1,6 +1,6 @@ --- a/cpp_src/widgets_bridge.cpp +++ b/cpp_src/widgets_bridge.cpp -@@ -0,0 +1,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) { diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp index 5b6d4914..22e3f281 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp @@ -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) { diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs index 625e66cf..8ca0cc8a 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs @@ -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) } }