Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71cdf2d988 |
+31
-17
@@ -82,6 +82,8 @@ struct Palette {
|
|||||||
amber: (u8, u8, u8),
|
amber: (u8, u8, u8),
|
||||||
red: (u8, u8, u8),
|
red: (u8, u8, u8),
|
||||||
accent: (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 {
|
fn luminance(c: (u8, u8, u8)) -> f32 {
|
||||||
@@ -236,14 +238,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 {
|
fn palette() -> Palette {
|
||||||
let win = wx_rs::system_color(0); // window background
|
let win = wx_rs::system_color(0); // window background
|
||||||
let text = wx_rs::system_color(1); // window text
|
let text = wx_rs::system_color(1); // window text
|
||||||
@@ -258,6 +252,9 @@ fn palette() -> Palette {
|
|||||||
amber: if dark { (245, 190, 66) } else { (176, 120, 10) },
|
amber: if dark { (245, 190, 66) } else { (176, 120, 10) },
|
||||||
red: if dark { (245, 110, 100) } else { (198, 55, 45) },
|
red: if dark { (245, 110, 100) } else { (198, 55, 45) },
|
||||||
accent: if dark { (108, 168, 250) } else { (40, 100, 170) },
|
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) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,6 +547,9 @@ impl App {
|
|||||||
t.destroy();
|
t.destroy();
|
||||||
}
|
}
|
||||||
let t = Widget::dvlc(self.table_parent);
|
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
|
// Creation order == display order. IP is the fixed first column (not
|
||||||
// reorderable); the rest are reorderable. The active sort column carries
|
// reorderable); the rest are reorderable. The active sort column carries
|
||||||
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
|
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
|
||||||
@@ -563,7 +563,7 @@ impl App {
|
|||||||
Some((sc, false)) if sc == c => title.push_str(" v"),
|
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.
|
// These columns show two-tone / multi-tone text (actual vs.
|
||||||
// expected, or one colour per fan) via a custom renderer that
|
// expected, or one colour per fan) via a custom renderer that
|
||||||
// parses the segment-encoded cell value fill_rows writes.
|
// parses the segment-encoded cell value fill_rows writes.
|
||||||
@@ -583,6 +583,9 @@ impl App {
|
|||||||
|
|
||||||
pub fn fill_rows(&mut self) {
|
pub fn fill_rows(&mut self) {
|
||||||
let Some(t) = self.table else { return };
|
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();
|
t.dvlc_clear();
|
||||||
self.view_idx = self.view.view(&self.rows);
|
self.view_idx = self.view.view(&self.rows);
|
||||||
let cols = self.view.display_columns();
|
let cols = self.view.display_columns();
|
||||||
@@ -592,13 +595,12 @@ impl App {
|
|||||||
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
|
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
|
||||||
t.dvlc_append_row(&refs);
|
t.dvlc_append_row(&refs);
|
||||||
}
|
}
|
||||||
// Colour each row's text by status (also separates rows visually).
|
// Rows are NOT tinted by status any more: every cell is the default text
|
||||||
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
// colour except the conditionally-formatted columns below (the Status
|
||||||
t.dvlc_set_row_color(disp, Some(status_color(&self.pal, &self.rows[ri])));
|
// column carries the status colour itself). Zebra striping + gridlines
|
||||||
}
|
// (set at table build) separate rows instead.
|
||||||
// Overwrite the combined actual/expected + cooling-fan cells with
|
// Overwrite the conditionally-coloured cells with segment-encoded text
|
||||||
// segment-encoded coloured text (the custom renderer these columns use
|
// (the custom renderer these columns use parses it back out).
|
||||||
// parses it back out; see encode_combined_cell/encode_cooling_cell).
|
|
||||||
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
for (disp, &ri) in self.view_idx.iter().enumerate() {
|
||||||
let r = &self.rows[ri];
|
let r = &self.rows[ri];
|
||||||
for (ci, c) in cols.iter().enumerate() {
|
for (ci, c) in cols.iter().enumerate() {
|
||||||
@@ -651,11 +653,19 @@ impl App {
|
|||||||
let color = (!r.errors.is_empty()).then_some(self.pal.red);
|
let color = (!r.errors.is_empty()).then_some(self.pal.red);
|
||||||
encode_flag_cell(&c.cell(r), color)
|
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,
|
_ => continue,
|
||||||
};
|
};
|
||||||
t.dvlc_set_cell(disp, ci, &encoded);
|
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).
|
// Re-apply the selection (a refresh clears the control's selection).
|
||||||
let sel: Vec<usize> = self
|
let sel: Vec<usize> = self
|
||||||
.view_idx
|
.view_idx
|
||||||
@@ -694,6 +704,9 @@ impl App {
|
|||||||
caption.set_fg(self.pal.label.0, self.pal.label.1, self.pal.label.2);
|
caption.set_fg(self.pal.label.0, self.pal.label.1, self.pal.label.2);
|
||||||
}
|
}
|
||||||
self.highlight_kpi_filter();
|
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.fill_rows(); // re-colour rows with the new palette
|
||||||
self.table_parent.layout();
|
self.table_parent.layout();
|
||||||
}
|
}
|
||||||
@@ -2075,7 +2088,7 @@ impl App {
|
|||||||
for (j, c) in cols.iter().enumerate() {
|
for (j, c) in cols.iter().enumerate() {
|
||||||
let want = c.cell(r);
|
let want = c.cell(r);
|
||||||
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
|
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)
|
decode_segments_plain(&raw)
|
||||||
} else {
|
} else {
|
||||||
raw
|
raw
|
||||||
@@ -2212,6 +2225,7 @@ mod tests {
|
|||||||
amber: (255, 128, 0),
|
amber: (255, 128, 0),
|
||||||
red: (255, 0, 0),
|
red: (255, 0, 0),
|
||||||
accent: (0, 0, 255),
|
accent: (0, 0, 255),
|
||||||
|
zebra: (245, 245, 245),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-1
@@ -10,7 +10,7 @@
|
|||||||
+pub use widgets::*;
|
+pub use widgets::*;
|
||||||
--- a/src/widgets.rs
|
--- a/src/widgets.rs
|
||||||
+++ b/src/widgets.rs
|
+++ b/src/widgets.rs
|
||||||
@@ -0,0 +1,688 @@
|
@@ -0,0 +1,712 @@
|
||||||
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
|
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
|
||||||
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
|
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
|
||||||
+// wxWidgets object tree (parents own children; nothing to free in Rust).
|
+// wxWidgets object tree (parents own children; nothing to free in Rust).
|
||||||
@@ -82,6 +82,9 @@
|
|||||||
+ pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
+ 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_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_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_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_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_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||||
@@ -548,6 +551,27 @@
|
|||||||
+ unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
+ 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 ----
|
+ // ---- rearrangeable check-list ----
|
||||||
+
|
+
|
||||||
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||||
|
|||||||
+45
-9
@@ -1,6 +1,6 @@
|
|||||||
--- a/cpp_src/widgets_bridge.cpp
|
--- a/cpp_src/widgets_bridge.cpp
|
||||||
+++ b/cpp_src/widgets_bridge.cpp
|
+++ b/cpp_src/widgets_bridge.cpp
|
||||||
@@ -0,0 +1,892 @@
|
@@ -0,0 +1,928 @@
|
||||||
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
|
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
|
||||||
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
|
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
|
||||||
+// render-callback bridge (which is kept untouched).
|
+// render-callback bridge (which is kept untouched).
|
||||||
@@ -56,21 +56,29 @@
|
|||||||
+ WxEV_DEFERRED = 14,
|
+ WxEV_DEFERRED = 14,
|
||||||
+};
|
+};
|
||||||
+
|
+
|
||||||
+// A list store that carries an optional per-row foreground colour, surfaced to
|
+// A list store that carries an optional per-row foreground colour plus an
|
||||||
+// the native control via GetAttrByRow. This is how the miner table paints each
|
+// alternating-row (zebra) background, surfaced to the native control via
|
||||||
+// row's text by status and separates rows on GTK (where SetAlternateRowColour
|
+// GetAttrByRow. The zebra background is set on odd rows only; because it is a
|
||||||
+// and :nth-child CSS are unreliable and fight the selection highlight).
|
+// 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 {
|
+class AttrListStore : public wxDataViewListStore {
|
||||||
+ public:
|
+ public:
|
||||||
+ std::vector<wxColour> row_fg;
|
+ 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,
|
+ bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||||
+ wxDataViewItemAttr& attr) const override {
|
+ wxDataViewItemAttr& attr) const override {
|
||||||
+ (void)col;
|
+ (void)col;
|
||||||
|
+ bool set = false;
|
||||||
+ if (row < row_fg.size() && row_fg[row].IsOk()) {
|
+ if (row < row_fg.size() && row_fg[row].IsOk()) {
|
||||||
+ attr.SetColour(row_fg[row]);
|
+ 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 +199,11 @@
|
|||||||
+// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
+// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
||||||
+// set_sizer_on calls as wxbr_box_sizer's result.
|
+// set_sizer_on calls as wxbr_box_sizer's result.
|
||||||
+void* wxbr_wrap_sizer(int vertical) {
|
+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):
|
+// flag bits (must match Rust sizer_flags):
|
||||||
@@ -442,7 +454,8 @@
|
|||||||
+ // status while the native selection highlight still shows through.
|
+ // status while the native selection highlight still shows through.
|
||||||
+ wxDataViewCtrl* dv =
|
+ wxDataViewCtrl* dv =
|
||||||
+ new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
+ 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();
|
+ AttrListStore* store = new AttrListStore();
|
||||||
+ dv->AssociateModel(store);
|
+ dv->AssociateModel(store);
|
||||||
+ store->DecRef(); // the control owns a reference now
|
+ store->DecRef(); // the control owns a reference now
|
||||||
@@ -549,6 +562,29 @@
|
|||||||
+ store->RowChanged(row);
|
+ 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) {
|
+int wxbr_dvlc_row_count(void* win) {
|
||||||
+ return (int)dvlc_store(win)->GetItemCount();
|
+ return (int)dvlc_store(win)->GetItemCount();
|
||||||
+}
|
+}
|
||||||
|
|||||||
@@ -53,21 +53,29 @@ enum WxWidgetEventKind {
|
|||||||
WxEV_DEFERRED = 14,
|
WxEV_DEFERRED = 14,
|
||||||
};
|
};
|
||||||
|
|
||||||
// A list store that carries an optional per-row foreground colour, surfaced to
|
// A list store that carries an optional per-row foreground colour plus an
|
||||||
// the native control via GetAttrByRow. This is how the miner table paints each
|
// alternating-row (zebra) background, surfaced to the native control via
|
||||||
// row's text by status and separates rows on GTK (where SetAlternateRowColour
|
// GetAttrByRow. The zebra background is set on odd rows only; because it is a
|
||||||
// and :nth-child CSS are unreliable and fight the selection highlight).
|
// 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 {
|
class AttrListStore : public wxDataViewListStore {
|
||||||
public:
|
public:
|
||||||
std::vector<wxColour> row_fg;
|
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,
|
bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||||
wxDataViewItemAttr& attr) const override {
|
wxDataViewItemAttr& attr) const override {
|
||||||
(void)col;
|
(void)col;
|
||||||
|
bool set = false;
|
||||||
if (row < row_fg.size() && row_fg[row].IsOk()) {
|
if (row < row_fg.size() && row_fg[row].IsOk()) {
|
||||||
attr.SetColour(row_fg[row]);
|
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 +196,11 @@ void* wxbr_box_sizer(int vertical) {
|
|||||||
// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
// subclass, so it accepts the same add/add_sizer/add_spacer/add_stretch and
|
||||||
// set_sizer_on calls as wxbr_box_sizer's result.
|
// set_sizer_on calls as wxbr_box_sizer's result.
|
||||||
void* wxbr_wrap_sizer(int vertical) {
|
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):
|
// flag bits (must match Rust sizer_flags):
|
||||||
@@ -439,7 +451,8 @@ void* wxbr_dvlc(void* parent) {
|
|||||||
// status while the native selection highlight still shows through.
|
// status while the native selection highlight still shows through.
|
||||||
wxDataViewCtrl* dv =
|
wxDataViewCtrl* dv =
|
||||||
new wxDataViewCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
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();
|
AttrListStore* store = new AttrListStore();
|
||||||
dv->AssociateModel(store);
|
dv->AssociateModel(store);
|
||||||
store->DecRef(); // the control owns a reference now
|
store->DecRef(); // the control owns a reference now
|
||||||
@@ -546,6 +559,29 @@ void wxbr_dvlc_set_row_color(void* win, unsigned row, int r, int g, int b) {
|
|||||||
store->RowChanged(row);
|
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) {
|
int wxbr_dvlc_row_count(void* win) {
|
||||||
return (int)dvlc_store(win)->GetItemCount();
|
return (int)dvlc_store(win)->GetItemCount();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ mod notsafe {
|
|||||||
pub fn wxbr_dvlc_select_rows(win: *mut c_void, rows: *const c_int, n: c_int);
|
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_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_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_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_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_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||||
@@ -535,6 +538,27 @@ impl Widget {
|
|||||||
unsafe { notsafe::wxbr_dvlc_set_row_color(self.0, row, r, g, b) }
|
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 ----
|
// ---- rearrangeable check-list ----
|
||||||
|
|
||||||
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||||
|
|||||||
Reference in New Issue
Block a user