GUI round 2: selection, scan loop, column management, dark-mode fix
- Fixed "Scan ranges" button label (no longer grows with the range list). - Dark-mode KPI cards: derive colours from the live system theme luminance instead of is_dark(), which mis-detected some GTK dark themes. - Removed the checkbox column; the table is multi-select (wxDV_MULTIPLE, ctrl/shift-click), with the selection tracked by IP so it survives refreshes. - Replaced Rescan with Play / Pause / Stop; added an editable auto-rescan interval (scan-ranges dialog; ~/.config/alkane-toolkit/auto-rescan-secs.txt) with a timer-driven countdown scheduler. - Status bar shows the last-probed IP during a scan and a countdown to the next scan when idle (dropped the "scan complete" text). - Default sort is IP-ascending with a header chevron; IP is column 0, sortable. - Choose-columns dialog is a wxRearrangeCtrl (check to show; up/down or drag to reorder) exposing every metric, including Pool 1/2/3 URL + worker. - Column drag-reorder moves the whole column with its data on drop. - Row separator lines (wxDV_ROW_LINES). GTK3 native has no zebra striping; a GTK4-forward zebra-CSS hook and pkg-config gtk cflags are in place. Scan engine: parse each configured pool's (url, worker); Progress carries the last-probed IP. Model: Column::Sel removed; Pool1/2/3 columns; default IP sort. wx-rs bridge: multi-select + selection/context-menu events + get_selections, alternating-row + zebra-CSS hooks, in-place column title, rearrangeable list, and popup-menu primitives (for the upcoming right-click config menu). Patches 0001-0003 regenerated and round-trip validated. Review fixes: scan loop no longer sticks "scanning" if a thread ends without Done (channel-disconnect handling + Stop force-reset); Play no longer starts a second scan; stale selections pruned on rescan; column apply order/visibility applied atomically. Verified: 22 unit tests, a 14-check headless UI self-test, and interaction checks (multi-select, column rearrange/drag, play/pause/stop, dark mode). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
+14
@@ -42,6 +42,20 @@ board metadata (`boards/*/board.yml`); this toolkit mechanizes those recipes.
|
||||
- Double-click a row opens `http://<ip>` in the default browser (`wxLaunchDefaultBrowser`).
|
||||
- Filter panel horizontal layout can get wide with many category columns (no scrolled-window in the bridge yet); it is resizable. Live text-search within a filter column is not implemented.
|
||||
|
||||
**Feature round 2 (2026-09-16, operator requests):**
|
||||
- Scan-ranges button is a fixed "Scan ranges" label (no longer grows with the ranges).
|
||||
- Dark-mode KPI cards fixed: colours derive from the live system theme luminance (`palette()` reads `system_color`), not `is_dark()` which mis-detected some GTK dark themes.
|
||||
- Checkbox column removed; the table is multi-select (`wxDV_MULTIPLE`, ctrl/shift-click), selection tracked by IP so it survives scan refreshes.
|
||||
- Rescan replaced by Play / Pause / Stop; auto-rescan interval editable in the scan-ranges dialog (`scan::load/save_auto_secs`, `~/.config/alkane-toolkit/auto-rescan-secs.txt`). Timer-driven scheduler with a countdown.
|
||||
- Status bar shows the last-probed IP during a scan and a countdown to the next scan when idle (no more "scan complete" text).
|
||||
- Default sort is IP-ascending with a header chevron; IP is column 0 and sortable.
|
||||
- Choose-columns dialog is a `wxRearrangeCtrl` (check to show, up/down or drag to reorder); exposes every metric incl. Pool 1/2/3 URL + worker (`MinerRow.pools`).
|
||||
- Column drag-reorder in the table moves the whole column with its data on drop (native GTK shows only the header ghost during the drag - not changeable without a custom-drawn table).
|
||||
- Row separation: `wxDV_ROW_LINES` (thin separators). GTK3's native dataview has no zebra striping (SetAlternateRowColour is generic-only; `:nth-child` CSS is GTK4-only). A `wxbr_apply_zebra_css` hook is in place for GTK4; true zebra on GTK3 needs a custom `wxDataViewVirtualListModel` with `GetAttrByRow` - deferred.
|
||||
- `build.rs` now adds `pkg-config --cflags gtk+-3.0` so the bridge can call GTK directly.
|
||||
|
||||
**Deferred - item 11 (right-click multi-config menu):** intersection-of-config context menu that writes to live miners via asic-rs `HasMinerControl`/`SupportsConfigs` (fault light, power limit, tuning, restart, pause/resume, pool config). The wx bridge for it (popup menu + context-menu event) is already in place; the apply-to-live-hardware layer + confirm-before-apply is the next round.
|
||||
|
||||
**Dev / review / visual-feedback loop (see AGENTS.md):**
|
||||
- `scripts/ui-selftest.sh` — headless workflow self-test: `ALKANE_SELFTEST` mode renders the bench-fleet fixtures through the real widgets and compares the table cells + KPIs to the expected hardware output (13 checks; exit non-zero on any mismatch). `cargo test -p alkane-gui` runs the transform-layer unit tests (10).
|
||||
- `scripts/ui-screenshot.sh [out.png] [--live]` — off-screen (private Xvfb) screenshot for visual review; defaults to the offline `ALKANE_FAKE_SCAN` fixtures.
|
||||
|
||||
@@ -60,6 +60,14 @@ impl Board {
|
||||
uptime_secs: if self.mining { 3600 * 24 * 2 + 3600 * 5 } else { 0 },
|
||||
light_flashing: Some(false),
|
||||
pool_url: if self.worker.is_empty() { String::new() } else { "stratum+tcp://pool.blueflare:3333".to_string() },
|
||||
pools: if self.worker.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
vec![
|
||||
("stratum+tcp://pool.blueflare:3333".to_string(), self.worker.to_string()),
|
||||
("stratum+tcp://backup.blueflare:3333".to_string(), format!("{}_bak", self.worker)),
|
||||
]
|
||||
},
|
||||
operating_state: if self.mining { "mining".to_string() } else { "idle".to_string() },
|
||||
..Default::default()
|
||||
}
|
||||
|
||||
@@ -92,9 +92,11 @@ pub struct MinerRow {
|
||||
pub expected_chips: Option<u32>,
|
||||
pub hashboards: Option<u32>,
|
||||
pub expected_hashboards: Option<u32>,
|
||||
// pool
|
||||
// pool: active-pool convenience fields, plus the (url, worker) of each
|
||||
// configured pool (miners usually allow up to 3 redundant pools).
|
||||
pub worker: String,
|
||||
pub pool_url: String,
|
||||
pub pools: Vec<(String, String)>,
|
||||
// shares
|
||||
pub best_share: Option<f64>,
|
||||
pub session_best_share: Option<f64>,
|
||||
@@ -130,11 +132,11 @@ impl MinerRow {
|
||||
}
|
||||
}
|
||||
|
||||
/// Model columns. Sel and Ip are fixed (checkbox + always-on IP column); the
|
||||
/// rest map 1:1 to a scannable metric and can be shown/hidden/reordered.
|
||||
/// 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)]
|
||||
pub enum Column {
|
||||
Sel,
|
||||
Ip,
|
||||
Hashrate,
|
||||
Power,
|
||||
@@ -167,12 +169,17 @@ pub enum Column {
|
||||
SessionBestShare,
|
||||
TuningPercent,
|
||||
PoolUrl,
|
||||
Pool1Url,
|
||||
Pool1Worker,
|
||||
Pool2Url,
|
||||
Pool2Worker,
|
||||
Pool3Url,
|
||||
Pool3Worker,
|
||||
}
|
||||
|
||||
/// Every column, in registry order. Sel + Ip first, then the default-visible
|
||||
/// set (UI-SPEC order), then all remaining metrics.
|
||||
pub const ALL_COLUMNS: [Column; 33] = [
|
||||
Column::Sel,
|
||||
/// Every column, in registry order. Ip first, then the default-visible set
|
||||
/// (UI-SPEC order), then all remaining metrics.
|
||||
pub const ALL_COLUMNS: [Column; 38] = [
|
||||
Column::Ip,
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
@@ -205,9 +212,15 @@ pub const ALL_COLUMNS: [Column; 33] = [
|
||||
Column::SessionBestShare,
|
||||
Column::TuningPercent,
|
||||
Column::PoolUrl,
|
||||
Column::Pool1Url,
|
||||
Column::Pool1Worker,
|
||||
Column::Pool2Url,
|
||||
Column::Pool2Worker,
|
||||
Column::Pool3Url,
|
||||
Column::Pool3Worker,
|
||||
];
|
||||
|
||||
/// The columns shown by default (UI-SPEC), after Sel + Ip.
|
||||
/// The columns shown by default (UI-SPEC), after the fixed IP column.
|
||||
pub const DEFAULT_VISIBLE: [Column; 8] = [
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
@@ -222,7 +235,6 @@ pub const DEFAULT_VISIBLE: [Column; 8] = [
|
||||
impl Column {
|
||||
pub fn title(self) -> &'static str {
|
||||
match self {
|
||||
Column::Sel => "",
|
||||
Column::Ip => "IP",
|
||||
Column::Hashrate => "Hashrate",
|
||||
Column::Power => "Power",
|
||||
@@ -255,12 +267,17 @@ impl Column {
|
||||
Column::SessionBestShare => "Session best",
|
||||
Column::TuningPercent => "Tuning %",
|
||||
Column::PoolUrl => "Pool URL",
|
||||
Column::Pool1Url => "Pool 1 URL",
|
||||
Column::Pool1Worker => "Pool 1 worker",
|
||||
Column::Pool2Url => "Pool 2 URL",
|
||||
Column::Pool2Worker => "Pool 2 worker",
|
||||
Column::Pool3Url => "Pool 3 URL",
|
||||
Column::Pool3Worker => "Pool 3 worker",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(self) -> i32 {
|
||||
match self {
|
||||
Column::Sel => 28,
|
||||
Column::Ip => 130,
|
||||
Column::Hashrate | Column::ExpectedHashrate => 110,
|
||||
Column::Power => 90,
|
||||
@@ -282,7 +299,8 @@ impl Column {
|
||||
Column::Uptime => 100,
|
||||
Column::OperatingState => 100,
|
||||
Column::BestShare | Column::SessionBestShare => 110,
|
||||
Column::PoolUrl => 220,
|
||||
Column::PoolUrl | Column::Pool1Url | Column::Pool2Url | Column::Pool3Url => 200,
|
||||
Column::Pool1Worker | Column::Pool2Worker | Column::Pool3Worker => 150,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +338,6 @@ impl Column {
|
||||
pub fn sort_key(&self, r: &MinerRow) -> SortKey {
|
||||
let none = f64::NEG_INFINITY;
|
||||
match self {
|
||||
Column::Sel => SortKey::Num(if r.selected { 1.0 } else { 0.0 }),
|
||||
Column::Hashrate => SortKey::Num(r.hashrate_ths),
|
||||
Column::ExpectedHashrate => SortKey::Num(r.expected_ths),
|
||||
Column::Power => SortKey::Num(r.power_w),
|
||||
@@ -360,8 +377,9 @@ impl Column {
|
||||
}
|
||||
};
|
||||
let count = |v: Option<u32>| -> String { v.map(|n| n.to_string()).unwrap_or_default() };
|
||||
let pool_url = |i: usize| r.pools.get(i).map(|(u, _)| u.clone()).unwrap_or_default();
|
||||
let pool_worker = |i: usize| r.pools.get(i).map(|(_, w)| w.clone()).unwrap_or_default();
|
||||
match self {
|
||||
Column::Sel => String::new(),
|
||||
Column::Ip => r.ip.clone(),
|
||||
Column::Hashrate => {
|
||||
if r.hashrate_ths > 0.0 {
|
||||
@@ -418,6 +436,12 @@ impl Column {
|
||||
r.session_best_share.map(|v| format_si(v, "")).unwrap_or_default()
|
||||
}
|
||||
Column::TuningPercent => r.tuning_percent.map(|v| format!("{v}%")).unwrap_or_default(),
|
||||
Column::Pool1Url => pool_url(0),
|
||||
Column::Pool1Worker => pool_worker(0),
|
||||
Column::Pool2Url => pool_url(1),
|
||||
Column::Pool2Worker => pool_worker(1),
|
||||
Column::Pool3Url => pool_url(2),
|
||||
Column::Pool3Worker => pool_worker(2),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,7 +453,7 @@ pub enum SortKey {
|
||||
|
||||
/// Display state: order, visibility, sort, filter.
|
||||
pub struct ViewState {
|
||||
/// Model column order as displayed (Sel is always display position 0).
|
||||
/// Model column order as displayed (Ip is always the first visible column).
|
||||
pub order: Vec<Column>,
|
||||
pub visible: HashSet<Column>,
|
||||
pub sort: Option<(Column, bool)>, // (column, ascending)
|
||||
@@ -439,36 +463,37 @@ pub struct ViewState {
|
||||
|
||||
impl Default for ViewState {
|
||||
fn default() -> Self {
|
||||
// Registry order for `order`; only Sel + Ip + DEFAULT_VISIBLE are shown.
|
||||
// Registry order for `order`; Ip + DEFAULT_VISIBLE are shown. Default
|
||||
// sort is by IP ascending.
|
||||
let order: Vec<Column> = ALL_COLUMNS.to_vec();
|
||||
let mut visible: HashSet<Column> = DEFAULT_VISIBLE.iter().copied().collect();
|
||||
visible.insert(Column::Sel);
|
||||
visible.insert(Column::Ip);
|
||||
ViewState { order, visible, sort: None, filters: HashMap::new() }
|
||||
ViewState { order, visible, sort: Some((Column::Ip, true)), filters: HashMap::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewState {
|
||||
pub fn display_columns(&self) -> Vec<Column> {
|
||||
// Ip is always shown first; the rest follow `order` filtered by visibility.
|
||||
self.order
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|c| *c == Column::Sel || self.visible.contains(c))
|
||||
.filter(|c| *c == Column::Ip || self.visible.contains(c))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn is_fixed(&self, c: Column) -> bool {
|
||||
c == Column::Sel || c == Column::Ip
|
||||
c == Column::Ip
|
||||
}
|
||||
|
||||
/// Apply a drag-reorder of the visible columns. `new_visible` is the visible
|
||||
/// columns in their new display order; it must be a permutation of the
|
||||
/// currently-visible set with Sel still first. The new order is spliced back
|
||||
/// currently-visible set with Ip still first. The new order is spliced back
|
||||
/// into `order`, leaving hidden columns in their existing slots, so a
|
||||
/// reorder while some column is hidden never drops or duplicates a column.
|
||||
pub fn apply_visible_reorder(&mut self, new_visible: &[Column]) {
|
||||
let disp = self.display_columns();
|
||||
if new_visible.len() != disp.len() || new_visible.first() != Some(&Column::Sel) {
|
||||
if new_visible.len() != disp.len() || new_visible.first() != Some(&Column::Ip) {
|
||||
return;
|
||||
}
|
||||
let want: HashSet<Column> = disp.iter().copied().collect();
|
||||
@@ -486,12 +511,9 @@ impl ViewState {
|
||||
|
||||
/// Rows that pass every active filter (AND across columns, OR within one).
|
||||
pub fn passes_filters(&self, r: &MinerRow) -> bool {
|
||||
self.filters.iter().all(|(col, allowed)| {
|
||||
if *col == Column::Sel {
|
||||
return true;
|
||||
}
|
||||
allowed.contains(&col.cell(r))
|
||||
})
|
||||
self.filters
|
||||
.iter()
|
||||
.all(|(col, allowed)| allowed.contains(&col.cell(r)))
|
||||
}
|
||||
|
||||
/// Filtered + sorted rows in display order.
|
||||
@@ -605,11 +627,14 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_view_is_insertion_order() {
|
||||
fn default_view_sorts_by_ip_ascending() {
|
||||
let (rows, _v, idx) = full_view();
|
||||
let ips: Vec<&str> = idx.iter().map(|&i| rows[i].ip.as_str()).collect();
|
||||
assert_eq!(ips[0], "10.255.1.112");
|
||||
let ips: Vec<String> = idx.iter().map(|&i| rows[i].ip.clone()).collect();
|
||||
assert_eq!(ips.len(), 9);
|
||||
let mut sorted = ips.clone();
|
||||
sorted.sort();
|
||||
assert_eq!(ips, sorted, "default view should be IP-ascending");
|
||||
assert_eq!(ips[0], "10.255.1.112");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -641,13 +666,12 @@ mod tests {
|
||||
fn default_visible_is_the_ui_spec_set() {
|
||||
let view = ViewState::default();
|
||||
let disp = view.display_columns();
|
||||
// Sel, Ip, then the 8 default columns in order.
|
||||
assert_eq!(disp[0], Column::Sel);
|
||||
assert_eq!(disp[1], Column::Ip);
|
||||
assert_eq!(&disp[2..], &DEFAULT_VISIBLE[..]);
|
||||
// Ip first, then the 8 default columns in order.
|
||||
assert_eq!(disp[0], Column::Ip);
|
||||
assert_eq!(&disp[1..], &DEFAULT_VISIBLE[..]);
|
||||
// hidden-by-default metrics are still selectable (present in order).
|
||||
assert!(view.order.contains(&Column::Mac));
|
||||
assert!(view.order.contains(&Column::Uptime));
|
||||
assert!(view.order.contains(&Column::Pool2Url));
|
||||
assert!(!view.visible.contains(&Column::Mac));
|
||||
}
|
||||
|
||||
@@ -659,8 +683,7 @@ mod tests {
|
||||
view.visible.remove(&Column::Power);
|
||||
let after = view.display_columns();
|
||||
assert!(!after.contains(&Column::Power));
|
||||
assert_eq!(after[0], Column::Sel);
|
||||
assert_eq!(after[1], Column::Ip);
|
||||
assert_eq!(after[0], Column::Ip);
|
||||
assert_eq!(after.len(), before.len() - 1);
|
||||
let hr = after.iter().position(|c| *c == Column::Hashrate).unwrap();
|
||||
assert_eq!(after[hr + 1], Column::ChipTemp);
|
||||
@@ -678,8 +701,9 @@ mod tests {
|
||||
fn reorder_with_hidden_column_keeps_all_columns() {
|
||||
let mut view = ViewState::default();
|
||||
view.visible.remove(&Column::Power);
|
||||
// display now: Ip(0), Hashrate(1), ChipTemp(2), ... - swap Hashrate/ChipTemp
|
||||
let mut vis = view.display_columns();
|
||||
vis.swap(2, 3); // swap Hashrate and ChipTemp
|
||||
vis.swap(1, 2);
|
||||
view.apply_visible_reorder(&vis);
|
||||
assert!(view.order.contains(&Column::Power), "hidden column dropped!");
|
||||
assert_eq!(view.order.len(), ALL_COLUMNS.len());
|
||||
@@ -689,15 +713,15 @@ mod tests {
|
||||
let hr = disp.iter().position(|c| *c == Column::Hashrate).unwrap();
|
||||
let ct = disp.iter().position(|c| *c == Column::ChipTemp).unwrap();
|
||||
assert!(ct < hr, "reorder not applied");
|
||||
assert_eq!(view.order[0], Column::Sel);
|
||||
assert_eq!(view.order[1], Column::Ip);
|
||||
assert_eq!(view.order[0], Column::Ip);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reorder_rejects_non_permutation() {
|
||||
let mut view = ViewState::default();
|
||||
let before = view.order.clone();
|
||||
view.apply_visible_reorder(&[Column::Ip, Column::Sel, Column::Hashrate]);
|
||||
// Ip not first -> ignored
|
||||
view.apply_visible_reorder(&[Column::Hashrate, Column::Ip, Column::Power]);
|
||||
assert_eq!(view.order, before);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@ pub enum ScanMsg {
|
||||
/// A new scan started: `total` addresses to probe, and the exact set of
|
||||
/// target IPs (as strings) so the UI can drop miners no longer in range.
|
||||
Started { total: usize, targets: HashSet<String> },
|
||||
/// Progress update: `done` of `total` addresses probed.
|
||||
Progress { done: usize, total: usize },
|
||||
/// Progress update: `done` of `total` addresses probed; `ip` is the most
|
||||
/// recently probed address (activity indicator).
|
||||
Progress { done: usize, total: usize, ip: String },
|
||||
/// A miner was identified.
|
||||
Row(MinerRow),
|
||||
/// The scan finished (label is informational).
|
||||
@@ -26,7 +27,27 @@ pub enum ScanMsg {
|
||||
|
||||
pub const CONFIG_DIR: &str = ".config/alkane-toolkit";
|
||||
pub const RANGES_FILE: &str = "scan-ranges.txt";
|
||||
pub const AUTO_FILE: &str = "auto-rescan-secs.txt";
|
||||
pub const DEFAULT_RANGE: &str = "10.255.1.0/24";
|
||||
/// Default seconds between automatic rescans.
|
||||
pub const DEFAULT_AUTO_SECS: u64 = 300;
|
||||
|
||||
/// Load the auto-rescan interval in seconds (0 = disabled).
|
||||
pub fn load_auto_secs() -> u64 {
|
||||
std::fs::read_to_string(config_path(AUTO_FILE))
|
||||
.ok()
|
||||
.and_then(|s| s.trim().parse().ok())
|
||||
.unwrap_or(DEFAULT_AUTO_SECS)
|
||||
}
|
||||
|
||||
/// Save the auto-rescan interval in seconds.
|
||||
pub fn save_auto_secs(secs: u64) -> std::io::Result<()> {
|
||||
let p = config_path(AUTO_FILE);
|
||||
if let Some(dir) = p.parent() {
|
||||
std::fs::create_dir_all(dir)?;
|
||||
}
|
||||
std::fs::write(p, secs.to_string())
|
||||
}
|
||||
|
||||
pub fn config_path(file: &str) -> PathBuf {
|
||||
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
|
||||
@@ -222,7 +243,7 @@ pub fn start_scan(lines: Vec<String>) -> Receiver<ScanMsg> {
|
||||
if tx.send(ScanMsg::Row(row)).is_err() {
|
||||
return;
|
||||
}
|
||||
let _ = tx.send(ScanMsg::Progress { done: i + 1, total });
|
||||
let _ = tx.send(ScanMsg::Progress { done: i + 1, total, ip: String::new() });
|
||||
}
|
||||
let _ = tx.send(ScanMsg::Done("fixtures".into()));
|
||||
})
|
||||
@@ -273,7 +294,7 @@ pub fn start_scan(lines: Vec<String>) -> Receiver<ScanMsg> {
|
||||
let mut stream = factory.scan_stream_with_ip();
|
||||
let mut done = 0usize;
|
||||
let step = (total / 100).max(1); // throttle progress messages
|
||||
while let Some((_ip, miner)) = stream.next().await {
|
||||
while let Some((ip, miner)) = stream.next().await {
|
||||
done += 1;
|
||||
if let Some(miner) = miner {
|
||||
let row = to_row(&*miner).await;
|
||||
@@ -282,7 +303,7 @@ pub fn start_scan(lines: Vec<String>) -> Receiver<ScanMsg> {
|
||||
}
|
||||
}
|
||||
if done % step == 0 || done == total {
|
||||
let _ = tx.send(ScanMsg::Progress { done, total });
|
||||
let _ = tx.send(ScanMsg::Progress { done, total, ip: ip.to_string() });
|
||||
}
|
||||
}
|
||||
let _ = tx.send(ScanMsg::Done(format!("{total} addresses")));
|
||||
@@ -332,6 +353,18 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
let pool_url = active_pool
|
||||
.and_then(|p| p.url.as_ref().map(|u| u.to_string()))
|
||||
.unwrap_or_default();
|
||||
// Each configured pool's (url, worker), in order, across all pool groups.
|
||||
let pools: Vec<(String, String)> = data
|
||||
.pools
|
||||
.iter()
|
||||
.flat_map(|g| g.pools.iter())
|
||||
.map(|p| {
|
||||
(
|
||||
p.url.as_ref().map(|u| u.to_string()).unwrap_or_default(),
|
||||
p.user.clone().unwrap_or_default(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let firmware = match (&data.device_info.firmware, &data.firmware_version) {
|
||||
(fw, Some(v)) if !fw.is_empty() => format!("{fw} {v}"),
|
||||
(fw, Some(v)) => format!("{fw}{v}"),
|
||||
@@ -383,6 +416,7 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
expected_hashboards: data.expected_hashboards.map(|v| v as u32),
|
||||
worker,
|
||||
pool_url,
|
||||
pools,
|
||||
best_share: data.best_share,
|
||||
session_best_share: data.session_best_share,
|
||||
uptime_secs: data.uptime.map(|d| d.as_secs()).unwrap_or(0),
|
||||
|
||||
+255
-137
@@ -11,14 +11,13 @@ use wx_rs::{Widget, WxEvent, WxEventKind, sizer_flags as sf};
|
||||
pub const ID_RANGES: i32 = 101;
|
||||
pub const ID_FILTER: i32 = 102;
|
||||
pub const ID_COLUMNS: i32 = 103;
|
||||
pub const ID_RESCAN: i32 = 104;
|
||||
pub const ID_PLAY: i32 = 104;
|
||||
pub const ID_PAUSE: i32 = 105;
|
||||
pub const ID_STOP: i32 = 106;
|
||||
const ID_RANGES_APPLY: i32 = 201;
|
||||
const ID_RANGES_CANCEL: i32 = 202;
|
||||
const ID_COLUMNS_OK: i32 = 203;
|
||||
const ID_COLUMNS_CANCEL: i32 = 204;
|
||||
const ID_COLUMNS_ALL: i32 = 207;
|
||||
const ID_COLUMNS_NONE: i32 = 208;
|
||||
const ID_COLUMNS_RESET: i32 = 209;
|
||||
const ID_FILTER_OK: i32 = 205;
|
||||
const ID_FILTER_CANCEL: i32 = 206;
|
||||
const ID_FILTER_RESET: i32 = 210;
|
||||
@@ -29,7 +28,9 @@ const ID_FILTER_NONE_BASE: i32 = 500;
|
||||
const TIMER_SCAN: i32 = 1;
|
||||
|
||||
/// Theme-aware palette for the KPI cards. Health is encoded in colour so a red
|
||||
/// "Not hashing" or amber "Slow" draws the eye immediately.
|
||||
/// "Not hashing" or amber "Slow" draws the eye immediately. Colours derive from
|
||||
/// the live system theme so the cards follow light/dark correctly (relying on
|
||||
/// wxAppearance alone left the cards white under some GTK dark themes).
|
||||
struct Palette {
|
||||
card_bg: (u8, u8, u8),
|
||||
label: (u8, u8, u8),
|
||||
@@ -40,27 +41,38 @@ struct Palette {
|
||||
accent: (u8, u8, u8),
|
||||
}
|
||||
|
||||
fn palette(dark: bool) -> Palette {
|
||||
if dark {
|
||||
Palette {
|
||||
card_bg: (44, 46, 51),
|
||||
label: (150, 156, 164),
|
||||
neutral: (228, 230, 234),
|
||||
green: (74, 222, 128),
|
||||
amber: (245, 190, 66),
|
||||
red: (245, 110, 100),
|
||||
accent: (108, 168, 250),
|
||||
}
|
||||
fn luminance(c: (u8, u8, u8)) -> f32 {
|
||||
0.299 * c.0 as f32 + 0.587 * c.1 as f32 + 0.114 * c.2 as f32
|
||||
}
|
||||
|
||||
fn nudge(c: (u8, u8, u8), d: i32) -> (u8, u8, u8) {
|
||||
let f = |v: u8| (v as i32 + d).clamp(0, 255) as u8;
|
||||
(f(c.0), f(c.1), f(c.2))
|
||||
}
|
||||
|
||||
/// Short mm:ss-ish duration for the rescan countdown ("4m 12s", "45s").
|
||||
fn fmt_secs(s: u64) -> String {
|
||||
if s >= 60 {
|
||||
format!("{}m {:02}s", s / 60, s % 60)
|
||||
} else {
|
||||
Palette {
|
||||
card_bg: (255, 255, 255),
|
||||
label: (108, 114, 122),
|
||||
neutral: (28, 32, 38),
|
||||
green: (33, 140, 80),
|
||||
amber: (176, 120, 10),
|
||||
red: (198, 55, 45),
|
||||
accent: (40, 100, 170),
|
||||
}
|
||||
format!("{s}s")
|
||||
}
|
||||
}
|
||||
|
||||
fn palette() -> Palette {
|
||||
let win = wx_rs::system_color(0); // window background
|
||||
let text = wx_rs::system_color(1); // window text
|
||||
let dark = luminance(win) < 128.0;
|
||||
Palette {
|
||||
// Cards read as slightly elevated vs the window: lighter in dark mode,
|
||||
// pure white on a light-grey window.
|
||||
card_bg: if dark { nudge(win, 14) } else { (255, 255, 255) },
|
||||
label: if dark { (150, 156, 164) } else { (108, 114, 122) },
|
||||
neutral: text,
|
||||
green: if dark { (74, 222, 128) } else { (33, 140, 80) },
|
||||
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) },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +86,6 @@ pub struct App {
|
||||
kpi_not: Widget,
|
||||
kpi_hashrate: Widget,
|
||||
kpi_power: Widget,
|
||||
ranges_btn: Widget,
|
||||
progress: Widget,
|
||||
pub table: Option<Widget>,
|
||||
table_parent: Widget,
|
||||
@@ -83,8 +94,17 @@ pub struct App {
|
||||
pub scanning: bool,
|
||||
scan_total: usize,
|
||||
target_ips: HashSet<String>,
|
||||
// scan loop (play/pause/stop + auto-rescan)
|
||||
playing: bool,
|
||||
auto_secs: u64,
|
||||
countdown: u64,
|
||||
// selection (replaces the old checkbox column), tracked by IP so it
|
||||
// survives table refreshes during a scan.
|
||||
selected_ips: HashSet<String>,
|
||||
alt_row: (u8, u8, u8),
|
||||
ranges_dialog: Widget,
|
||||
ranges_edit: Widget,
|
||||
ranges_auto: Widget,
|
||||
columns_dialog: Widget,
|
||||
columns_list: Widget,
|
||||
filter_dialog: Widget,
|
||||
@@ -92,8 +112,12 @@ pub struct App {
|
||||
}
|
||||
|
||||
pub fn build(frame: Widget) -> App {
|
||||
let dark = wx_rs::is_dark();
|
||||
let pal = palette(dark);
|
||||
let pal = palette();
|
||||
// Subtle alternating-row tint derived from the theme. GTK's native dataview
|
||||
// ignores SetAlternateRowColour, so also install an app-wide zebra CSS.
|
||||
let win = wx_rs::system_color(0);
|
||||
let alt_row = if luminance(win) < 128.0 { nudge(win, 12) } else { nudge(win, -12) };
|
||||
wx_rs::apply_zebra_css(alt_row.0, alt_row.1, alt_row.2);
|
||||
let panel = Widget::panel(frame);
|
||||
let root = Widget::box_sizer(true);
|
||||
|
||||
@@ -128,18 +152,23 @@ pub fn build(frame: Widget) -> App {
|
||||
let kpi_power = mk_card("Est. power", pal.neutral);
|
||||
root.add_sizer(kpi_row, 0, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
|
||||
// Controls row: scan-ranges button on the left; Filter / Columns / Rescan
|
||||
// Controls row: scan-ranges + play/pause/stop on the left; Filter / Columns
|
||||
// pushed to the right.
|
||||
let ctl = Widget::box_sizer(false);
|
||||
let ranges_btn = Widget::button(panel, "Scan ranges", ID_RANGES);
|
||||
ctl.add(ranges_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
ctl.add_spacer(8);
|
||||
let play_btn = Widget::button(panel, "Play", ID_PLAY);
|
||||
ctl.add(play_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
let pause_btn = Widget::button(panel, "Pause", ID_PAUSE);
|
||||
ctl.add(pause_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
let stop_btn = Widget::button(panel, "Stop", ID_STOP);
|
||||
ctl.add(stop_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
ctl.add_stretch(1);
|
||||
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);
|
||||
ctl.add(columns_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
let rescan_btn = Widget::button(panel, "Rescan", ID_RESCAN);
|
||||
ctl.add(rescan_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
root.add_sizer(ctl, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 4);
|
||||
|
||||
// Scan-progress bar across the top of the table (hidden when idle).
|
||||
@@ -171,7 +200,6 @@ pub fn build(frame: Widget) -> App {
|
||||
kpi_not,
|
||||
kpi_hashrate,
|
||||
kpi_power,
|
||||
ranges_btn,
|
||||
progress,
|
||||
table: None,
|
||||
table_parent,
|
||||
@@ -180,14 +208,19 @@ pub fn build(frame: Widget) -> App {
|
||||
scanning: true,
|
||||
scan_total: 0,
|
||||
target_ips: HashSet::new(),
|
||||
playing: true,
|
||||
auto_secs: scan::load_auto_secs(),
|
||||
countdown: 0,
|
||||
selected_ips: HashSet::new(),
|
||||
alt_row,
|
||||
ranges_dialog: frame,
|
||||
ranges_edit: frame,
|
||||
ranges_auto: frame,
|
||||
columns_dialog: frame,
|
||||
columns_list: frame,
|
||||
filter_dialog: frame,
|
||||
filter_lists: Vec::new(),
|
||||
};
|
||||
app.ranges_btn.set_label(&format!("Scan ranges: {}", ranges.join(", ")));
|
||||
app.rebuild_table();
|
||||
Widget::timer(TIMER_SCAN, 1000);
|
||||
app
|
||||
@@ -202,26 +235,25 @@ impl App {
|
||||
t.destroy();
|
||||
}
|
||||
let t = Widget::dvlc(self.table_parent);
|
||||
// creation order == display order: Sel toggle column first (fixed),
|
||||
// then Ip (fixed), then the reorderable statistics columns. The active
|
||||
// sort column carries an ASCII direction marker in its header ("^" asc,
|
||||
// "v" desc) -- wx's native SetSortOrder re-sorts the store lexically and
|
||||
// would fight our numeric sort, so we mark the header text instead.
|
||||
t.dvlc_append_toggle_col(28);
|
||||
for c in self.view.display_columns().iter().skip(1) {
|
||||
let fixed = self.view.is_fixed(*c);
|
||||
// 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
|
||||
// native SetSortOrder re-sorts the store lexically and would fight our
|
||||
// numeric sort, so we mark the header text instead.
|
||||
for c in self.view.display_columns() {
|
||||
let fixed = self.view.is_fixed(c);
|
||||
let mut title = c.title().to_string();
|
||||
match self.view.sort {
|
||||
Some((sc, true)) if sc == *c => title.push_str(" ^"),
|
||||
Some((sc, false)) if sc == *c => title.push_str(" v"),
|
||||
Some((sc, true)) if sc == c => title.push_str(" ^"),
|
||||
Some((sc, false)) if sc == c => title.push_str(" v"),
|
||||
_ => {}
|
||||
}
|
||||
t.dvlc_append_text_col(&title, c.width(), !fixed);
|
||||
}
|
||||
t.dvlc_set_alt_row_color(self.alt_row.0, self.alt_row.1, self.alt_row.2);
|
||||
// Add the table to the root sizer (proportion 1 => fills the area under
|
||||
// the KPI + controls rows) and re-run the panel's layout so it is
|
||||
// positioned, not left floating at (0,0). This was the "table in the
|
||||
// top-left corner" bug: the control was created but never sized.
|
||||
// positioned, not left floating at (0,0).
|
||||
self.root_sizer.add(t, 1, sf::EXPAND | sf::BORDER_ALL, 4);
|
||||
self.table = Some(t);
|
||||
self.table_parent.layout();
|
||||
@@ -235,18 +267,21 @@ impl App {
|
||||
let cols = self.view.display_columns();
|
||||
for &ri in &self.view_idx {
|
||||
let r = &self.rows[ri];
|
||||
// The toggle column carries the checked state ("1"/"0") so a refresh
|
||||
// preserves selection; other columns carry their text.
|
||||
let cells: Vec<String> = cols
|
||||
.iter()
|
||||
.map(|c| match c {
|
||||
Column::Sel => if r.selected { "1".to_string() } else { "0".to_string() },
|
||||
_ => c.cell(r),
|
||||
})
|
||||
.collect();
|
||||
let cells: Vec<String> = cols.iter().map(|c| c.cell(r)).collect();
|
||||
let refs: Vec<&str> = cells.iter().map(|s| s.as_str()).collect();
|
||||
t.dvlc_append_row(&refs);
|
||||
}
|
||||
// Re-apply the selection (a refresh clears the control's selection).
|
||||
let sel: Vec<usize> = self
|
||||
.view_idx
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, &ri)| self.selected_ips.contains(&self.rows[ri].ip))
|
||||
.map(|(disp, _)| disp)
|
||||
.collect();
|
||||
if !sel.is_empty() {
|
||||
t.dvlc_select_rows(&sel);
|
||||
}
|
||||
self.refresh_kpis();
|
||||
}
|
||||
|
||||
@@ -271,6 +306,9 @@ impl App {
|
||||
self.rows.retain(|r| targets.contains(&r.ip));
|
||||
changed |= self.rows.len() != before;
|
||||
self.target_ips = targets;
|
||||
// Drop selections that are no longer in range.
|
||||
let keep = std::mem::take(&mut self.selected_ips);
|
||||
self.selected_ips = keep.into_iter().filter(|ip| self.target_ips.contains(ip)).collect();
|
||||
self.scan_total = total;
|
||||
self.scanning = true;
|
||||
self.progress.gauge_set_range(total.max(1) as i32);
|
||||
@@ -279,11 +317,12 @@ impl App {
|
||||
self.table_parent.layout();
|
||||
wx_rs::set_status_text(&format!("scanning {total} addresses..."));
|
||||
}
|
||||
Ok(ScanMsg::Progress { done, total }) => {
|
||||
Ok(ScanMsg::Progress { done, total, ip }) => {
|
||||
self.scan_total = total;
|
||||
self.progress.gauge_set_value(done.min(total) as i32);
|
||||
let where_ = if ip.is_empty() { String::new() } else { format!(" - scanning {ip}") };
|
||||
wx_rs::set_status_text(&format!(
|
||||
"scanning {done}/{total} - {} found",
|
||||
"{done}/{total}{where_} ({} found)",
|
||||
self.rows.len()
|
||||
));
|
||||
}
|
||||
@@ -294,20 +333,35 @@ impl App {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
Ok(ScanMsg::Done(s)) => {
|
||||
Ok(ScanMsg::Done(_s)) => {
|
||||
self.scanning = false;
|
||||
self.progress.gauge_set_value(self.scan_total.max(1) as i32);
|
||||
self.progress.show(false);
|
||||
self.table_parent.layout();
|
||||
wx_rs::set_status_text(&format!("scan complete: {} found in {s}", self.rows.len()));
|
||||
// Arm the next automatic scan (if the loop is running).
|
||||
self.countdown = if self.playing { self.auto_secs } else { 0 };
|
||||
}
|
||||
Ok(ScanMsg::Failed(e)) => {
|
||||
self.scanning = false;
|
||||
self.progress.show(false);
|
||||
self.table_parent.layout();
|
||||
wx_rs::set_status_text(&format!("scan failed: {e}"));
|
||||
self.countdown = if self.playing { self.auto_secs } else { 0 };
|
||||
}
|
||||
Err(std::sync::mpsc::TryRecvError::Empty) => break,
|
||||
Err(std::sync::mpsc::TryRecvError::Disconnected) => {
|
||||
// The scan thread ended. Normally this follows Done/Failed
|
||||
// (handled above); if it ended without either (panic/hang
|
||||
// recovery), don't leave the loop stuck "scanning".
|
||||
if self.scanning {
|
||||
self.scanning = false;
|
||||
self.progress.show(false);
|
||||
self.table_parent.layout();
|
||||
self.countdown = if self.playing { self.auto_secs } else { 0 };
|
||||
}
|
||||
self.scan_rx = None;
|
||||
break;
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
@@ -315,14 +369,54 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_select(&mut self, store_row: usize, _col: usize) {
|
||||
// The toggle renderer + list store update themselves visually; we
|
||||
// flip the model and refresh the KPIs (selection is not a KPI, but
|
||||
// keep state coherent for future bulk actions).
|
||||
if let Some(&ri) = self.view_idx.get(store_row) {
|
||||
if let Some(r) = self.rows.get_mut(ri) {
|
||||
r.selected = !r.selected;
|
||||
/// Called every second by the scan timer: drain scan messages, then run the
|
||||
/// scan-loop scheduler (countdown to the next automatic rescan, or idle).
|
||||
fn tick(&mut self) {
|
||||
self.drain_scan();
|
||||
if self.scanning {
|
||||
return; // status already shows scan progress
|
||||
}
|
||||
if self.playing && self.auto_secs > 0 {
|
||||
if self.countdown > 1 {
|
||||
self.countdown -= 1;
|
||||
wx_rs::set_status_text(&format!(
|
||||
"{} miners - next scan in {}",
|
||||
self.rows.len(),
|
||||
fmt_secs(self.countdown)
|
||||
));
|
||||
} else {
|
||||
self.start_new_scan();
|
||||
}
|
||||
} else {
|
||||
wx_rs::set_status_text(&format!(
|
||||
"{} miners - {}",
|
||||
self.rows.len(),
|
||||
if self.playing { "auto-rescan off" } else { "paused" }
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Start a fresh scan of the saved ranges.
|
||||
fn start_new_scan(&mut self) {
|
||||
self.scan_rx = Some(scan::start_scan(scan::load_ranges()));
|
||||
self.scanning = true;
|
||||
self.countdown = 0;
|
||||
wx_rs::set_status_text("scanning...");
|
||||
}
|
||||
|
||||
/// The table's selection changed (ctrl/shift-click). Mirror it into the
|
||||
/// model, tracked by IP so it survives table refreshes during a scan.
|
||||
fn on_selection_changed(&mut self) {
|
||||
let Some(t) = self.table else { return };
|
||||
let rows_sel = t.dvlc_get_selections();
|
||||
self.selected_ips.clear();
|
||||
for disp in rows_sel {
|
||||
if let Some(&ri) = self.view_idx.get(disp) {
|
||||
self.selected_ips.insert(self.rows[ri].ip.clone());
|
||||
}
|
||||
}
|
||||
for r in &mut self.rows {
|
||||
r.selected = self.selected_ips.contains(&r.ip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,13 +433,12 @@ impl App {
|
||||
}
|
||||
|
||||
fn header_click(&mut self, creation_idx: usize) {
|
||||
// Columns are appended to the table in display order (toggle col first,
|
||||
// then each visible column). Map the clicked creation index back to a
|
||||
// model column through display_columns(), not view.order, so hidden
|
||||
// columns don't shift the mapping.
|
||||
// Columns are appended in display order; map the clicked creation index
|
||||
// back to a model column through display_columns() (hidden columns don't
|
||||
// shift the mapping). Every column, including IP at index 0, is sortable.
|
||||
let cols = self.view.display_columns();
|
||||
if creation_idx == 0 || creation_idx >= cols.len() {
|
||||
return; // toggle column (idx 0) is not sortable
|
||||
if creation_idx >= cols.len() {
|
||||
return;
|
||||
}
|
||||
let col = cols[creation_idx];
|
||||
self.view.sort = match self.view.sort {
|
||||
@@ -364,9 +457,6 @@ impl App {
|
||||
fn update_headers(&self) {
|
||||
let Some(t) = self.table else { return };
|
||||
for (i, c) in self.view.display_columns().iter().enumerate() {
|
||||
if i == 0 {
|
||||
continue; // toggle column has no title
|
||||
}
|
||||
let mut title = c.title().to_string();
|
||||
match self.view.sort {
|
||||
Some((sc, true)) if sc == *c => title.push_str(" ^"),
|
||||
@@ -409,18 +499,24 @@ impl App {
|
||||
let edit = Widget::text_ctrl(dlg, true);
|
||||
edit.set_value(&scan::load_ranges().join("\n"));
|
||||
root.add(edit, 1, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
// Auto-rescan interval (seconds; 0 = off).
|
||||
let auto_row = Widget::box_sizer(false);
|
||||
let auto_lbl = Widget::static_text(dlg, "Auto-rescan every (seconds, 0 = off):");
|
||||
auto_row.add(auto_lbl, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
|
||||
let auto_edit = Widget::text_ctrl(dlg, false);
|
||||
auto_edit.set_value(&self.auto_secs.to_string());
|
||||
auto_row.add(auto_edit, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
|
||||
root.add_sizer(auto_row, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
let btns = Widget::box_sizer(false);
|
||||
let apply = Widget::button(dlg, "Apply", ID_RANGES_APPLY);
|
||||
btns.add(apply, 0, sf::BORDER_ALL, 6);
|
||||
let cancel = Widget::button(dlg, "Cancel", ID_RANGES_CANCEL);
|
||||
btns.add(cancel, 0, sf::BORDER_ALL, 6);
|
||||
// `root` is a vertical sizer: only border flags are valid here. Using
|
||||
// ALIGN_CENTRE_VERTICAL trips a wxWidgets consistency assert whose
|
||||
// handler pumps a nested event loop -> re-entrant dispatch -> crash.
|
||||
root.add_sizer(btns, 0, sf::BORDER_ALL, 6);
|
||||
root.set_sizer_on(dlg);
|
||||
self.ranges_dialog = dlg;
|
||||
self.ranges_edit = edit;
|
||||
self.ranges_auto = auto_edit;
|
||||
dlg
|
||||
}
|
||||
|
||||
@@ -441,82 +537,85 @@ impl App {
|
||||
wx_rs::set_status_text(&format!("invalid range: {e}"));
|
||||
return; // keep dialog open
|
||||
}
|
||||
// Save the auto-rescan interval too.
|
||||
if let Ok(secs) = self.ranges_auto.get_value().trim().parse::<u64>() {
|
||||
self.auto_secs = secs;
|
||||
let _ = scan::save_auto_secs(secs);
|
||||
}
|
||||
let _ = scan::save_ranges(&lines);
|
||||
self.scan_rx = Some(scan::start_scan(lines.clone()));
|
||||
self.scanning = true;
|
||||
self.countdown = 0;
|
||||
wx_rs::set_status_text("scanning...");
|
||||
self.ranges_btn.set_label(&format!("Scan ranges: {}", lines.join(", ")));
|
||||
self.ranges_dialog.close(1);
|
||||
}
|
||||
|
||||
/// The columns available to show/hide: every metric except the fixed
|
||||
/// Sel + Ip columns, in registry order (matches the check-list order).
|
||||
/// The columns available to show/hide: every metric except the fixed IP
|
||||
/// column, in registry order (the rearrange-list's item index space).
|
||||
fn selectable_columns() -> Vec<Column> {
|
||||
ALL_COLUMNS
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|c| *c != Column::Sel && *c != Column::Ip)
|
||||
.collect()
|
||||
ALL_COLUMNS.iter().copied().filter(|c| *c != Column::Ip).collect()
|
||||
}
|
||||
|
||||
/// Build (but do not show) the columns chooser. Every scannable metric is
|
||||
/// listed, so any of them can be shown.
|
||||
/// 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.
|
||||
fn build_columns_dialog(&mut self) -> Widget {
|
||||
let frame = Widget::main_frame();
|
||||
let dlg = Widget::dialog(frame, "Choose columns");
|
||||
let root = Widget::box_sizer(true);
|
||||
let hint = Widget::static_text(dlg, "Show any scannable metric (IP is always shown):");
|
||||
let hint = Widget::static_text(
|
||||
dlg,
|
||||
"Check to show a metric; drag or use the arrows to reorder (IP is always first).",
|
||||
);
|
||||
root.add(hint, 0, sf::BORDER_ALL, 6);
|
||||
let list = Widget::check_list_box(dlg);
|
||||
for c in Self::selectable_columns() {
|
||||
list.clb_append(c.title());
|
||||
list.clb_set_checked(list.clb_count() - 1, self.view.visible.contains(&c));
|
||||
// Base list is registry order; the wx order array lists items in the
|
||||
// current arranged order, encoding checked = visible (a negative value
|
||||
// ~idx means item idx unchecked).
|
||||
let base = Self::selectable_columns();
|
||||
let titles: Vec<&str> = base.iter().map(|c| c.title()).collect();
|
||||
let mut order: Vec<i32> = Vec::with_capacity(base.len());
|
||||
for c in self.view.order.iter().filter(|c| **c != Column::Ip) {
|
||||
if let Some(idx) = base.iter().position(|b| b == c) {
|
||||
let idx = idx as i32;
|
||||
order.push(if self.view.visible.contains(c) { idx } else { !idx });
|
||||
}
|
||||
}
|
||||
let list = Widget::rearrange_list(dlg, &order, &titles);
|
||||
root.add(list, 1, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
// quick actions
|
||||
let quick = Widget::box_sizer(false);
|
||||
quick.add(Widget::button(dlg, "All", ID_COLUMNS_ALL), 0, sf::BORDER_ALL, 4);
|
||||
quick.add(Widget::button(dlg, "None", ID_COLUMNS_NONE), 0, sf::BORDER_ALL, 4);
|
||||
quick.add(Widget::button(dlg, "Defaults", ID_COLUMNS_RESET), 0, sf::BORDER_ALL, 4);
|
||||
root.add_sizer(quick, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 4);
|
||||
let btns = Widget::box_sizer(false);
|
||||
btns.add(Widget::button(dlg, "OK", ID_COLUMNS_OK), 0, sf::BORDER_ALL, 6);
|
||||
btns.add(Widget::button(dlg, "Cancel", ID_COLUMNS_CANCEL), 0, sf::BORDER_ALL, 6);
|
||||
root.add_sizer(btns, 0, sf::BORDER_ALL, 6);
|
||||
root.set_sizer_on(dlg);
|
||||
dlg.fit(dlg);
|
||||
self.columns_dialog = dlg;
|
||||
self.columns_list = list;
|
||||
dlg
|
||||
}
|
||||
|
||||
/// Check or uncheck every item in the columns list (visual only).
|
||||
fn columns_check_all(&self, checked: bool) {
|
||||
let list = self.columns_list;
|
||||
for i in 0..list.clb_count() {
|
||||
list.clb_set_checked(i, checked);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reset the columns list to the default-visible set (visual only).
|
||||
fn columns_reset_defaults(&self) {
|
||||
let list = self.columns_list;
|
||||
for (i, c) in Self::selectable_columns().iter().enumerate() {
|
||||
list.clb_set_checked(i, DEFAULT_VISIBLE.contains(c));
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_columns(&mut self) {
|
||||
let list = self.columns_list;
|
||||
for (i, c) in Self::selectable_columns().iter().enumerate() {
|
||||
if list.clb_checked(i) {
|
||||
self.view.visible.insert(*c);
|
||||
} else {
|
||||
self.view.visible.remove(c);
|
||||
let base = Self::selectable_columns();
|
||||
let order = self.columns_list.rearrange_get_order();
|
||||
let mut new_order: Vec<Column> = vec![Column::Ip];
|
||||
let mut visible: HashSet<Column> = HashSet::from([Column::Ip]);
|
||||
for entry in order {
|
||||
let (idx, checked) = if entry < 0 { ((!entry) as usize, false) } else { (entry as usize, true) };
|
||||
if let Some(&c) = base.get(idx) {
|
||||
new_order.push(c);
|
||||
if checked {
|
||||
visible.insert(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
// keep sort column visible-ish: drop sort if hidden
|
||||
// Only accept a full permutation (no dropped/duplicated columns); apply
|
||||
// order + visibility together so they never desync.
|
||||
if new_order.len() == self.view.order.len() {
|
||||
self.view.order = new_order;
|
||||
self.view.visible = visible;
|
||||
}
|
||||
// Drop the sort if its column was hidden (IP is always shown).
|
||||
if let Some((c, _)) = self.view.sort {
|
||||
if !self.view.visible.contains(&c) {
|
||||
if c != Column::Ip && !self.view.visible.contains(&c) {
|
||||
self.view.sort = None;
|
||||
}
|
||||
}
|
||||
@@ -536,8 +635,8 @@ impl App {
|
||||
let mut lists = Vec::new();
|
||||
for c in self.view.display_columns() {
|
||||
// Value checklists only make sense for categorical columns; skip the
|
||||
// checkbox column and continuous numeric metrics.
|
||||
if c == Column::Sel || c.is_numeric() {
|
||||
// continuous numeric metrics.
|
||||
if c.is_numeric() {
|
||||
continue;
|
||||
}
|
||||
let mut values: Vec<String> = self.rows.iter().map(|r| c.cell(r)).collect();
|
||||
@@ -640,18 +739,32 @@ 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_COLUMNS_ALL => self.columns_check_all(true),
|
||||
ID_COLUMNS_NONE => self.columns_check_all(false),
|
||||
ID_COLUMNS_RESET => self.columns_reset_defaults(),
|
||||
ID_FILTER => return Some(self.build_filter_dialog()),
|
||||
ID_FILTER_OK => self.apply_filter(),
|
||||
ID_FILTER_CANCEL => self.filter_dialog.close(0),
|
||||
ID_FILTER_RESET => self.reset_filters(),
|
||||
ID_RESCAN => {
|
||||
let ranges = scan::load_ranges();
|
||||
self.scan_rx = Some(scan::start_scan(ranges));
|
||||
self.scanning = true;
|
||||
wx_rs::set_status_text("scanning...");
|
||||
ID_PLAY => {
|
||||
// Resume/start the scan loop: scan now (unless one is
|
||||
// already running) + auto-rescan on.
|
||||
self.playing = true;
|
||||
if !self.scanning {
|
||||
self.start_new_scan();
|
||||
}
|
||||
}
|
||||
ID_PAUSE => {
|
||||
// Stop the auto-rescan loop (a scan in flight finishes).
|
||||
self.playing = false;
|
||||
wx_rs::set_status_text(&format!("{} miners - paused", self.rows.len()));
|
||||
}
|
||||
ID_STOP => {
|
||||
// Halt the loop and drop any in-flight scan.
|
||||
self.playing = false;
|
||||
self.countdown = 0;
|
||||
self.scanning = false;
|
||||
self.scan_rx = None;
|
||||
self.progress.show(false);
|
||||
self.table_parent.layout();
|
||||
wx_rs::set_status_text(&format!("{} miners - stopped", self.rows.len()));
|
||||
}
|
||||
_ if (ID_FILTER_ALL_BASE..ID_FILTER_NONE_BASE).contains(&id) => {
|
||||
self.filter_check_all((id - ID_FILTER_ALL_BASE) as usize, true);
|
||||
@@ -663,10 +776,10 @@ impl App {
|
||||
}
|
||||
}
|
||||
WxEventKind::DvlcHeaderClick => self.header_click(ev.p1 as usize),
|
||||
WxEventKind::DvlcValueChanged => self.toggle_select(ev.p1 as usize, ev.p2 as usize),
|
||||
WxEventKind::DvlcSelectionChanged => self.on_selection_changed(),
|
||||
WxEventKind::DvlcActivated => self.activate_row(ev.p1 as usize),
|
||||
WxEventKind::DvlcReordered => self.column_reordered(),
|
||||
WxEventKind::TimerTick if ev.p1 as i32 == TIMER_SCAN => self.drain_scan(),
|
||||
WxEventKind::TimerTick if ev.p1 as i32 == TIMER_SCAN => self.tick(),
|
||||
_ => {}
|
||||
}
|
||||
None
|
||||
@@ -720,7 +833,7 @@ impl App {
|
||||
let mut mismatches = 0;
|
||||
for (disp_row, &ri) in self.view_idx.iter().enumerate() {
|
||||
let r = &self.rows[ri];
|
||||
for (j, c) in cols.iter().enumerate().skip(1) {
|
||||
for (j, c) in cols.iter().enumerate() {
|
||||
let want = c.cell(r);
|
||||
let got = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
|
||||
if got != want {
|
||||
@@ -760,8 +873,13 @@ impl App {
|
||||
} else {
|
||||
check("S17 (.112) present", false, "row not found".into());
|
||||
}
|
||||
check("IP is the first text column", ip_col == Some(1),
|
||||
check("IP is the first column", ip_col == Some(0),
|
||||
format!("ip col index = {ip_col:?}"));
|
||||
// default view is IP-ascending
|
||||
let ips: Vec<String> = self.view_idx.iter().map(|&ri| self.rows[ri].ip.clone()).collect();
|
||||
let mut sorted = ips.clone();
|
||||
sorted.sort();
|
||||
check("default sort is IP ascending", ips == sorted, String::new());
|
||||
|
||||
ok
|
||||
}
|
||||
|
||||
+14
-2
@@ -1,6 +1,5 @@
|
||||
--- a/build.rs
|
||||
+++ b/build.rs
|
||||
+++ wx-rs-0.2.0-patched/build.rs 2026-09-15 12:56:37.552254500 -0600
|
||||
@@ -24,8 +24,14 @@
|
||||
cfg!(target_os = "macos")
|
||||
}
|
||||
@@ -52,7 +51,7 @@
|
||||
if is_windows() {
|
||||
build_msvc(wx_path)?;
|
||||
} else {
|
||||
@@ -217,6 +232,46 @@
|
||||
@@ -217,6 +232,59 @@
|
||||
)?)
|
||||
}
|
||||
|
||||
@@ -65,6 +64,16 @@
|
||||
+ Command::new(&wxconfig).arg("--cxxflags").output()?.stdout,
|
||||
+ )?;
|
||||
+ let libs = String::from_utf8(Command::new(&wxconfig).arg("--libs").output()?.stdout)?;
|
||||
+ // The widget bridge uses GTK directly (zebra-striping CSS), so add GTK's own
|
||||
+ // include paths. Best-effort: if pkg-config or gtk3-dev is missing the flags
|
||||
+ // are simply empty and the GTK-only code stays disabled.
|
||||
+ let gtk_cflags = Command::new("pkg-config")
|
||||
+ .args(["--cflags", "gtk+-3.0"])
|
||||
+ .output()
|
||||
+ .ok()
|
||||
+ .filter(|o| o.status.success())
|
||||
+ .and_then(|o| String::from_utf8(o.stdout).ok())
|
||||
+ .unwrap_or_default();
|
||||
+
|
||||
+ let mut build = cc::Build::new();
|
||||
+ build.cpp(true)
|
||||
@@ -73,6 +82,9 @@
|
||||
+ for f in cxxflags.split_whitespace() {
|
||||
+ build.flag(f);
|
||||
+ }
|
||||
+ for f in gtk_cflags.split_whitespace() {
|
||||
+ build.flag(f);
|
||||
+ }
|
||||
+ build.compile("wxbridge");
|
||||
+
|
||||
+ for flag in libs.split_whitespace() {
|
||||
|
||||
+89
-1
@@ -10,7 +10,7 @@
|
||||
+pub use widgets::*;
|
||||
--- a/src/widgets.rs
|
||||
+++ b/src/widgets.rs
|
||||
@@ -0,0 +1,473 @@
|
||||
@@ -0,0 +1,561 @@
|
||||
+// 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).
|
||||
@@ -69,10 +69,21 @@
|
||||
+ 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_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;
|
||||
+ pub fn wxbr_dvlc_selected_row(win: *mut c_void) -> c_long;
|
||||
+ pub fn wxbr_dvlc_select_row(win: *mut c_void, row: c_long);
|
||||
+ pub fn wxbr_dvlc_get_selections(win: *mut c_void, buf: *mut c_int, cap: c_int) -> 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_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||
+ pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
+ pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
+ pub fn wxbr_menu_new() -> *mut c_void;
|
||||
+ pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
+ pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
+ pub fn wxbr_popup_menu(win: *mut c_void, menu: *mut c_void);
|
||||
+ pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
|
||||
+ pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
|
||||
+ pub fn wxbr_gauge_set_range(win: *mut c_void, range: c_int);
|
||||
@@ -115,6 +126,9 @@
|
||||
+ DvlcReordered,
|
||||
+ TimerTick,
|
||||
+ DvlcActivated,
|
||||
+ DvlcSelectionChanged,
|
||||
+ DvlcContextMenu,
|
||||
+ MenuItem,
|
||||
+}
|
||||
+
|
||||
+impl WxEventKind {
|
||||
@@ -127,11 +141,19 @@
|
||||
+ 6 => WxEventKind::DvlcReordered,
|
||||
+ 7 => WxEventKind::TimerTick,
|
||||
+ 8 => WxEventKind::DvlcActivated,
|
||||
+ 9 => WxEventKind::DvlcSelectionChanged,
|
||||
+ 10 => WxEventKind::DvlcContextMenu,
|
||||
+ 11 => WxEventKind::MenuItem,
|
||||
+ _ => return None,
|
||||
+ })
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/// Apply app-wide zebra striping to tree/list views (GTK CSS; no-op elsewhere).
|
||||
+pub fn apply_zebra_css(r: u8, g: u8, b: u8) {
|
||||
+ unsafe { notsafe::wxbr_apply_zebra_css(r as c_int, g as c_int, b as c_int) }
|
||||
+}
|
||||
+
|
||||
+/// Open a URL in the system default browser. Returns true on success.
|
||||
+pub fn launch_browser(url: &str) -> bool {
|
||||
+ let c = CString::new(url).unwrap_or_default();
|
||||
@@ -431,6 +453,72 @@
|
||||
+ unsafe { notsafe::wxbr_dvlc_select_row(self.0, row as c_long) }
|
||||
+ }
|
||||
+
|
||||
+ /// The selected row indices (multi-select).
|
||||
+ pub fn dvlc_get_selections(&self) -> Vec<usize> {
|
||||
+ let mut buf = vec![0i32; 8192];
|
||||
+ let n = unsafe {
|
||||
+ notsafe::wxbr_dvlc_get_selections(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
+ };
|
||||
+ buf.into_iter().take(n.max(0) as usize).map(|v| v as usize).collect()
|
||||
+ }
|
||||
+
|
||||
+ /// Replace the selection with the given row indices.
|
||||
+ pub fn dvlc_select_rows(&self, rows: &[usize]) {
|
||||
+ let v: Vec<c_int> = rows.iter().map(|&r| r as c_int).collect();
|
||||
+ unsafe { notsafe::wxbr_dvlc_select_rows(self.0, v.as_ptr(), v.len() as c_int) }
|
||||
+ }
|
||||
+
|
||||
+ pub fn dvlc_set_alt_row_color(&self, r: u8, g: u8, b: u8) {
|
||||
+ unsafe { notsafe::wxbr_dvlc_set_alt_row_color(self.0, r as c_int, g as c_int, b as c_int) }
|
||||
+ }
|
||||
+
|
||||
+ // ---- rearrangeable check-list ----
|
||||
+
|
||||
+ /// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||
+ /// >= 0 is item `v` (checked); `!v` (negative) is item `v` unchecked.
|
||||
+ pub fn rearrange_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
|
||||
+ let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
|
||||
+ let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
|
||||
+ Widget(unsafe {
|
||||
+ notsafe::wxbr_rearrange_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
+ })
|
||||
+ }
|
||||
+
|
||||
+ /// Read back the current order (same wx encoding as `rearrange_list`).
|
||||
+ pub fn rearrange_get_order(&self) -> Vec<i32> {
|
||||
+ let mut buf = vec![0i32; 4096];
|
||||
+ let n = unsafe {
|
||||
+ notsafe::wxbr_rearrange_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
+ };
|
||||
+ buf.into_iter().take(n.max(0) as usize).collect()
|
||||
+ }
|
||||
+
|
||||
+ // ---- popup menu ----
|
||||
+
|
||||
+ pub fn menu_new() -> Widget {
|
||||
+ Widget(unsafe { notsafe::wxbr_menu_new() })
|
||||
+ }
|
||||
+
|
||||
+ pub fn menu_append(&self, id: i32, label: &str) {
|
||||
+ let c = CString::new(label).unwrap_or_default();
|
||||
+ unsafe { notsafe::wxbr_menu_append(self.0, id, c.as_ptr()) }
|
||||
+ }
|
||||
+
|
||||
+ pub fn menu_append_separator(&self) {
|
||||
+ unsafe { notsafe::wxbr_menu_append_separator(self.0) }
|
||||
+ }
|
||||
+
|
||||
+ /// Show `menu` as a popup on this window; blocks until dismissed.
|
||||
+ pub fn popup_menu(&self, menu: Widget) {
|
||||
+ unsafe { notsafe::wxbr_popup_menu(self.0, menu.0) }
|
||||
+ }
|
||||
+
|
||||
+ /// Update a column's header text in place (creation index).
|
||||
+ pub fn dvlc_set_col_title(&self, col: usize, title: &str) {
|
||||
+ let c = CString::new(title).unwrap_or_default();
|
||||
+ unsafe { notsafe::wxbr_dvlc_set_col_title(self.0, col as c_int, c.as_ptr()) }
|
||||
+ }
|
||||
+
|
||||
+ /// Show or clear the native sort arrow on a column (creation index).
|
||||
+ pub fn dvlc_set_sort_indicator(&self, col: usize, active: bool, ascending: bool) {
|
||||
+ unsafe {
|
||||
|
||||
+126
-10
@@ -1,6 +1,6 @@
|
||||
--- a/cpp_src/widgets_bridge.cpp
|
||||
+++ b/cpp_src/widgets_bridge.cpp
|
||||
@@ -0,0 +1,482 @@
|
||||
@@ -0,0 +1,598 @@
|
||||
+// 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).
|
||||
@@ -21,6 +21,12 @@
|
||||
+#include <wx/settings.h>
|
||||
+#include <wx/utils.h>
|
||||
+#include <wx/app.h>
|
||||
+#include <wx/rearrangectrl.h>
|
||||
+#include <wx/menu.h>
|
||||
+#ifdef __WXGTK__
|
||||
+#include <gtk/gtk.h>
|
||||
+#endif
|
||||
+#include <cstdio>
|
||||
+
|
||||
+typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
||||
+static WxWidgetEventFn g_widget_event = nullptr;
|
||||
@@ -34,6 +40,9 @@
|
||||
+ WxEV_DVLC_REORDERED = 6,
|
||||
+ WxEV_TIMER_TICK = 7,
|
||||
+ WxEV_DVLC_ACTIVATED = 8,
|
||||
+ WxEV_DVLC_SELECTION_CHANGED = 9,
|
||||
+ WxEV_DVLC_CONTEXT_MENU = 10,
|
||||
+ WxEV_MENU_ITEM = 11,
|
||||
+};
|
||||
+
|
||||
+extern "C" {
|
||||
@@ -261,9 +270,17 @@
|
||||
+// ---- data view list ctrl ------------------------------------------------------
|
||||
+
|
||||
+void* wxbr_dvlc(void* parent) {
|
||||
+ // Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
|
||||
+ // checkbox column.
|
||||
+ wxDataViewListCtrl* lc =
|
||||
+ new wxDataViewListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
+ wxSize(-1, -1), wxDV_ROW_LINES);
|
||||
+ wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
|
||||
+ lc->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||
+ });
|
||||
+ lc->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent&) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_CONTEXT_MENU, 0, 0);
|
||||
+ });
|
||||
+ lc->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& e) {
|
||||
+ if (g_widget_event) {
|
||||
+ wxDataViewListCtrl* lc =
|
||||
@@ -312,16 +329,10 @@
|
||||
+}
|
||||
+
|
||||
+void wxbr_dvlc_append_row(void* win, int nvals, const char** vals) {
|
||||
+ // All columns are text now (row selection replaced the checkbox column).
|
||||
+ wxVector<wxVariant> values;
|
||||
+ for (int i = 0; i < nvals; i++) {
|
||||
+ if (i == 0)
|
||||
+ // toggle column (checkbox): vals[0] carries the checked state as "1"/"0"
|
||||
+ // so a refresh preserves the row selection instead of clearing it.
|
||||
+ values.push_back(wxVariant(vals[0] && vals[0][0] == '1'));
|
||||
+ else if (vals[i])
|
||||
+ values.push_back(wxVariant(wxString::FromUTF8(vals[i])));
|
||||
+ else
|
||||
+ values.push_back(wxVariant(wxT("")));
|
||||
+ values.push_back(wxVariant(vals[i] ? wxString::FromUTF8(vals[i]) : wxString()));
|
||||
+ }
|
||||
+ ((wxDataViewListCtrl*)win)->AppendItem(values);
|
||||
+}
|
||||
@@ -361,6 +372,15 @@
|
||||
+ return (int)((wxDataViewListCtrl*)win)->GetColumnCount();
|
||||
+}
|
||||
+
|
||||
+// 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) {
|
||||
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
|
||||
+ if (col < 0 || (unsigned)col >= dv->GetColumnCount()) return;
|
||||
+ wxDataViewColumn* c = dv->GetColumn(col);
|
||||
+ if (c) c->SetTitle(wxString::FromUTF8(title));
|
||||
+}
|
||||
+
|
||||
+// Show/clear the native sort arrow on a column (creation index). The app does
|
||||
+// its own sorting; this only draws the indicator so the header shows which
|
||||
+// column is the sort key and in which direction.
|
||||
@@ -392,6 +412,52 @@
|
||||
+ return (long)((wxDataViewListCtrl*)win)->GetSelectedRow();
|
||||
+}
|
||||
+
|
||||
+// Fill `buf` with the selected row indices (multi-select); returns the count.
|
||||
+int wxbr_dvlc_get_selections(void* win, int* buf, int cap) {
|
||||
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
|
||||
+ wxDataViewItemArray items;
|
||||
+ int n = (int)lc->GetSelections(items);
|
||||
+ int out = 0;
|
||||
+ for (int i = 0; i < n && out < cap; i++) {
|
||||
+ int row = lc->GetStore()->GetRow(items[i]);
|
||||
+ if (row >= 0) buf[out++] = row;
|
||||
+ }
|
||||
+ return out;
|
||||
+}
|
||||
+
|
||||
+void wxbr_dvlc_select_rows(void* win, const int* rows, int n) {
|
||||
+ wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
|
||||
+ lc->UnselectAll();
|
||||
+ for (int i = 0; i < n; i++) {
|
||||
+ if (rows[i] >= 0) lc->SelectRow((unsigned)rows[i]);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void wxbr_dvlc_set_alt_row_color(void* win, int r, int g, int b) {
|
||||
+ // No-op on GTK (native dataview lacks it); see wxbr_apply_zebra_css.
|
||||
+ ((wxDataViewListCtrl*)win)->SetAlternateRowColour(wxColour(r, g, b));
|
||||
+}
|
||||
+
|
||||
+// GTK's native dataview does not implement SetAlternateRowColour, so apply
|
||||
+// zebra striping app-wide via a CSS provider (GTK 3.20+ supports :nth-child on
|
||||
+// treeview rows). No-op off GTK.
|
||||
+void wxbr_apply_zebra_css(int r, int g, int b) {
|
||||
+#ifdef __WXGTK__
|
||||
+ GtkCssProvider* p = gtk_css_provider_new();
|
||||
+ char css[192];
|
||||
+ std::snprintf(css, sizeof(css),
|
||||
+ "treeview.view:nth-child(even){background-color:rgb(%d,%d,%d);}",
|
||||
+ r, g, b);
|
||||
+ gtk_css_provider_load_from_data(p, css, -1, NULL);
|
||||
+ gtk_style_context_add_provider_for_screen(
|
||||
+ gdk_screen_get_default(), GTK_STYLE_PROVIDER(p),
|
||||
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
+ g_object_unref(p);
|
||||
+#else
|
||||
+ (void)r; (void)g; (void)b;
|
||||
+#endif
|
||||
+}
|
||||
+
|
||||
+void wxbr_dvlc_select_row(void* win, long row) {
|
||||
+ if (row < 0) return;
|
||||
+ ((wxDataViewListCtrl*)win)->SelectRow((unsigned)row);
|
||||
@@ -478,6 +544,56 @@
|
||||
+ ((wxWindow*)win)->SetForegroundColour(wxColour(r, g, b));
|
||||
+}
|
||||
+
|
||||
+// ---- rearrangeable check-list (Choose columns, drag/reorder + check) ---------
|
||||
+
|
||||
+// order[i] encodes the item at display position i: value v >= 0 means original
|
||||
+// item v, checked; a negative value ~v means original item v, unchecked.
|
||||
+void* wxbr_rearrange_list(void* parent, int n, const int* order, const char** items) {
|
||||
+ wxArrayInt aorder;
|
||||
+ wxArrayString aitems;
|
||||
+ for (int i = 0; i < n; i++) {
|
||||
+ aorder.Add(order[i]);
|
||||
+ aitems.Add(wxString::FromUTF8(items[i]));
|
||||
+ }
|
||||
+ wxRearrangeCtrl* ctrl =
|
||||
+ new wxRearrangeCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
+ wxSize(-1, -1), aorder, aitems);
|
||||
+ return (void*)ctrl;
|
||||
+}
|
||||
+
|
||||
+// Read back the current order (same encoding as above) into buf; returns count.
|
||||
+int wxbr_rearrange_get_order(void* win, int* buf, int cap) {
|
||||
+ wxRearrangeCtrl* ctrl = (wxRearrangeCtrl*)win;
|
||||
+ const wxArrayInt& order = ctrl->GetList()->GetCurrentOrder();
|
||||
+ int n = (int)order.GetCount();
|
||||
+ for (int i = 0; i < n && i < cap; i++) buf[i] = order[i];
|
||||
+ return n < cap ? n : cap;
|
||||
+}
|
||||
+
|
||||
+// ---- popup menu (right-click context menu) ----------------------------------
|
||||
+
|
||||
+void* wxbr_menu_new() { return (void*)new wxMenu(); }
|
||||
+
|
||||
+void wxbr_menu_append(void* menu, int id, const char* label) {
|
||||
+ ((wxMenu*)menu)->Append(id, wxString::FromUTF8(label));
|
||||
+}
|
||||
+
|
||||
+void wxbr_menu_append_separator(void* menu) {
|
||||
+ ((wxMenu*)menu)->AppendSeparator();
|
||||
+}
|
||||
+
|
||||
+// Show the menu at the current mouse position on `win`; blocks until dismissed.
|
||||
+// The chosen item id is delivered via WxEV_MENU_ITEM before this returns.
|
||||
+void wxbr_popup_menu(void* win, void* menu) {
|
||||
+ wxWindow* w = (wxWindow*)win;
|
||||
+ wxMenu* m = (wxMenu*)menu;
|
||||
+ m->Bind(wxEVT_MENU, [](wxCommandEvent& e) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_MENU_ITEM, e.GetId(), 0);
|
||||
+ });
|
||||
+ w->PopupMenu(m);
|
||||
+ delete m;
|
||||
+}
|
||||
+
|
||||
+// ---- deferred destroy (safe from event handlers) ----------------------------
|
||||
+
|
||||
+void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
|
||||
|
||||
+13
@@ -241,6 +241,16 @@ fn build_linux() -> Result<(), Box<dyn Error>> {
|
||||
Command::new(&wxconfig).arg("--cxxflags").output()?.stdout,
|
||||
)?;
|
||||
let libs = String::from_utf8(Command::new(&wxconfig).arg("--libs").output()?.stdout)?;
|
||||
// The widget bridge uses GTK directly (zebra-striping CSS), so add GTK's own
|
||||
// include paths. Best-effort: if pkg-config or gtk3-dev is missing the flags
|
||||
// are simply empty and the GTK-only code stays disabled.
|
||||
let gtk_cflags = Command::new("pkg-config")
|
||||
.args(["--cflags", "gtk+-3.0"])
|
||||
.output()
|
||||
.ok()
|
||||
.filter(|o| o.status.success())
|
||||
.and_then(|o| String::from_utf8(o.stdout).ok())
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut build = cc::Build::new();
|
||||
build.cpp(true)
|
||||
@@ -249,6 +259,9 @@ fn build_linux() -> Result<(), Box<dyn Error>> {
|
||||
for f in cxxflags.split_whitespace() {
|
||||
build.flag(f);
|
||||
}
|
||||
for f in gtk_cflags.split_whitespace() {
|
||||
build.flag(f);
|
||||
}
|
||||
build.compile("wxbridge");
|
||||
|
||||
for flag in libs.split_whitespace() {
|
||||
|
||||
+116
-9
@@ -18,6 +18,12 @@
|
||||
#include <wx/settings.h>
|
||||
#include <wx/utils.h>
|
||||
#include <wx/app.h>
|
||||
#include <wx/rearrangectrl.h>
|
||||
#include <wx/menu.h>
|
||||
#ifdef __WXGTK__
|
||||
#include <gtk/gtk.h>
|
||||
#endif
|
||||
#include <cstdio>
|
||||
|
||||
typedef void (*WxWidgetEventFn)(int kind, long p1, long p2);
|
||||
static WxWidgetEventFn g_widget_event = nullptr;
|
||||
@@ -31,6 +37,9 @@ enum WxWidgetEventKind {
|
||||
WxEV_DVLC_REORDERED = 6,
|
||||
WxEV_TIMER_TICK = 7,
|
||||
WxEV_DVLC_ACTIVATED = 8,
|
||||
WxEV_DVLC_SELECTION_CHANGED = 9,
|
||||
WxEV_DVLC_CONTEXT_MENU = 10,
|
||||
WxEV_MENU_ITEM = 11,
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
@@ -258,9 +267,17 @@ void wxbr_dialog_close(void* win, int code) {
|
||||
// ---- data view list ctrl ------------------------------------------------------
|
||||
|
||||
void* wxbr_dvlc(void* parent) {
|
||||
// Multi-select (ctrl/shift-click) + row lines. Selection replaces the old
|
||||
// checkbox column.
|
||||
wxDataViewListCtrl* lc =
|
||||
new wxDataViewListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
wxSize(-1, -1), wxDV_ROW_LINES);
|
||||
wxSize(-1, -1), wxDV_ROW_LINES | wxDV_MULTIPLE);
|
||||
lc->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
|
||||
if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||
});
|
||||
lc->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent&) {
|
||||
if (g_widget_event) g_widget_event(WxEV_DVLC_CONTEXT_MENU, 0, 0);
|
||||
});
|
||||
lc->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& e) {
|
||||
if (g_widget_event) {
|
||||
wxDataViewListCtrl* lc =
|
||||
@@ -309,16 +326,10 @@ void wxbr_dvlc_append_toggle_col(void* win, int width) {
|
||||
}
|
||||
|
||||
void wxbr_dvlc_append_row(void* win, int nvals, const char** vals) {
|
||||
// All columns are text now (row selection replaced the checkbox column).
|
||||
wxVector<wxVariant> values;
|
||||
for (int i = 0; i < nvals; i++) {
|
||||
if (i == 0)
|
||||
// toggle column (checkbox): vals[0] carries the checked state as "1"/"0"
|
||||
// so a refresh preserves the row selection instead of clearing it.
|
||||
values.push_back(wxVariant(vals[0] && vals[0][0] == '1'));
|
||||
else if (vals[i])
|
||||
values.push_back(wxVariant(wxString::FromUTF8(vals[i])));
|
||||
else
|
||||
values.push_back(wxVariant(wxT("")));
|
||||
values.push_back(wxVariant(vals[i] ? wxString::FromUTF8(vals[i]) : wxString()));
|
||||
}
|
||||
((wxDataViewListCtrl*)win)->AppendItem(values);
|
||||
}
|
||||
@@ -398,6 +409,52 @@ long wxbr_dvlc_selected_row(void* win) {
|
||||
return (long)((wxDataViewListCtrl*)win)->GetSelectedRow();
|
||||
}
|
||||
|
||||
// Fill `buf` with the selected row indices (multi-select); returns the count.
|
||||
int wxbr_dvlc_get_selections(void* win, int* buf, int cap) {
|
||||
wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
|
||||
wxDataViewItemArray items;
|
||||
int n = (int)lc->GetSelections(items);
|
||||
int out = 0;
|
||||
for (int i = 0; i < n && out < cap; i++) {
|
||||
int row = lc->GetStore()->GetRow(items[i]);
|
||||
if (row >= 0) buf[out++] = row;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void wxbr_dvlc_select_rows(void* win, const int* rows, int n) {
|
||||
wxDataViewListCtrl* lc = (wxDataViewListCtrl*)win;
|
||||
lc->UnselectAll();
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (rows[i] >= 0) lc->SelectRow((unsigned)rows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void wxbr_dvlc_set_alt_row_color(void* win, int r, int g, int b) {
|
||||
// No-op on GTK (native dataview lacks it); see wxbr_apply_zebra_css.
|
||||
((wxDataViewListCtrl*)win)->SetAlternateRowColour(wxColour(r, g, b));
|
||||
}
|
||||
|
||||
// GTK's native dataview does not implement SetAlternateRowColour, so apply
|
||||
// zebra striping app-wide via a CSS provider (GTK 3.20+ supports :nth-child on
|
||||
// treeview rows). No-op off GTK.
|
||||
void wxbr_apply_zebra_css(int r, int g, int b) {
|
||||
#ifdef __WXGTK__
|
||||
GtkCssProvider* p = gtk_css_provider_new();
|
||||
char css[192];
|
||||
std::snprintf(css, sizeof(css),
|
||||
"treeview.view:nth-child(even){background-color:rgb(%d,%d,%d);}",
|
||||
r, g, b);
|
||||
gtk_css_provider_load_from_data(p, css, -1, NULL);
|
||||
gtk_style_context_add_provider_for_screen(
|
||||
gdk_screen_get_default(), GTK_STYLE_PROVIDER(p),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
g_object_unref(p);
|
||||
#else
|
||||
(void)r; (void)g; (void)b;
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxbr_dvlc_select_row(void* win, long row) {
|
||||
if (row < 0) return;
|
||||
((wxDataViewListCtrl*)win)->SelectRow((unsigned)row);
|
||||
@@ -484,6 +541,56 @@ void wxbr_set_fg(void* win, int r, int g, int b) {
|
||||
((wxWindow*)win)->SetForegroundColour(wxColour(r, g, b));
|
||||
}
|
||||
|
||||
// ---- rearrangeable check-list (Choose columns, drag/reorder + check) ---------
|
||||
|
||||
// order[i] encodes the item at display position i: value v >= 0 means original
|
||||
// item v, checked; a negative value ~v means original item v, unchecked.
|
||||
void* wxbr_rearrange_list(void* parent, int n, const int* order, const char** items) {
|
||||
wxArrayInt aorder;
|
||||
wxArrayString aitems;
|
||||
for (int i = 0; i < n; i++) {
|
||||
aorder.Add(order[i]);
|
||||
aitems.Add(wxString::FromUTF8(items[i]));
|
||||
}
|
||||
wxRearrangeCtrl* ctrl =
|
||||
new wxRearrangeCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
wxSize(-1, -1), aorder, aitems);
|
||||
return (void*)ctrl;
|
||||
}
|
||||
|
||||
// Read back the current order (same encoding as above) into buf; returns count.
|
||||
int wxbr_rearrange_get_order(void* win, int* buf, int cap) {
|
||||
wxRearrangeCtrl* ctrl = (wxRearrangeCtrl*)win;
|
||||
const wxArrayInt& order = ctrl->GetList()->GetCurrentOrder();
|
||||
int n = (int)order.GetCount();
|
||||
for (int i = 0; i < n && i < cap; i++) buf[i] = order[i];
|
||||
return n < cap ? n : cap;
|
||||
}
|
||||
|
||||
// ---- popup menu (right-click context menu) ----------------------------------
|
||||
|
||||
void* wxbr_menu_new() { return (void*)new wxMenu(); }
|
||||
|
||||
void wxbr_menu_append(void* menu, int id, const char* label) {
|
||||
((wxMenu*)menu)->Append(id, wxString::FromUTF8(label));
|
||||
}
|
||||
|
||||
void wxbr_menu_append_separator(void* menu) {
|
||||
((wxMenu*)menu)->AppendSeparator();
|
||||
}
|
||||
|
||||
// Show the menu at the current mouse position on `win`; blocks until dismissed.
|
||||
// The chosen item id is delivered via WxEV_MENU_ITEM before this returns.
|
||||
void wxbr_popup_menu(void* win, void* menu) {
|
||||
wxWindow* w = (wxWindow*)win;
|
||||
wxMenu* m = (wxMenu*)menu;
|
||||
m->Bind(wxEVT_MENU, [](wxCommandEvent& e) {
|
||||
if (g_widget_event) g_widget_event(WxEV_MENU_ITEM, e.GetId(), 0);
|
||||
});
|
||||
w->PopupMenu(m);
|
||||
delete m;
|
||||
}
|
||||
|
||||
// ---- deferred destroy (safe from event handlers) ----------------------------
|
||||
|
||||
void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
|
||||
|
||||
@@ -61,6 +61,16 @@ mod notsafe {
|
||||
pub fn wxbr_dvlc_col_at_pos(win: *mut c_void, pos: c_int) -> c_int;
|
||||
pub fn wxbr_dvlc_selected_row(win: *mut c_void) -> c_long;
|
||||
pub fn wxbr_dvlc_select_row(win: *mut c_void, row: c_long);
|
||||
pub fn wxbr_dvlc_get_selections(win: *mut c_void, buf: *mut c_int, cap: c_int) -> 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_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||
pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
pub fn wxbr_menu_new() -> *mut c_void;
|
||||
pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
pub fn wxbr_popup_menu(win: *mut c_void, menu: *mut c_void);
|
||||
pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
|
||||
pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
|
||||
pub fn wxbr_gauge_set_range(win: *mut c_void, range: c_int);
|
||||
@@ -103,6 +113,9 @@ pub enum WxEventKind {
|
||||
DvlcReordered,
|
||||
TimerTick,
|
||||
DvlcActivated,
|
||||
DvlcSelectionChanged,
|
||||
DvlcContextMenu,
|
||||
MenuItem,
|
||||
}
|
||||
|
||||
impl WxEventKind {
|
||||
@@ -115,11 +128,19 @@ impl WxEventKind {
|
||||
6 => WxEventKind::DvlcReordered,
|
||||
7 => WxEventKind::TimerTick,
|
||||
8 => WxEventKind::DvlcActivated,
|
||||
9 => WxEventKind::DvlcSelectionChanged,
|
||||
10 => WxEventKind::DvlcContextMenu,
|
||||
11 => WxEventKind::MenuItem,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply app-wide zebra striping to tree/list views (GTK CSS; no-op elsewhere).
|
||||
pub fn apply_zebra_css(r: u8, g: u8, b: u8) {
|
||||
unsafe { notsafe::wxbr_apply_zebra_css(r as c_int, g as c_int, b as c_int) }
|
||||
}
|
||||
|
||||
/// Open a URL in the system default browser. Returns true on success.
|
||||
pub fn launch_browser(url: &str) -> bool {
|
||||
let c = CString::new(url).unwrap_or_default();
|
||||
@@ -419,6 +440,66 @@ impl Widget {
|
||||
unsafe { notsafe::wxbr_dvlc_select_row(self.0, row as c_long) }
|
||||
}
|
||||
|
||||
/// The selected row indices (multi-select).
|
||||
pub fn dvlc_get_selections(&self) -> Vec<usize> {
|
||||
let mut buf = vec![0i32; 8192];
|
||||
let n = unsafe {
|
||||
notsafe::wxbr_dvlc_get_selections(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
};
|
||||
buf.into_iter().take(n.max(0) as usize).map(|v| v as usize).collect()
|
||||
}
|
||||
|
||||
/// Replace the selection with the given row indices.
|
||||
pub fn dvlc_select_rows(&self, rows: &[usize]) {
|
||||
let v: Vec<c_int> = rows.iter().map(|&r| r as c_int).collect();
|
||||
unsafe { notsafe::wxbr_dvlc_select_rows(self.0, v.as_ptr(), v.len() as c_int) }
|
||||
}
|
||||
|
||||
pub fn dvlc_set_alt_row_color(&self, r: u8, g: u8, b: u8) {
|
||||
unsafe { notsafe::wxbr_dvlc_set_alt_row_color(self.0, r as c_int, g as c_int, b as c_int) }
|
||||
}
|
||||
|
||||
// ---- rearrangeable check-list ----
|
||||
|
||||
/// Create a rearrangeable checklist. `order` uses wx encoding: a value `v`
|
||||
/// >= 0 is item `v` (checked); `!v` (negative) is item `v` unchecked.
|
||||
pub fn rearrange_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
|
||||
let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
|
||||
let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
|
||||
Widget(unsafe {
|
||||
notsafe::wxbr_rearrange_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
})
|
||||
}
|
||||
|
||||
/// Read back the current order (same wx encoding as `rearrange_list`).
|
||||
pub fn rearrange_get_order(&self) -> Vec<i32> {
|
||||
let mut buf = vec![0i32; 4096];
|
||||
let n = unsafe {
|
||||
notsafe::wxbr_rearrange_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
};
|
||||
buf.into_iter().take(n.max(0) as usize).collect()
|
||||
}
|
||||
|
||||
// ---- popup menu ----
|
||||
|
||||
pub fn menu_new() -> Widget {
|
||||
Widget(unsafe { notsafe::wxbr_menu_new() })
|
||||
}
|
||||
|
||||
pub fn menu_append(&self, id: i32, label: &str) {
|
||||
let c = CString::new(label).unwrap_or_default();
|
||||
unsafe { notsafe::wxbr_menu_append(self.0, id, c.as_ptr()) }
|
||||
}
|
||||
|
||||
pub fn menu_append_separator(&self) {
|
||||
unsafe { notsafe::wxbr_menu_append_separator(self.0) }
|
||||
}
|
||||
|
||||
/// Show `menu` as a popup on this window; blocks until dismissed.
|
||||
pub fn popup_menu(&self, menu: Widget) {
|
||||
unsafe { notsafe::wxbr_popup_menu(self.0, menu.0) }
|
||||
}
|
||||
|
||||
/// Update a column's header text in place (creation index).
|
||||
pub fn dvlc_set_col_title(&self, col: usize, title: &str) {
|
||||
let c = CString::new(title).unwrap_or_default();
|
||||
|
||||
Reference in New Issue
Block a user