Compare commits

...
3 Commits
Author SHA1 Message Date
noahandClaude Opus 4.8 a81fef3c7d GUI round 8: Errors column hover tooltip (full message list)
Item 12 (tooltip half): hovering an Errors cell now shows the full list of the
miner's error/event messages ("[Severity] text (component)", most severe first)
as a tooltip; the cell itself keeps the compact red summary.

wxDataViewCtrl has no per-cell tooltip API, and wx mouse-motion events are not
delivered to wx handlers on the native GTK control, so this uses GtkTreeView's
native "query-tooltip" signal directly (guarded by __WXGTK__): a per-cell
tooltip map (row, model column) -> text on the AttrListStore, populated from
Rust via a new dvlc_set_cell_tooltip bridge fn, and looked up by the signal
handler using dv->GTKColumnToWX(gcol)->GetModelColumn(). The map is populated on
every platform (a no-op where nothing reads it) so the non-GTK platform round
can wire its own tooltip surface later.

Local wx-rs bridge compile + full cargo check clean; patches 0002/0003
regenerated + validated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-17 17:37:18 -06:00
noahandClaude Opus 4.8 365732b5d4 GUI round 8b.2 fix: rubber-band drag-select uses native GtkTreeView on GTK
The wx-mouse-event rubber-band approach (LEFT_DOWN/MOTION/LEFT_UP) does not work
on the native GTK wxDataViewCtrl: the underlying GtkTreeView grabs the pointer
during a button drag, so wx never delivers the MOTION events, and only the
initial click row was selected (verified against the shipped binary).

Fix: on GTK, enable the GtkTreeView's own native rubber-band selection via
dv->GtkGetTreeView() + gtk_tree_view_set_rubber_banding(TRUE), guarded by
__WXGTK__ (gtk/gtk.h included only there). The wx-mouse-event approach is kept
as the non-GTK fallback for the future Windows/macOS builds, where it will be
verified in the platform round. The column-header right-click menu (native wx
dataview event) already worked and is unchanged.

Local wx-rs bridge compile clean; patch 0003 regenerated + validated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-17 17:27:16 -06:00
noahandClaude Opus 4.8 98603077e3 GUI round 8: view presets (save/load column arrangement, filters, sort)
Item 11: a "Presets" button (top-right) opens a dialog to save the current
table view -- column arrangement + visibility, sort, and all active filters --
as a named profile, load a saved one, or delete it. The built-in "Default"
profile is always the first preset and shows IP, Model, Hashrate, Power, Chip
temp, Firmware, Control board, PIC and Status; the app now boots with it.

