diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index a1de3118..3e0f9f34 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -632,6 +632,11 @@ pub struct App { kpi_power: Widget, progress: Widget, pub table: Option, + // Whether the columns have had their one-time content-fit autosize applied + // since the table was last (re)built (round 18 #10). Reset on rebuild; set + // the first time fill_rows runs with rows present, so the default widths fit + // their contents (capped) once and manual resizes afterwards are preserved. + columns_autosized: bool, table_parent: Widget, root_sizer: Widget, pub scan: Option, @@ -982,6 +987,7 @@ pub fn build(frame: Widget) -> App { kpi_power, progress, table: None, + columns_autosized: false, table_parent, root_sizer: root, scan: Some(scan::start_scan(ranges.clone(), scan::load_scan_timeout())), @@ -1170,6 +1176,9 @@ impl App { // Re-apply the table zoom so a non-100% zoom survives this rebuild // (round 14 #3); the fresh columns come back at their 100% widths. wx_rs::table_zoom_reapply(); + // Fresh columns come back at their configured default widths; let the + // next fill_rows shrink them to fit their contents (round 18 #10). + self.columns_autosized = false; self.fill_rows(); } @@ -1275,6 +1284,17 @@ impl App { } } } + // Item 10: the first time we have rows to measure after a (re)build, set + // each column's width to the smaller of its content-fit width and its + // configured default (the cap), so columns are no wider than needed. Done + // once per rebuild; the user's later manual resizes are then preserved + // because subsequent fill_rows calls (scan updates) skip this. + if !self.columns_autosized && !self.view_idx.is_empty() { + for (pos, c) in cols.iter().enumerate() { + t.dvlc_autosize_col_capped(pos, c.width()); + } + self.columns_autosized = true; + } if let Some(row) = top { t.dvlc_ensure_visible(row.min(self.view_idx.len().saturating_sub(1))); } 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 804627da..49c8f149 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 @@ -1291,6 +1291,23 @@ void wxbr_dvlc_autosize_col(void* win, int pos) { if (c) c->SetWidth(wxCOL_WIDTH_AUTOSIZE); } +// Size a column to fit its content + header, then clamp to cap_px so the default +// width is min(reasonable cap, content-fit) -- a short column shrinks to its +// content, a long one is capped at the caller's sensible default (round 18 #10). +// A small floor keeps a column from collapsing to nothing. +void wxbr_dvlc_autosize_col_capped(void* win, int pos, int cap_px) { + wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + if (pos < 0 || (unsigned)pos >= dv->GetColumnCount()) return; + wxDataViewColumn* c = dv->GetColumn((unsigned)pos); + if (!c) return; + c->SetWidth(wxCOL_WIDTH_AUTOSIZE); + int w = c->GetWidth(); + const int floor_px = 24; + if (w < floor_px) w = floor_px; + if (cap_px > 0 && w > cap_px) w = cap_px; + c->SetWidth(w); +} + // 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) { 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 a96c3256..7c55fda6 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 @@ -68,6 +68,7 @@ mod notsafe { 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_autosize_col(win: *mut c_void, pos: c_int); + pub fn wxbr_dvlc_autosize_col_capped(win: *mut c_void, pos: c_int, cap_px: 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; @@ -647,6 +648,12 @@ impl Widget { unsafe { notsafe::wxbr_dvlc_autosize_col(self.0, pos as c_int) } } + /// Size the column at display position `pos` to its content, then clamp to + /// `cap_px`: the width becomes min(cap, content-fit) (round 18 #10). + pub fn dvlc_autosize_col_capped(&self, pos: usize, cap_px: i32) { + unsafe { notsafe::wxbr_dvlc_autosize_col_capped(self.0, pos as c_int, cap_px) } + } + /// Model column index shown at display position `pos` (after drag reorder). pub fn dvlc_col_at_pos(&self, pos: usize) -> Option { let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };