From e593548746aada615c541091d82cc71fe223be25 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 18 Sep 2026 18:03:47 -0600 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh --- crates/alkane-gui/src/ui.rs | 6 +- .../wx-rs/patches/0002-widget-bridge-rs.patch | 25 ++++- .../patches/0003-widget-bridge-cpp.patch | 106 +++++++++++++++++- .../cpp_src/widgets_bridge.cpp | 104 +++++++++++++++++ .../wx-rs/wx-rs-0.2.0-patched/src/widgets.rs | 23 ++++ 5 files changed, 259 insertions(+), 5 deletions(-) diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 8d712dbe..88296c78 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -2374,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 @@ -2389,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"); @@ -2412,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 = vec![Column::Ip]; let mut visible: HashSet = HashSet::from([Column::Ip]); for entry in order { diff --git a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch index ce15aa75..1df8b895 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,777 @@ +@@ -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); @@ -644,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 = 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 { ++ 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 { diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index c1297279..a47a7d11 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,1379 @@ +@@ -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 +#include +#include ++#include +#include +#include +#include @@ -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 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 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 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 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(); } 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 d2295850..ff5e6455 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 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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 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 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 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 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(); } 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 c791e9fe..d0871d84 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 @@ -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); @@ -631,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 = 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 { + 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 {