- New presets.rs: a serde-serialized PresetView snapshot of ViewState (Vec-based
  so the JSON has no enum map keys), Preset { name, view }, and load/save to
  ~/.config/alkane-toolkit/presets.json. "Default" is re-seeded on load and not
  written, so it can't be lost or deleted. A loaded preset missing newer columns
  still covers every column (they're appended hidden).
- serde/serde_json added to alkane-gui (already vendored + locked via asic-rs);
  Column/ColFilter/TextOp/NumOp derive Serialize/Deserialize and ViewState is
  now Clone.
- ui.rs: build_presets_dialog + apply_preset_load/save/delete, wired to the new
  Presets button.

Unit tests: default-preset round-trips through ViewState and JSON.
cargo check --release --tests is clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-17 17:21:49 -06:00
10 changed files with 464 additions and 16 deletions
Generated
+2
View File
@@ -81,6 +81,8 @@ dependencies = [
"asic-rs",
"futures-util",
"measurements",
"serde",
"serde_json",
"tokio",
"wx-rs",
]
+2
View File
@@ -17,3 +17,5 @@ asic-rs = "0.8.1"
measurements = "0.11"
tokio = { version = "1", features = ["rt"] }
futures-util = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+1
View File
@@ -4,6 +4,7 @@
mod credentials;
mod fixtures;
mod model;
mod presets;
mod scan;
mod ui;
+5 -4
View File
@@ -345,7 +345,7 @@ pub fn flash_confirmed(input: &str) -> bool {
/// Model columns. Ip is fixed (always shown first); the rest map 1:1 to a
/// scannable metric and can be shown/hidden/reordered. Row selection replaces
/// the old checkbox column.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum Column {
Ip,
Hashrate,
@@ -688,7 +688,7 @@ pub enum SortKey {
}
/// Text-column filter operators (Excel-style text filters).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TextOp {
Contains,
NotContains,
@@ -698,7 +698,7 @@ pub enum TextOp {
}
/// Numeric-column filter operators (Excel-style number filters).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum NumOp {
Between,
Eq,
@@ -711,7 +711,7 @@ pub enum NumOp {
/// One column's active filter. Text columns can filter by a value checklist
/// ("is any of") or a text predicate; numeric columns by a numeric predicate.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum ColFilter {
Values(HashSet<String>),
Text { op: TextOp, needle: String },
@@ -752,6 +752,7 @@ impl ColFilter {
}
/// Display state: order, visibility, sort, filter.
#[derive(Clone)]
pub struct ViewState {
/// Model column order as displayed (Ip is always the first visible column).
pub order: Vec<Column>,
+146
View File
@@ -0,0 +1,146 @@
//! Saved view presets: named snapshots of the table's column arrangement,
//! visibility, sort, and filters. Persisted as JSON in the config dir. The
//! first preset is always a built-in "Default" profile.
use std::collections::{HashMap, HashSet};
use serde::{Deserialize, Serialize};
use crate::model::{ColFilter, Column, ViewState, ALL_COLUMNS};
use crate::scan::config_path;
pub const PRESETS_FILE: &str = "presets.json";
/// The built-in default profile's visible columns, in display order (Ip first).
const DEFAULT_PROFILE: [Column; 9] = [
Column::Ip,
Column::Model,
Column::Hashrate,
Column::Power,
Column::ChipTemp,
Column::Firmware,
Column::ControlBoard,
Column::Pic,
Column::Status,
];
/// A serializable snapshot of a `ViewState` (Vec-based so JSON has no map keys
/// that are enums, and column order within `visible` is preserved).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PresetView {
pub order: Vec<Column>,
pub visible: Vec<Column>,
pub sort: Option<(Column, bool)>,
pub filters: Vec<(Column, ColFilter)>,
}
impl PresetView {
pub fn from_view(v: &ViewState) -> PresetView {
PresetView {
order: v.order.clone(),
// keep the visible columns in display order for stability
visible: v.order.iter().copied().filter(|c| v.visible.contains(c)).collect(),
sort: v.sort,
filters: v.filters.iter().map(|(k, f)| (*k, f.clone())).collect(),
}
}
/// Rebuild a `ViewState` from this snapshot. Any column missing from a
/// loaded (possibly older) preset is appended to `order` and left hidden, so
/// the result always covers every `Column`.
pub fn to_view(&self) -> ViewState {
let mut order = self.order.clone();
for c in ALL_COLUMNS {
if !order.contains(&c) {
order.push(c);
}
}
let mut visible: HashSet<Column> = self.visible.iter().copied().collect();
visible.insert(Column::Ip); // IP is always shown
let filters: HashMap<Column, ColFilter> = self.filters.iter().cloned().collect();
ViewState { order, visible, sort: self.sort, filters }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Preset {
pub name: String,
pub view: PresetView,
}
/// The built-in default profile (always present as the first preset).
pub fn default_preset() -> Preset {
let mut order: Vec<Column> = DEFAULT_PROFILE.to_vec();
for c in ALL_COLUMNS {
if !order.contains(&c) {
order.push(c);
}
}
Preset {
name: "Default".to_string(),
view: PresetView {
order,
visible: DEFAULT_PROFILE.to_vec(),
sort: None,
filters: Vec::new(),
},
}
}
/// Load saved presets, always with the built-in "Default" first. A missing or
/// unreadable file yields just the default.
pub fn load_presets() -> Vec<Preset> {
let mut presets = std::fs::read_to_string(config_path(PRESETS_FILE))
.ok()
.and_then(|s| serde_json::from_str::<Vec<Preset>>(&s).ok())
.unwrap_or_default();
// The default profile is always present and always first.
presets.retain(|p| p.name != "Default");
presets.insert(0, default_preset());
presets
}
/// Persist presets (the built-in "Default" is not written; it is re-seeded on
/// load). Best-effort: errors are returned for the caller to surface.
pub fn save_presets(presets: &[Preset]) -> std::io::Result<()> {
let p = config_path(PRESETS_FILE);
if let Some(dir) = p.parent() {
std::fs::create_dir_all(dir)?;
}
let user: Vec<&Preset> = presets.iter().filter(|p| p.name != "Default").collect();
let json = serde_json::to_string_pretty(&user)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
std::fs::write(p, json)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_preset_round_trips_through_view() {
let p = default_preset();
let view = p.view.to_view();
// IP first + the requested default columns visible.
assert!(view.visible.contains(&Column::Ip));
assert!(view.visible.contains(&Column::ControlBoard));
assert!(view.visible.contains(&Column::Pic));
assert!(view.visible.contains(&Column::Status));
assert!(!view.visible.contains(&Column::Cooling), "not in the default profile");
// to_view covers every column in `order`.
assert_eq!(view.order.len(), ALL_COLUMNS.len());
// Round-trip a snapshot back out.
let snap = PresetView::from_view(&view);
assert_eq!(snap.visible.first(), Some(&Column::Ip));
}
#[test]
fn preset_json_round_trip() {
let p = default_preset();
let json = serde_json::to_string(&vec![&p]).unwrap();
let back: Vec<Preset> = serde_json::from_str(&json).unwrap();
assert_eq!(back.len(), 1);
assert_eq!(back[0].name, "Default");
assert_eq!(back[0].view.visible, DEFAULT_PROFILE.to_vec());
}
}
+140
View File
@@ -16,6 +16,13 @@ pub const ID_PLAY: i32 = 104;
pub const ID_PAUSE: i32 = 105;
pub const ID_STOP: i32 = 106;
pub const ID_SCAN_CREDS: i32 = 107;
pub const ID_PRESETS: i32 = 108;
// Presets dialog.
const ID_PRESET_LOAD: i32 = 770;
const ID_PRESET_SAVE: i32 = 771;
const ID_PRESET_DELETE: i32 = 772;
const ID_PRESET_CLOSE: i32 = 773;
const ID_PRESET_CHOICE: i32 = 774;
const ID_RANGES_APPLY: i32 = 201;
const ID_RANGES_CANCEL: i32 = 202;
const ID_COLUMNS_OK: i32 = 203;
@@ -337,6 +344,11 @@ pub struct App {
creds_dialog: Widget,
creds_user_input: Widget,
creds_pass_input: Widget,
// Saved view presets + the Presets dialog widgets.
presets: Vec<crate::presets::Preset>,
presets_dialog: Widget,
presets_choice: Widget,
presets_name_input: Widget,
// The last action's result, kept on the status bar for a few ticks.
action_result: Option<String>,
action_result_ticks: u8,
@@ -446,6 +458,8 @@ pub fn build(frame: Widget) -> App {
let stop_btn = Widget::media_button(panel, ID_STOP, 2, (226, 72, 60));
ctl.add(stop_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 2);
ctl.add_stretch(1);
let presets_btn = Widget::button(panel, "Presets", ID_PRESETS);
ctl.add(presets_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let filter_btn = Widget::button(panel, "Filter", ID_FILTER);
ctl.add(filter_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let columns_btn = Widget::button(panel, "Columns", ID_COLUMNS);
@@ -522,6 +536,10 @@ pub fn build(frame: Widget) -> App {
creds_dialog: frame,
creds_user_input: frame,
creds_pass_input: frame,
presets: crate::presets::load_presets(),
presets_dialog: frame,
presets_choice: frame,
presets_name_input: frame,
action_result: None,
action_result_ticks: 0,
ranges_dialog: frame,
@@ -544,6 +562,10 @@ pub fn build(frame: Widget) -> App {
filter_pending_op: None,
filter_working: HashMap::new(),
};
// Boot with the first (Default) preset's column layout.
if let Some(p) = app.presets.first() {
app.view = p.view.to_view();
}
app.rebuild_table();
Widget::timer(TIMER_SCAN, 1000);
app
@@ -672,6 +694,10 @@ impl App {
_ => continue,
};
t.dvlc_set_cell(disp, ci, &encoded);
// The Errors cell gets the full message list as a hover tooltip.
if matches!(c, Column::Error) {
t.dvlc_set_cell_tooltip(disp, ci, &r.errors.join("\n"));
}
}
}
if let Some(row) = top {
@@ -1645,6 +1671,115 @@ impl App {
ALL_COLUMNS.iter().copied().filter(|c| *c != Column::Ip).collect()
}
/// Build (but do not show) the view-presets dialog: load a saved view, save
/// the current columns/filters/sort as a named preset, or delete one.
fn build_presets_dialog(&mut self) -> Widget {
let frame = Widget::main_frame();
let dlg = Widget::dialog(frame, "View presets");
let root = Widget::box_sizer(true);
root.add(
Widget::static_text(
dlg,
"Load a saved view, or save the current columns, filters and sort as a new preset.",
),
0,
sf::BORDER_ALL,
8,
);
let choice = Widget::choice(dlg, ID_PRESET_CHOICE);
for p in &self.presets {
choice.choice_append(&p.name);
}
choice.choice_set_selection(0);
choice.set_min_size(220, -1);
root.add(choice, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 8);
let row = Widget::box_sizer(false);
row.add(Widget::button(dlg, "Load", ID_PRESET_LOAD), 0, sf::BORDER_ALL, 4);
row.add(Widget::button(dlg, "Delete", ID_PRESET_DELETE), 0, sf::BORDER_ALL, 4);
root.add_sizer(row, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 8);
let saverow = Widget::box_sizer(false);
saverow.add(
Widget::static_text(dlg, "Save current as:"),
0,
sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL,
4,
);
let name = Widget::text_ctrl(dlg, false);
name.set_min_size(150, -1);
saverow.add(name, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
saverow.add(Widget::button(dlg, "Save", ID_PRESET_SAVE), 0, sf::BORDER_ALL, 4);
root.add_sizer(saverow, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 8);
let btns = Widget::box_sizer(false);
btns.add_stretch(1);
btns.add(Widget::button(dlg, "Close", ID_PRESET_CLOSE), 0, sf::BORDER_ALL, 6);
root.add_sizer(btns, 0, sf::EXPAND | sf::BORDER_ALL, 6);
root.set_sizer_on(dlg);
dlg.set_min_size(400, 220);
dlg.fit(dlg);
self.presets_dialog = dlg;
self.presets_choice = choice;
self.presets_name_input = name;
dlg
}
/// Load the selected preset, replacing the current view (columns, filters,
/// sort) and rebuilding the table.
fn apply_preset_load(&mut self) {
let sel = self.presets_choice.choice_get_selection();
let Some(p) = usize::try_from(sel).ok().and_then(|i| self.presets.get(i)) else { return };
self.view = p.view.to_view();
self.presets_dialog.close(1);
self.rebuild_table();
self.update_headers();
self.resync_kpi_filter();
wx_rs::set_status_text("preset loaded");
}
/// Save the current view as a new (or replaced) named preset.
fn apply_preset_save(&mut self) {
let name = self.presets_name_input.get_value().trim().to_string();
if name.is_empty() {
wx_rs::set_status_text("enter a preset name");
return;
}
if name == "Default" {
wx_rs::set_status_text("\"Default\" is reserved");
return;
}
let view = crate::presets::PresetView::from_view(&self.view);
let preset = crate::presets::Preset { name: name.clone(), view };
if let Some(existing) = self.presets.iter_mut().find(|p| p.name == name) {
*existing = preset;
} else {
self.presets.push(preset);
}
match crate::presets::save_presets(&self.presets) {
Ok(()) => {
self.presets_dialog.close(1);
wx_rs::set_status_text(&format!("saved preset \"{name}\""));
}
Err(e) => wx_rs::set_status_text(&format!("failed to save preset: {e}")),
}
}
/// Delete the selected preset (the built-in "Default" can't be deleted).
fn apply_preset_delete(&mut self) {
let sel = self.presets_choice.choice_get_selection();
let Some(i) = usize::try_from(sel).ok().filter(|&i| i < self.presets.len()) else { return };
if self.presets[i].name == "Default" {
wx_rs::set_status_text("the Default preset can't be deleted");
return;
}
let name = self.presets.remove(i).name;
match crate::presets::save_presets(&self.presets) {
Ok(()) => {
self.presets_dialog.close(1);
wx_rs::set_status_text(&format!("deleted preset \"{name}\""));
}
Err(e) => wx_rs::set_status_text(&format!("failed to save presets: {e}")),
}
}
/// Build (but do not show) the columns chooser: a rearrangeable checklist of
/// every scannable metric. Check to show; drag or use the up/down arrows to
/// reorder. IP is always the first column and is not listed here.
@@ -2025,6 +2160,11 @@ impl App {
ID_COLUMNS => return Some(self.build_columns_dialog()),
ID_COLUMNS_OK => self.apply_columns(),
ID_COLUMNS_CANCEL => self.columns_dialog.close(0),
ID_PRESETS => return Some(self.build_presets_dialog()),
ID_PRESET_LOAD => self.apply_preset_load(),
ID_PRESET_SAVE => self.apply_preset_save(),
ID_PRESET_DELETE => self.apply_preset_delete(),
ID_PRESET_CLOSE => self.presets_dialog.close(0),
ID_FILTER => return Some(self.build_filter_dialog()),
ID_FILTER_OK => self.apply_filter(),
ID_FILTER_CANCEL => self.filter_dialog.close(0),
+9 -1
View File
@@ -10,7 +10,7 @@
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
@@ -0,0 +1,720 @@
@@ -0,0 +1,728 @@
+// 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).
@@ -71,6 +71,7 @@
+ pub fn wxbr_dvlc_clear(win: *mut c_void);
+ pub fn wxbr_dvlc_row_count(win: *mut c_void) -> c_int;
+ pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
+ pub fn wxbr_dvlc_set_cell_tooltip(win: *mut c_void, row: usize, col: usize, text: *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);
@@ -495,6 +496,13 @@
+ unsafe { notsafe::wxbr_dvlc_set_cell(self.0, row, col, c.as_ptr()) }
+ }
+
+ /// Set the hover tooltip for one cell (empty clears it). GTK only; a no-op
+ /// on other platforms until they gain per-cell tooltip support.
+ pub fn dvlc_set_cell_tooltip(&self, row: usize, col: usize, text: &str) {
+ let c = CString::new(text).unwrap_or_default();
+ unsafe { notsafe::wxbr_dvlc_set_cell_tooltip(self.0, row, col, c.as_ptr()) }
+ }
+
+ pub fn dvlc_get_cell(&self, row: usize, col: usize) -> Option<String> {
+ let mut buf = vec![0i8; 4096];
+ let n = unsafe {
+76 -6
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,989 @@
@@ -0,0 +1,1059 @@
+// 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).
@@ -36,12 +36,21 @@
+#include <cstdio>
+#include <map>
+#include <vector>
+#ifdef __WXGTK__
+// For native GtkTreeView rubber-band (click-drag) selection, which wx does not
+// enable and which cannot be done via wx mouse events on GTK (the native widget
+// grabs the pointer during a drag). Guarded so non-GTK builds are unaffected.
+#include <gtk/gtk.h>
+#endif
+
+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.
+#ifndef __WXGTK__
+// Anchor row per data-view control for the wx-mouse-event rubber-band fallback
+// (non-GTK platforms; GTK uses native GtkTreeView rubber-banding instead).
+static std::map<wxDataViewCtrl*, int> g_drag_anchor;
+#endif
+
+// Event kinds (must match Rust WxEventKind in src/widgets.rs)
+enum WxWidgetEventKind {
@@ -71,6 +80,9 @@
+ public:
+ std::vector<wxColour> row_fg;
+ wxColour zebra; // odd-row background; unset (=off) unless the app sets it
+ // Per-cell hover tooltip text, keyed by (row, model column). Used for the
+ // Errors column's full-message tooltip (see the GTK query-tooltip handler).
+ std::map<std::pair<unsigned, unsigned>, wxString> cell_tip;
+ bool GetAttrByRow(unsigned int row, unsigned int col,
+ wxDataViewItemAttr& attr) const override {
+ (void)col;
@@ -453,6 +465,36 @@
+ return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
+}
+
+#ifdef __WXGTK__
+// GtkTreeView "query-tooltip" handler: show the per-cell tooltip stored for the
+// (row, model column) under the pointer (used by the Errors column). wx does
+// not surface per-cell tooltips on wxDataViewCtrl, and mouse-motion events are
+// not delivered to wx handlers on the native GTK control, so this hooks the
+// native signal directly.
+static gboolean dvlc_query_tooltip(GtkWidget* tv, gint x, gint y, gboolean keyboard,
+ GtkTooltip* tooltip, gpointer user_data) {
+ (void)keyboard;
+ wxDataViewCtrl* dv = static_cast<wxDataViewCtrl*>(user_data);
+ gint bx = 0, by = 0;
+ gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(tv), x, y, &bx, &by);
+ GtkTreePath* path = nullptr;
+ GtkTreeViewColumn* gcol = nullptr;
+ if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), bx, by, &path, &gcol, nullptr, nullptr))
+ return FALSE;
+ gint* idx = gtk_tree_path_get_indices(path);
+ int row = idx ? idx[0] : -1;
+ gtk_tree_path_free(path);
+ if (row < 0 || !gcol) return FALSE;
+ wxDataViewColumn* wxcol = dv->GTKColumnToWX(gcol);
+ if (!wxcol) return FALSE;
+ AttrListStore* store = static_cast<AttrListStore*>(dv->GetModel());
+ auto it = store->cell_tip.find({(unsigned)row, wxcol->GetModelColumn()});
+ if (it == store->cell_tip.end() || it->second.IsEmpty()) return FALSE;
+ gtk_tooltip_set_text(tooltip, it->second.utf8_str());
+ return TRUE;
+}
+#endif
+
+void* wxbr_dvlc(void* parent) {
+ // Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
+ // checkbox column. A custom AttrListStore backs it so rows can be coloured by
@@ -490,10 +532,25 @@
+ 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.
+ // Rubber-band (click-drag) range selection. wxDataViewCtrl has none natively.
+#ifdef __WXGTK__
+ // On GTK the control wraps a GtkTreeView, which supports native rubber-band
+ // selection -- just not enabled by wx. Enable it directly. (wx delivers no
+ // MOTION events during the native drag, so the mouse-event fallback below is
+ // inapplicable on GTK.)
+ {
+ GtkWidget* tv = dv->GtkGetTreeView();
+ if (tv) {
+ gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
+ // Per-cell hover tooltips (Errors column) via the native signal.
+ gtk_widget_set_has_tooltip(tv, TRUE);
+ g_signal_connect(tv, "query-tooltip", G_CALLBACK(dvlc_query_tooltip), dv);
+ }
+ }
+#else
+ // Non-GTK fallback: track a drag anchor and extend the selection to the row
+ // under the cursor. LEFT_DOWN records the anchor (and lets the native handler
+ // select it); dragging with the button down selects the inclusive range.
+ dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
+ if (!dv) { e.Skip(); return; }
@@ -534,6 +591,7 @@
+ if (dv) g_drag_anchor.erase(dv);
+ e.Skip();
+ });
+#endif
+ // 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) {
@@ -605,6 +663,18 @@
+ AttrListStore* store = dvlc_store(win);
+ store->DeleteAllItems();
+ store->row_fg.clear();
+ store->cell_tip.clear();
+}
+
+// Set (or clear, with an empty string) the hover tooltip for one cell,
+// addressed by (row, model column). Used for the Errors column's full text.
+void wxbr_dvlc_set_cell_tooltip(void* win, unsigned row, unsigned col, const char* text) {
+ AttrListStore* store = dvlc_store(win);
+ if (text && text[0]) {
+ store->cell_tip[{row, col}] = wxString::FromUTF8(text);
+ } else {
+ store->cell_tip.erase({row, col});
+ }
+}
+
+// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
@@ -33,12 +33,21 @@
#include <cstdio>
#include <map>
#include <vector>
#ifdef __WXGTK__
// For native GtkTreeView rubber-band (click-drag) selection, which wx does not
// enable and which cannot be done via wx mouse events on GTK (the native widget
// grabs the pointer during a drag). Guarded so non-GTK builds are unaffected.
#include <gtk/gtk.h>
#endif
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.
#ifndef __WXGTK__
// Anchor row per data-view control for the wx-mouse-event rubber-band fallback
// (non-GTK platforms; GTK uses native GtkTreeView rubber-banding instead).
static std::map<wxDataViewCtrl*, int> g_drag_anchor;
#endif
// Event kinds (must match Rust WxEventKind in src/widgets.rs)
enum WxWidgetEventKind {
@@ -68,6 +77,9 @@ class AttrListStore : public wxDataViewListStore {
public:
std::vector<wxColour> row_fg;
wxColour zebra; // odd-row background; unset (=off) unless the app sets it
// Per-cell hover tooltip text, keyed by (row, model column). Used for the
// Errors column's full-message tooltip (see the GTK query-tooltip handler).
std::map<std::pair<unsigned, unsigned>, wxString> cell_tip;
bool GetAttrByRow(unsigned int row, unsigned int col,
wxDataViewItemAttr& attr) const override {
(void)col;
@@ -450,6 +462,36 @@ static AttrListStore* dvlc_store(void* win) {
return static_cast<AttrListStore*>(((wxDataViewCtrl*)win)->GetModel());
}
#ifdef __WXGTK__
// GtkTreeView "query-tooltip" handler: show the per-cell tooltip stored for the
// (row, model column) under the pointer (used by the Errors column). wx does
// not surface per-cell tooltips on wxDataViewCtrl, and mouse-motion events are
// not delivered to wx handlers on the native GTK control, so this hooks the
// native signal directly.
static gboolean dvlc_query_tooltip(GtkWidget* tv, gint x, gint y, gboolean keyboard,
GtkTooltip* tooltip, gpointer user_data) {
(void)keyboard;
wxDataViewCtrl* dv = static_cast<wxDataViewCtrl*>(user_data);
gint bx = 0, by = 0;
gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(tv), x, y, &bx, &by);
GtkTreePath* path = nullptr;
GtkTreeViewColumn* gcol = nullptr;
if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv), bx, by, &path, &gcol, nullptr, nullptr))
return FALSE;
gint* idx = gtk_tree_path_get_indices(path);
int row = idx ? idx[0] : -1;
gtk_tree_path_free(path);
if (row < 0 || !gcol) return FALSE;
wxDataViewColumn* wxcol = dv->GTKColumnToWX(gcol);
if (!wxcol) return FALSE;
AttrListStore* store = static_cast<AttrListStore*>(dv->GetModel());
auto it = store->cell_tip.find({(unsigned)row, wxcol->GetModelColumn()});
if (it == store->cell_tip.end() || it->second.IsEmpty()) return FALSE;
gtk_tooltip_set_text(tooltip, it->second.utf8_str());
return TRUE;
}
#endif
void* wxbr_dvlc(void* parent) {
// Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
// checkbox column. A custom AttrListStore backs it so rows can be coloured by
@@ -487,10 +529,25 @@ void* wxbr_dvlc(void* parent) {
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.
// Rubber-band (click-drag) range selection. wxDataViewCtrl has none natively.
#ifdef __WXGTK__
// On GTK the control wraps a GtkTreeView, which supports native rubber-band
// selection -- just not enabled by wx. Enable it directly. (wx delivers no
// MOTION events during the native drag, so the mouse-event fallback below is
// inapplicable on GTK.)
{
GtkWidget* tv = dv->GtkGetTreeView();
if (tv) {
gtk_tree_view_set_rubber_banding(GTK_TREE_VIEW(tv), TRUE);
// Per-cell hover tooltips (Errors column) via the native signal.
gtk_widget_set_has_tooltip(tv, TRUE);
g_signal_connect(tv, "query-tooltip", G_CALLBACK(dvlc_query_tooltip), dv);
}
}
#else
// Non-GTK fallback: track a drag anchor and extend the selection to the row
// under the cursor. LEFT_DOWN records the anchor (and lets the native handler
// select it); dragging with the button down selects the inclusive range.
dv->Bind(wxEVT_LEFT_DOWN, [](wxMouseEvent& e) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)e.GetEventObject();
if (!dv) { e.Skip(); return; }
@@ -531,6 +588,7 @@ void* wxbr_dvlc(void* parent) {
if (dv) g_drag_anchor.erase(dv);
e.Skip();
});
#endif
// 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) {
@@ -602,6 +660,18 @@ void wxbr_dvlc_clear(void* win) {
AttrListStore* store = dvlc_store(win);
store->DeleteAllItems();
store->row_fg.clear();
store->cell_tip.clear();
}
// Set (or clear, with an empty string) the hover tooltip for one cell,
// addressed by (row, model column). Used for the Errors column's full text.
void wxbr_dvlc_set_cell_tooltip(void* win, unsigned row, unsigned col, const char* text) {
AttrListStore* store = dvlc_store(win);
if (text && text[0]) {
store->cell_tip[{row, col}] = wxString::FromUTF8(text);
} else {
store->cell_tip.erase({row, col});
}
}
// Set (or clear, when r<0) a row's text colour; used to paint rows by status.
+8
View File
@@ -58,6 +58,7 @@ mod notsafe {
pub fn wxbr_dvlc_clear(win: *mut c_void);
pub fn wxbr_dvlc_row_count(win: *mut c_void) -> c_int;
pub fn wxbr_dvlc_set_cell(win: *mut c_void, row: usize, col: usize, value: *const c_char);
pub fn wxbr_dvlc_set_cell_tooltip(win: *mut c_void, row: usize, col: usize, text: *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);
@@ -482,6 +483,13 @@ impl Widget {
unsafe { notsafe::wxbr_dvlc_set_cell(self.0, row, col, c.as_ptr()) }
}
/// Set the hover tooltip for one cell (empty clears it). GTK only; a no-op
/// on other platforms until they gain per-cell tooltip support.
pub fn dvlc_set_cell_tooltip(&self, row: usize, col: usize, text: &str) {
let c = CString::new(text).unwrap_or_default();
unsafe { notsafe::wxbr_dvlc_set_cell_tooltip(self.0, row, col, c.as_ptr()) }
}
pub fn dvlc_get_cell(&self, row: usize, col: usize) -> Option<String> {
let mut buf = vec![0i8; 4096];
let n = unsafe {