Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc9f847689 | ||
|
|
71cdf2d988 |
+100
-19
@@ -58,6 +58,12 @@ const ID_FLASH_CANCEL: i32 = 745;
|
||||
const ID_CREDS_SAVE: i32 = 746;
|
||||
const ID_CREDS_CLEAR: i32 = 747;
|
||||
const ID_CREDS_CANCEL: i32 = 748;
|
||||
// Column-header right-click menu (Excel-style).
|
||||
const ID_HDR_SORT_ASC: i32 = 760;
|
||||
const ID_HDR_SORT_DESC: i32 = 761;
|
||||
const ID_HDR_HIDE: i32 = 762;
|
||||
const ID_HDR_AUTOSIZE: i32 = 763;
|
||||
const ID_HDR_COLUMNS: i32 = 764;
|
||||
// Ticks (~seconds) to keep an action's result on the status bar before the
|
||||
// idle/countdown status takes over again.
|
||||
const ACTION_RESULT_TICKS: u8 = 8;
|
||||
@@ -82,6 +88,8 @@ struct Palette {
|
||||
amber: (u8, u8, u8),
|
||||
red: (u8, u8, u8),
|
||||
accent: (u8, u8, u8),
|
||||
/// Odd-row (zebra) background: a subtle tint of the window colour.
|
||||
zebra: (u8, u8, u8),
|
||||
}
|
||||
|
||||
fn luminance(c: (u8, u8, u8)) -> f32 {
|
||||
@@ -236,14 +244,6 @@ fn status_kind_color(pal: &Palette, status: &str) -> (u8, u8, u8) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A miner row's text colour, by status: green = hashing, amber = slow, blue =
|
||||
/// paused, red = not hashing. This both conveys status and separates rows
|
||||
/// visually (GTK's native zebra/alt-row support is unreliable and fights
|
||||
/// selection).
|
||||
fn status_color(pal: &Palette, r: &MinerRow) -> (u8, u8, u8) {
|
||||
status_kind_color(pal, r.status())
|
||||
}
|
||||
|
||||
fn palette() -> Palette {
|
||||
let win = wx_rs::system_color(0); // window background
|
||||
let text = wx_rs::system_color(1); // window text
|
||||
@@ -258,6 +258,9 @@ fn palette() -> Palette {
|
||||
amber: if dark { (245, 190, 66) } else { (176, 120, 10) },
|
||||
red: if dark { (245, 110, 100) } else { (198, 55, 45) },
|
||||
accent: if dark { (108, 168, 250) } else { (40, 100, 170) },
|
||||
// Subtle zebra tint of the window: slightly lighter in dark mode, a
|
||||
// touch darker than the light window.
|
||||
zebra: if dark { nudge(win, 12) } else { nudge(win, -10) },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +330,9 @@ pub struct App {
|
||||
// start while it runs, and it will not start while anything else is running,
|
||||
// so no two network operations ever race the same miner mid-upload.
|
||||
flashing: bool,
|
||||
// The column a header right-click menu targets (remembered across the menu's
|
||||
// nested event loop until an item is chosen).
|
||||
header_menu_col: Option<Column>,
|
||||
// The "Set scan credentials..." dialog.
|
||||
creds_dialog: Widget,
|
||||
creds_user_input: Widget,
|
||||
@@ -372,8 +378,9 @@ pub fn build(frame: Widget) -> App {
|
||||
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);
|
||||
// Uniform size so every KPI box is identical regardless of its content.
|
||||
card.set_min_size(128, 62);
|
||||
// Uniform size so every KPI box is identical regardless of its content
|
||||
// (wide enough for the largest value, e.g. "685 TH/s" / "21.3 kW").
|
||||
card.set_min_size(150, 62);
|
||||
let cs = Widget::box_sizer(true);
|
||||
let value = Widget::static_text(card, "0");
|
||||
value.set_font_size(19);
|
||||
@@ -511,6 +518,7 @@ pub fn build(frame: Widget) -> App {
|
||||
flash_confirm_input: frame,
|
||||
pending_flash: None,
|
||||
flashing: false,
|
||||
header_menu_col: None,
|
||||
creds_dialog: frame,
|
||||
creds_user_input: frame,
|
||||
creds_pass_input: frame,
|
||||
@@ -550,6 +558,9 @@ impl App {
|
||||
t.destroy();
|
||||
}
|
||||
let t = Widget::dvlc(self.table_parent);
|
||||
// Zebra striping (theme-aware) for row separation now that rows are no
|
||||
// longer tinted by status.
|
||||
t.dvlc_set_zebra(Some(self.pal.zebra));
|
||||
// Creation order == display order. IP is the fixed first column (not
|
||||
// reorderable); the rest are reorderable. The active sort column carries
|
||||
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
|
||||
@@ -563,7 +574,7 @@ impl App {
|
||||
Some((sc, false)) if sc == c => title.push_str(" v"),
|
||||
_ => {}
|
||||
}
|
||||
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error) {
|
||||
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error | Column::Status) {
|
||||
// These columns show two-tone / multi-tone text (actual vs.
|
||||
// expected, or one colour per fan) via a custom renderer that
|
||||
// parses the segment-encoded cell value fill_rows writes.
|
||||
@@ -583,6 +594,9 @@ impl App {
|
||||
|
||||
pub fn fill_rows(&mut self) {
|
||||
let Some(t) = self.table else { return };
|
||||
// Hold the scroll position across the full clear+refill so the table
|
||||
// doesn't jump back to the top as new rows stream in during a scan.
|
||||
let top = t.dvlc_get_top_row();
|
||||
t.dvlc_clear();
|
||||
self.view_idx = self.view.view(&self.rows);
|
||||
let cols = self.view.display_columns();
|
||||
@@ -592,13 +606,12 @@ impl App {
|
||||
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
|
||||
t.dvlc_append_row(&refs);
|
||||
}
|
||||
// Colour each row's text by status (also separates rows visually).
|
||||
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
||||
t.dvlc_set_row_color(disp, Some(status_color(&self.pal, &self.rows[ri])));
|
||||
}
|
||||
// Overwrite the combined actual/expected + cooling-fan cells with
|
||||
// segment-encoded coloured text (the custom renderer these columns use
|
||||
// parses it back out; see encode_combined_cell/encode_cooling_cell).
|
||||
// Rows are NOT tinted by status any more: every cell is the default text
|
||||
// colour except the conditionally-formatted columns below (the Status
|
||||
// column carries the status colour itself). Zebra striping + gridlines
|
||||
// (set at table build) separate rows instead.
|
||||
// Overwrite the conditionally-coloured cells with segment-encoded text
|
||||
// (the custom renderer these columns use parses it back out).
|
||||
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
||||
let r = &self.rows[ri];
|
||||
for (ci, c) in cols.iter().enumerate() {
|
||||
@@ -651,11 +664,19 @@ impl App {
|
||||
let color = (!r.errors.is_empty()).then_some(self.pal.red);
|
||||
encode_flag_cell(&c.cell(r), color)
|
||||
}
|
||||
Column::Status => {
|
||||
// Status keeps its status colour on its own cell (the
|
||||
// row is no longer tinted wholesale).
|
||||
encode_flag_cell(&c.cell(r), Some(status_kind_color(&self.pal, r.status())))
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
t.dvlc_set_cell(disp, ci, &encoded);
|
||||
}
|
||||
}
|
||||
if let Some(row) = top {
|
||||
t.dvlc_ensure_visible(row.min(self.view_idx.len().saturating_sub(1)));
|
||||
}
|
||||
// Re-apply the selection (a refresh clears the control's selection).
|
||||
let sel: Vec<usize> = self
|
||||
.view_idx
|
||||
@@ -694,6 +715,9 @@ impl App {
|
||||
caption.set_fg(self.pal.label.0, self.pal.label.1, self.pal.label.2);
|
||||
}
|
||||
self.highlight_kpi_filter();
|
||||
if let Some(t) = self.table {
|
||||
t.dvlc_set_zebra(Some(self.pal.zebra));
|
||||
}
|
||||
self.fill_rows(); // re-colour rows with the new palette
|
||||
self.table_parent.layout();
|
||||
}
|
||||
@@ -864,6 +888,9 @@ impl App {
|
||||
/// actions (power limit / tuning %) return a prompt dialog to show modally.
|
||||
fn on_menu_item(&mut self, id: i32) -> Option<Widget> {
|
||||
match id {
|
||||
ID_HDR_SORT_ASC | ID_HDR_SORT_DESC | ID_HDR_HIDE | ID_HDR_AUTOSIZE | ID_HDR_COLUMNS => {
|
||||
return self.on_header_menu(id)
|
||||
}
|
||||
ID_CTX_OPEN => {
|
||||
for ip in self.selected_ip_list() {
|
||||
wx_rs::launch_browser(&format!("http://{ip}"));
|
||||
@@ -1458,6 +1485,58 @@ impl App {
|
||||
self.fill_rows();
|
||||
}
|
||||
|
||||
/// Right-click on a column header: Excel-style per-column menu (sort, hide,
|
||||
/// auto-size, and open the full column picker).
|
||||
fn header_context_menu(&mut self, creation_idx: usize) {
|
||||
let Some(t) = self.table else { return };
|
||||
let cols = self.view.display_columns();
|
||||
let Some(&col) = cols.get(creation_idx) else { return };
|
||||
self.header_menu_col = Some(col);
|
||||
let menu = Widget::menu_new();
|
||||
menu.menu_append(ID_HDR_SORT_ASC, &format!("Sort {} ascending", col.title()));
|
||||
menu.menu_append(ID_HDR_SORT_DESC, &format!("Sort {} descending", col.title()));
|
||||
menu.menu_append_separator();
|
||||
menu.menu_append(ID_HDR_AUTOSIZE, "Auto-size this column");
|
||||
// The fixed IP column can't be hidden.
|
||||
if !self.view.is_fixed(col) {
|
||||
menu.menu_append(ID_HDR_HIDE, &format!("Hide {}", col.title()));
|
||||
}
|
||||
menu.menu_append_separator();
|
||||
menu.menu_append(ID_HDR_COLUMNS, "Columns...");
|
||||
self.pending_popup = Some((t, menu));
|
||||
}
|
||||
|
||||
/// Apply a header-menu action to the remembered column.
|
||||
fn on_header_menu(&mut self, id: i32) -> Option<Widget> {
|
||||
let Some(col) = self.header_menu_col else { return None };
|
||||
match id {
|
||||
ID_HDR_SORT_ASC => {
|
||||
self.view.sort = Some((col, true));
|
||||
self.update_headers();
|
||||
self.fill_rows();
|
||||
}
|
||||
ID_HDR_SORT_DESC => {
|
||||
self.view.sort = Some((col, false));
|
||||
self.update_headers();
|
||||
self.fill_rows();
|
||||
}
|
||||
ID_HDR_HIDE if !self.view.is_fixed(col) => {
|
||||
self.view.visible.remove(&col);
|
||||
self.rebuild_table();
|
||||
}
|
||||
ID_HDR_AUTOSIZE => {
|
||||
if let (Some(t), Some(pos)) =
|
||||
(self.table, self.view.display_columns().iter().position(|c| *c == col))
|
||||
{
|
||||
t.dvlc_autosize_col(pos);
|
||||
}
|
||||
}
|
||||
ID_HDR_COLUMNS => return Some(self.build_columns_dialog()),
|
||||
_ => {}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Refresh each column header's ASCII sort marker ("^" asc, "v" desc) in
|
||||
/// place, without recreating the table.
|
||||
fn update_headers(&self) {
|
||||
@@ -2007,6 +2086,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
WxEventKind::DvlcHeaderClick => self.header_click(ev.p1 as usize),
|
||||
WxEventKind::DvlcHeaderRightClick => self.header_context_menu(ev.p1 as usize),
|
||||
WxEventKind::DvlcSelectionChanged => self.on_selection_changed(),
|
||||
WxEventKind::DvlcActivated => self.activate_row(ev.p1 as usize),
|
||||
WxEventKind::DvlcReordered => self.column_reordered(),
|
||||
@@ -2075,7 +2155,7 @@ impl App {
|
||||
for (j, c) in cols.iter().enumerate() {
|
||||
let want = c.cell(r);
|
||||
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
|
||||
let got = if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error) {
|
||||
let got = if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error | Column::Status) {
|
||||
decode_segments_plain(&raw)
|
||||
} else {
|
||||
raw
|
||||
@@ -2212,6 +2292,7 @@ mod tests {
|
||||
amber: (255, 128, 0),
|
||||
red: (255, 0, 0),
|
||||
accent: (0, 0, 255),
|
||||
zebra: (245, 245, 245),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
-1
@@ -10,7 +10,7 @@
|
||||
+pub use widgets::*;
|
||||
--- a/src/widgets.rs
|
||||
+++ b/src/widgets.rs
|
||||
@@ -0,0 +1,688 @@
|
||||
@@ -0,0 +1,720 @@
|
||||
+// 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).
|
||||
@@ -73,6 +73,7 @@
|
||||
+ pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
|
||||
+ 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_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;
|
||||
@@ -82,6 +83,9 @@
|
||||
+ pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
||||
+ pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||
+ pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
|
||||
+ pub fn wxbr_dvlc_set_zebra(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||
+ pub fn wxbr_dvlc_get_top_row(win: *mut c_void) -> c_int;
|
||||
+ pub fn wxbr_dvlc_ensure_visible(win: *mut c_void, row: usize);
|
||||
+ 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;
|
||||
@@ -146,6 +150,7 @@
|
||||
+ ChoiceChanged,
|
||||
+ SysColour,
|
||||
+ Deferred,
|
||||
+ DvlcHeaderRightClick,
|
||||
+}
|
||||
+
|
||||
+impl WxEventKind {
|
||||
@@ -164,6 +169,7 @@
|
||||
+ 12 => WxEventKind::ChoiceChanged,
|
||||
+ 13 => WxEventKind::SysColour,
|
||||
+ 14 => WxEventKind::Deferred,
|
||||
+ 15 => WxEventKind::DvlcHeaderRightClick,
|
||||
+ _ => return None,
|
||||
+ })
|
||||
+ }
|
||||
@@ -505,6 +511,11 @@
|
||||
+ unsafe { notsafe::wxbr_dvlc_col_count(self.0).max(0) as usize }
|
||||
+ }
|
||||
+
|
||||
+ /// Auto-size the column at display position `pos` to fit its content.
|
||||
+ pub fn dvlc_autosize_col(&self, pos: usize) {
|
||||
+ unsafe { notsafe::wxbr_dvlc_autosize_col(self.0, pos as c_int) }
|
||||
+ }
|
||||
+
|
||||
+ /// Model column index shown at display position `pos` (after drag reorder).
|
||||
+ pub fn dvlc_col_at_pos(&self, pos: usize) -> Option<usize> {
|
||||
+ let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };
|
||||
@@ -548,6 +559,27 @@
|
||||
+ unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
||||
+ }
|
||||
+
|
||||
+ /// Set the alternating-row (zebra) background colour applied to odd rows.
|
||||
+ /// Pass `None` to turn zebra striping off.
|
||||
+ pub fn dvlc_set_zebra(&self, color: Option<(u8, u8, u8)>) {
|
||||
+ let (r, g, b) = match color {
|
||||
+ Some((r, g, b)) => (r as c_int, g as c_int, b as c_int),
|
||||
+ None => (-1, -1, -1),
|
||||
+ };
|
||||
+ unsafe { notsafe::wxbr_dvlc_set_zebra(self.0, r, g, b) }
|
||||
+ }
|
||||
+
|
||||
+ /// The model-row index of the top (first visible) row, or `None` if empty.
|
||||
+ pub fn dvlc_get_top_row(&self) -> Option<usize> {
|
||||
+ let r = unsafe { notsafe::wxbr_dvlc_get_top_row(self.0) };
|
||||
+ (r >= 0).then_some(r as usize)
|
||||
+ }
|
||||
+
|
||||
+ /// Scroll so `row` is visible (used to restore scroll position after a refill).
|
||||
+ pub fn dvlc_ensure_visible(&self, row: usize) {
|
||||
+ unsafe { notsafe::wxbr_dvlc_ensure_visible(self.0, row) }
|
||||
+ }
|
||||
+
|
||||
+ // ---- rearrangeable check-list ----
|
||||
+
|
||||
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||
|
||||
+106
-9
@@ -1,6 +1,6 @@
|
||||
--- a/cpp_src/widgets_bridge.cpp
|
||||
+++ b/cpp_src/widgets_bridge.cpp
|
||||
@@ -0,0 +1,892 @@
|
||||
@@ -0,0 +1,989 @@
|
||||
+// 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).
|
||||
@@ -34,11 +34,15 @@
|
||||
+#include <wx/filedlg.h>
|
||||
+#include <cstring>
|
||||
+#include <cstdio>
|
||||
+#include <map>
|
||||
+#include <vector>
|
||||
+
|
||||
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
||||
+static WxWidgetEventFn g_widget_event = nullptr;
|
||||
+
|
||||
+// Anchor row per data-view control for rubber-band (click-drag) range select.
|
||||
+static std::map<wxDataViewCtrl*, int> g_drag_anchor;
|
||||
+
|
||||
+// Event kinds (must match Rust WxEventKind in src/widgets.rs)
|
||||
+enum WxWidgetEventKind {
|
||||
+ WxEV_BUTTON_CLICKED = 1,
|
||||
@@ -54,23 +58,32 @@
|
||||
+ WxEV_CHOICE_CHANGED = 12,
|
||||
+ WxEV_SYS_COLOUR = 13,
|
||||
+ WxEV_DEFERRED = 14,
|
||||
+ WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
|
||||
+};
|
||||
+
|
||||
+// A list store that carries an optional per-row foreground colour, surfaced to
|
||||
+// the native control via GetAttrByRow. This is how the miner table paints each
|
||||
+// row's text by status and separates rows on GTK (where SetAlternateRowColour
|
||||
+// and :nth-child CSS are unreliable and fight the selection highlight).
|
||||
+// A list store that carries an optional per-row foreground colour plus an
|
||||
+// alternating-row (zebra) background, surfaced to the native control via
|
||||
+// GetAttrByRow. The zebra background is set on odd rows only; because it is a
|
||||
+// BACKGROUND attr (not a foreground one), it does not affect the SegmentRenderer
|
||||
+// "no explicit colour -> default text colour" path, and the native selection
|
||||
+// highlight still paints over it for selected rows.
|
||||
+class AttrListStore : public wxDataViewListStore {
|
||||
+ public:
|
||||
+ std::vector<wxColour> row_fg;
|
||||
+ wxColour zebra; // odd-row background; unset (=off) unless the app sets it
|
||||
+ bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||
+ wxDataViewItemAttr& attr) const override {
|
||||
+ (void)col;
|
||||
+ bool set = false;
|
||||
+ if (row < row_fg.size() && row_fg[row].IsOk()) {
|
||||
+ attr.SetColour(row_fg[row]);
|
||||
+ return true;
|
||||
+ set = true;
|
||||
+ }
|
||||
+ return false;
|
||||
+ if (zebra.IsOk() && (row % 2 == 1)) {
|
||||
+ attr.SetBackgroundColour(zebra);
|
||||
+ set = true;
|
||||
+ }
|
||||
+ return set;
|
||||
+ }
|
||||
+};
|
||||
+
|
||||
@@ -191,7 +204,11 @@
|
||||
+// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
||||
+// set_sizer_on calls as wxbr_box_sizer's result.
|
||||
+void* wxbr_wrap_sizer(int vertical) {
|
||||
+ return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL);
|
||||
+ // wxREMOVE_LEADING_SPACES only: drop the default wxEXTEND_LAST_ON_EACH_LINE so
|
||||
+ // the last item on a line is NOT stretched to fill the row (keeps fixed-size
|
||||
+ // items -- e.g. the uniform KPI cards -- the same size).
|
||||
+ return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL,
|
||||
+ wxREMOVE_LEADING_SPACES);
|
||||
+}
|
||||
+
|
||||
+// flag bits (must match Rust sizer_flags):
|
||||
@@ -442,7 +459,8 @@
|
||||
+ // status while the native selection highlight still shows through.
|
||||
+ wxDataViewCtrl* dv =
|
||||
+ new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
+ wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
|
||||
+ wxSize(-1, -1),
|
||||
+ wxDV_ROW_LINES | wxDV_VERT_RULES | wxDV_MULTIPLE);
|
||||
+ AttrListStore* store = new AttrListStore();
|
||||
+ dv->AssociateModel(store);
|
||||
+ store->DecRef(); // the control owns a reference now
|
||||
@@ -465,9 +483,57 @@
|
||||
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
|
||||
+ });
|
||||
+ // Right-click on a column header: Excel-style per-column menu (hide/sort/...).
|
||||
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, [](wxDataViewEvent& e) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_RIGHT_CLICK, (long)e.GetColumn(), 0);
|
||||
+ });
|
||||
+ dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
|
||||
+ });
|
||||
+ // Rubber-band (click-drag) range selection: wxDataViewCtrl has none natively
|
||||
+ // (only ctrl/shift-click), so track it here. LEFT_DOWN records the anchor row
|
||||
+ // (and lets the native handler select it); dragging with the button down
|
||||
+ // extends the selection to the row under the cursor.
|
||||
+ dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
|
||||
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||
+ if (!dv) { e.Skip(); return; }
|
||||
+ // Leave modifier-clicks to the native ctrl/shift multi-select behaviour.
|
||||
+ if (e.ControlDown() || e.ShiftDown()) { g_drag_anchor.erase(dv); e.Skip(); return; }
|
||||
+ wxDataViewItem item;
|
||||
+ wxDataViewColumn* col = nullptr;
|
||||
+ dv->HitTest(e.GetPosition(), item, col);
|
||||
+ if (item.IsOk()) {
|
||||
+ g_drag_anchor[dv] =
|
||||
+ (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||
+ } else {
|
||||
+ g_drag_anchor.erase(dv);
|
||||
+ }
|
||||
+ e.Skip(); // let the native handler select the anchor row
|
||||
+ });
|
||||
+ dv->Bind(wxEVT_MOTION, [](wxMouseEvent& e) {
|
||||
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||
+ if (!dv || !e.LeftIsDown()) { e.Skip(); return; }
|
||||
+ auto it = g_drag_anchor.find(dv);
|
||||
+ if (it == g_drag_anchor.end()) { e.Skip(); return; }
|
||||
+ wxDataViewItem item;
|
||||
+ wxDataViewColumn* col = nullptr;
|
||||
+ dv->HitTest(e.GetPosition(), item, col);
|
||||
+ if (!item.IsOk()) { e.Skip(); return; }
|
||||
+ wxDataViewIndexListModel* model = (wxDataViewIndexListModel*)dv->GetModel();
|
||||
+ int cur = (int)model->GetRow(item);
|
||||
+ int lo = it->second < cur ? it->second : cur;
|
||||
+ int hi = it->second < cur ? cur : it->second;
|
||||
+ dv->UnselectAll();
|
||||
+ for (int r = lo; r <= hi; ++r) dv->Select(model->GetItem((unsigned)r));
|
||||
+ // Selecting programmatically does not emit SELECTION_CHANGED, so notify.
|
||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||
+ e.Skip();
|
||||
+ });
|
||||
+ dv->Bind(wxEVT_LEFT_UP, [](wxMouseEvent& e) {
|
||||
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||
+ if (dv) g_drag_anchor.erase(dv);
|
||||
+ e.Skip();
|
||||
+ });
|
||||
+ // Row activation (double-click / Enter): report the row + column so the app
|
||||
+ // can, e.g., open the miner's IP in a browser.
|
||||
+ dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
|
||||
@@ -549,6 +615,29 @@
|
||||
+ store->RowChanged(row);
|
||||
+}
|
||||
+
|
||||
+// Set (or clear, when r<0) the alternating-row (zebra) background colour. The
|
||||
+// app passes a theme-aware colour; odd rows get it (see AttrListStore).
|
||||
+void wxbr_dvlc_set_zebra(void* win, int r, int g, int b) {
|
||||
+ dvlc_store(win)->zebra = (r < 0) ? wxColour() : wxColour(r, g, b);
|
||||
+}
|
||||
+
|
||||
+// The model-row index of the first (top) visible row, or -1 if none. Used to
|
||||
+// hold the scroll position across a full clear+refill during a live scan.
|
||||
+int wxbr_dvlc_get_top_row(void* win) {
|
||||
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||
+ wxDataViewItem item = dv->GetTopItem();
|
||||
+ if (!item.IsOk()) return -1;
|
||||
+ return (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||
+}
|
||||
+
|
||||
+// Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the
|
||||
+// scroll position after a refill). Out-of-range rows are ignored.
|
||||
+void wxbr_dvlc_ensure_visible(void* win, unsigned row) {
|
||||
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||
+ wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row);
|
||||
+ if (item.IsOk()) dv->EnsureVisible(item);
|
||||
+}
|
||||
+
|
||||
+int wxbr_dvlc_row_count(void* win) {
|
||||
+ return (int)dvlc_store(win)->GetItemCount();
|
||||
+}
|
||||
@@ -579,6 +668,14 @@
|
||||
+ return (int)((wxDataViewCtrl*)win)->GetColumnCount();
|
||||
+}
|
||||
+
|
||||
+// Auto-size a column (by display position) to fit its content + header.
|
||||
+void wxbr_dvlc_autosize_col(void* win, int pos) {
|
||||
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||
+ if (pos < 0 || (unsigned)pos >= dv->GetColumnCount()) return;
|
||||
+ wxDataViewColumn* c = dv->GetColumn((unsigned)pos);
|
||||
+ if (c) c->SetWidth(wxCOL_WIDTH_AUTOSIZE);
|
||||
+}
|
||||
+
|
||||
+// 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) {
|
||||
|
||||
+105
-8
@@ -31,11 +31,15 @@
|
||||
#include <wx/filedlg.h>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
||||
static WxWidgetEventFn g_widget_event = nullptr;
|
||||
|
||||
// Anchor row per data-view control for rubber-band (click-drag) range select.
|
||||
static std::map<wxDataViewCtrl*, int> g_drag_anchor;
|
||||
|
||||
// Event kinds (must match Rust WxEventKind in src/widgets.rs)
|
||||
enum WxWidgetEventKind {
|
||||
WxEV_BUTTON_CLICKED = 1,
|
||||
@@ -51,23 +55,32 @@ enum WxWidgetEventKind {
|
||||
WxEV_CHOICE_CHANGED = 12,
|
||||
WxEV_SYS_COLOUR = 13,
|
||||
WxEV_DEFERRED = 14,
|
||||
WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
|
||||
};
|
||||
|
||||
// A list store that carries an optional per-row foreground colour, surfaced to
|
||||
// the native control via GetAttrByRow. This is how the miner table paints each
|
||||
// row's text by status and separates rows on GTK (where SetAlternateRowColour
|
||||
// and :nth-child CSS are unreliable and fight the selection highlight).
|
||||
// A list store that carries an optional per-row foreground colour plus an
|
||||
// alternating-row (zebra) background, surfaced to the native control via
|
||||
// GetAttrByRow. The zebra background is set on odd rows only; because it is a
|
||||
// BACKGROUND attr (not a foreground one), it does not affect the SegmentRenderer
|
||||
// "no explicit colour -> default text colour" path, and the native selection
|
||||
// highlight still paints over it for selected rows.
|
||||
class AttrListStore : public wxDataViewListStore {
|
||||
public:
|
||||
std::vector<wxColour> row_fg;
|
||||
wxColour zebra; // odd-row background; unset (=off) unless the app sets it
|
||||
bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||
wxDataViewItemAttr& attr) const override {
|
||||
(void)col;
|
||||
bool set = false;
|
||||
if (row < row_fg.size() && row_fg[row].IsOk()) {
|
||||
attr.SetColour(row_fg[row]);
|
||||
return true;
|
||||
set = true;
|
||||
}
|
||||
return false;
|
||||
if (zebra.IsOk() && (row % 2 == 1)) {
|
||||
attr.SetBackgroundColour(zebra);
|
||||
set = true;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -188,7 +201,11 @@ void* wxbr_box_sizer(int vertical) {
|
||||
// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
||||
// set_sizer_on calls as wxbr_box_sizer's result.
|
||||
void* wxbr_wrap_sizer(int vertical) {
|
||||
return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL);
|
||||
// wxREMOVE_LEADING_SPACES only: drop the default wxEXTEND_LAST_ON_EACH_LINE so
|
||||
// the last item on a line is NOT stretched to fill the row (keeps fixed-size
|
||||
// items -- e.g. the uniform KPI cards -- the same size).
|
||||
return (void*)new wxWrapSizer(vertical ? wxVERTICAL : wxHORIZONTAL,
|
||||
wxREMOVE_LEADING_SPACES);
|
||||
}
|
||||
|
||||
// flag bits (must match Rust sizer_flags):
|
||||
@@ -439,7 +456,8 @@ void* wxbr_dvlc(void* parent) {
|
||||
// status while the native selection highlight still shows through.
|
||||
wxDataViewCtrl* dv =
|
||||
new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
|
||||
wxSize(-1, -1),
|
||||
wxDV_ROW_LINES | wxDV_VERT_RULES | wxDV_MULTIPLE);
|
||||
AttrListStore* store = new AttrListStore();
|
||||
dv->AssociateModel(store);
|
||||
store->DecRef(); // the control owns a reference now
|
||||
@@ -462,9 +480,57 @@ void* wxbr_dvlc(void* parent) {
|
||||
dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, [](wxDataViewEvent& e) {
|
||||
if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_CLICK, (long)e.GetColumn(), 0);
|
||||
});
|
||||
// Right-click on a column header: Excel-style per-column menu (hide/sort/...).
|
||||
dv->Bind(wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, [](wxDataViewEvent& e) {
|
||||
if (g_widget_event) g_widget_event(WxEV_DVLC_HEADER_RIGHT_CLICK, (long)e.GetColumn(), 0);
|
||||
});
|
||||
dv->Bind(wxEVT_DATAVIEW_COLUMN_REORDERED, [](wxDataViewEvent&) {
|
||||
if (g_widget_event) g_widget_event(WxEV_DVLC_REORDERED, 0, 0);
|
||||
});
|
||||
// Rubber-band (click-drag) range selection: wxDataViewCtrl has none natively
|
||||
// (only ctrl/shift-click), so track it here. LEFT_DOWN records the anchor row
|
||||
// (and lets the native handler select it); dragging with the button down
|
||||
// extends the selection to the row under the cursor.
|
||||
dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
|
||||
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||
if (!dv) { e.Skip(); return; }
|
||||
// Leave modifier-clicks to the native ctrl/shift multi-select behaviour.
|
||||
if (e.ControlDown() || e.ShiftDown()) { g_drag_anchor.erase(dv); e.Skip(); return; }
|
||||
wxDataViewItem item;
|
||||
wxDataViewColumn* col = nullptr;
|
||||
dv->HitTest(e.GetPosition(), item, col);
|
||||
if (item.IsOk()) {
|
||||
g_drag_anchor[dv] =
|
||||
(int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||
} else {
|
||||
g_drag_anchor.erase(dv);
|
||||
}
|
||||
e.Skip(); // let the native handler select the anchor row
|
||||
});
|
||||
dv->Bind(wxEVT_MOTION, [](wxMouseEvent& e) {
|
||||
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||
if (!dv || !e.LeftIsDown()) { e.Skip(); return; }
|
||||
auto it = g_drag_anchor.find(dv);
|
||||
if (it == g_drag_anchor.end()) { e.Skip(); return; }
|
||||
wxDataViewItem item;
|
||||
wxDataViewColumn* col = nullptr;
|
||||
dv->HitTest(e.GetPosition(), item, col);
|
||||
if (!item.IsOk()) { e.Skip(); return; }
|
||||
wxDataViewIndexListModel* model = (wxDataViewIndexListModel*)dv->GetModel();
|
||||
int cur = (int)model->GetRow(item);
|
||||
int lo = it->second < cur ? it->second : cur;
|
||||
int hi = it->second < cur ? cur : it->second;
|
||||
dv->UnselectAll();
|
||||
for (int r = lo; r <= hi; ++r) dv->Select(model->GetItem((unsigned)r));
|
||||
// Selecting programmatically does not emit SELECTION_CHANGED, so notify.
|
||||
if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||
e.Skip();
|
||||
});
|
||||
dv->Bind(wxEVT_LEFT_UP, [](wxMouseEvent& e) {
|
||||
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
|
||||
if (dv) g_drag_anchor.erase(dv);
|
||||
e.Skip();
|
||||
});
|
||||
// Row activation (double-click / Enter): report the row + column so the app
|
||||
// can, e.g., open the miner's IP in a browser.
|
||||
dv->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, [](wxDataViewEvent& e) {
|
||||
@@ -546,6 +612,29 @@ void wxbr_dvlc_set_row_color(void* win, unsigned row, int r, int g, int b) {
|
||||
store->RowChanged(row);
|
||||
}
|
||||
|
||||
// Set (or clear, when r<0) the alternating-row (zebra) background colour. The
|
||||
// app passes a theme-aware colour; odd rows get it (see AttrListStore).
|
||||
void wxbr_dvlc_set_zebra(void* win, int r, int g, int b) {
|
||||
dvlc_store(win)->zebra = (r < 0) ? wxColour() : wxColour(r, g, b);
|
||||
}
|
||||
|
||||
// The model-row index of the first (top) visible row, or -1 if none. Used to
|
||||
// hold the scroll position across a full clear+refill during a live scan.
|
||||
int wxbr_dvlc_get_top_row(void* win) {
|
||||
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||
wxDataViewItem item = dv->GetTopItem();
|
||||
if (!item.IsOk()) return -1;
|
||||
return (int)((wxDataViewIndexListModel*)dv->GetModel())->GetRow(item);
|
||||
}
|
||||
|
||||
// Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the
|
||||
// scroll position after a refill). Out-of-range rows are ignored.
|
||||
void wxbr_dvlc_ensure_visible(void* win, unsigned row) {
|
||||
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||
wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row);
|
||||
if (item.IsOk()) dv->EnsureVisible(item);
|
||||
}
|
||||
|
||||
int wxbr_dvlc_row_count(void* win) {
|
||||
return (int)dvlc_store(win)->GetItemCount();
|
||||
}
|
||||
@@ -576,6 +665,14 @@ int wxbr_dvlc_col_count(void* win) {
|
||||
return (int)((wxDataViewCtrl*)win)->GetColumnCount();
|
||||
}
|
||||
|
||||
// Auto-size a column (by display position) to fit its content + header.
|
||||
void wxbr_dvlc_autosize_col(void* win, int pos) {
|
||||
wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||
if (pos < 0 || (unsigned)pos >= dv->GetColumnCount()) return;
|
||||
wxDataViewColumn* c = dv->GetColumn((unsigned)pos);
|
||||
if (c) c->SetWidth(wxCOL_WIDTH_AUTOSIZE);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
@@ -60,6 +60,7 @@ mod notsafe {
|
||||
pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
|
||||
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_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;
|
||||
@@ -69,6 +70,9 @@ mod notsafe {
|
||||
pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
||||
pub fn wxbr_dvlc_set_alt_row_color(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||
pub fn wxbr_dvlc_set_row_color(win: *mut c_void, row: usize, r: c_int, g: c_int, b: c_int);
|
||||
pub fn wxbr_dvlc_set_zebra(win: *mut c_void, r: c_int, g: c_int, b: c_int);
|
||||
pub fn wxbr_dvlc_get_top_row(win: *mut c_void) -> c_int;
|
||||
pub fn wxbr_dvlc_ensure_visible(win: *mut c_void, row: usize);
|
||||
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;
|
||||
@@ -133,6 +137,7 @@ pub enum WxEventKind {
|
||||
ChoiceChanged,
|
||||
SysColour,
|
||||
Deferred,
|
||||
DvlcHeaderRightClick,
|
||||
}
|
||||
|
||||
impl WxEventKind {
|
||||
@@ -151,6 +156,7 @@ impl WxEventKind {
|
||||
12 => WxEventKind::ChoiceChanged,
|
||||
13 => WxEventKind::SysColour,
|
||||
14 => WxEventKind::Deferred,
|
||||
15 => WxEventKind::DvlcHeaderRightClick,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -492,6 +498,11 @@ impl Widget {
|
||||
unsafe { notsafe::wxbr_dvlc_col_count(self.0).max(0) as usize }
|
||||
}
|
||||
|
||||
/// Auto-size the column at display position `pos` to fit its content.
|
||||
pub fn dvlc_autosize_col(&self, pos: usize) {
|
||||
unsafe { notsafe::wxbr_dvlc_autosize_col(self.0, pos as c_int) }
|
||||
}
|
||||
|
||||
/// Model column index shown at display position `pos` (after drag reorder).
|
||||
pub fn dvlc_col_at_pos(&self, pos: usize) -> Option<usize> {
|
||||
let v = unsafe { notsafe::wxbr_dvlc_col_at_pos(self.0, pos as c_int) };
|
||||
@@ -535,6 +546,27 @@ impl Widget {
|
||||
unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
||||
}
|
||||
|
||||
/// Set the alternating-row (zebra) background colour applied to odd rows.
|
||||
/// Pass `None` to turn zebra striping off.
|
||||
pub fn dvlc_set_zebra(&self, color: Option<(u8, u8, u8)>) {
|
||||
let (r, g, b) = match color {
|
||||
Some((r, g, b)) => (r as c_int, g as c_int, b as c_int),
|
||||
None => (-1, -1, -1),
|
||||
};
|
||||
unsafe { notsafe::wxbr_dvlc_set_zebra(self.0, r, g, b) }
|
||||
}
|
||||
|
||||
/// The model-row index of the top (first visible) row, or `None` if empty.
|
||||
pub fn dvlc_get_top_row(&self) -> Option<usize> {
|
||||
let r = unsafe { notsafe::wxbr_dvlc_get_top_row(self.0) };
|
||||
(r >= 0).then_some(r as usize)
|
||||
}
|
||||
|
||||
/// Scroll so `row` is visible (used to restore scroll position after a refill).
|
||||
pub fn dvlc_ensure_visible(&self, row: usize) {
|
||||
unsafe { notsafe::wxbr_dvlc_ensure_visible(self.0, row) }
|
||||
}
|
||||
|
||||
// ---- rearrangeable check-list ----
|
||||
|
||||
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||
|
||||
Reference in New Issue
Block a user