Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b5d811b1e |
@@ -790,6 +790,16 @@ impl ViewState {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Every column available to filter on, independent of visibility: a filter
|
||||
/// matches a row by that column's cell text whether or not the column is
|
||||
/// shown, so (e.g.) Algorithm can be filtered without first un-hiding it.
|
||||
/// Ip first, then the registry order.
|
||||
pub fn filter_columns(&self) -> Vec<Column> {
|
||||
let mut v = vec![Column::Ip];
|
||||
v.extend(self.order.iter().copied().filter(|c| *c != Column::Ip));
|
||||
v
|
||||
}
|
||||
|
||||
pub fn is_fixed(&self, c: Column) -> bool {
|
||||
c == Column::Ip
|
||||
}
|
||||
@@ -859,6 +869,11 @@ pub struct Kpis {
|
||||
pub paused: usize,
|
||||
pub total_hashrate_ths: f64,
|
||||
pub total_power_w: f64,
|
||||
/// Per-algorithm hashrate totals (algorithm name, total TH/s), only for
|
||||
/// algorithms actually producing hashrate, ordered by total descending then
|
||||
/// name. The hashrate KPI card cycles through these when more than one
|
||||
/// algorithm is running in the fleet.
|
||||
pub hashrate_by_algo: Vec<(String, f64)>,
|
||||
}
|
||||
|
||||
pub fn compute_kpis(rows: &[MinerRow], view_idx: &[usize]) -> Kpis {
|
||||
@@ -870,7 +885,11 @@ pub fn compute_kpis(rows: &[MinerRow], view_idx: &[usize]) -> Kpis {
|
||||
paused: 0,
|
||||
total_hashrate_ths: 0.0,
|
||||
total_power_w: 0.0,
|
||||
hashrate_by_algo: Vec::new(),
|
||||
};
|
||||
// Accumulate per-algorithm totals in an insertion-ordered list (fleets have
|
||||
// a handful of algorithms at most, so a linear scan is cheaper than a map).
|
||||
let mut by_algo: Vec<(String, f64)> = Vec::new();
|
||||
for &i in view_idx {
|
||||
let r = &rows[i];
|
||||
// Bucket by the same precedence status() uses, so the KPI header can
|
||||
@@ -883,7 +902,19 @@ pub fn compute_kpis(rows: &[MinerRow], view_idx: &[usize]) -> Kpis {
|
||||
}
|
||||
k.total_hashrate_ths += r.hashrate_ths;
|
||||
k.total_power_w += r.power_w;
|
||||
if r.hashrate_ths > 0.0 {
|
||||
// Fall back to "SHA256" when a miner didn't report its algorithm, so
|
||||
// a producing miner is never dropped from the per-algorithm cycle.
|
||||
let algo = if r.algorithm.is_empty() { "SHA256" } else { r.algorithm.as_str() };
|
||||
match by_algo.iter_mut().find(|(a, _)| a == algo) {
|
||||
Some((_, t)) => *t += r.hashrate_ths,
|
||||
None => by_algo.push((algo.to_string(), r.hashrate_ths)),
|
||||
}
|
||||
}
|
||||
}
|
||||
// Stable order: largest total first, ties broken alphabetically.
|
||||
by_algo.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(std::cmp::Ordering::Equal).then(a.0.cmp(&b.0)));
|
||||
k.hashrate_by_algo = by_algo;
|
||||
k
|
||||
}
|
||||
|
||||
|
||||
+151
-26
@@ -40,6 +40,8 @@ const ID_KPI_HASHING: i32 = 150;
|
||||
const ID_KPI_SLOW: i32 = 151;
|
||||
const ID_KPI_NOT: i32 = 152;
|
||||
const ID_KPI_PAUSED: i32 = 153;
|
||||
// Click the hashrate KPI card to cycle through per-algorithm hashrate totals.
|
||||
const ID_KPI_HASHRATE: i32 = 154;
|
||||
// Right-click context-menu item ids.
|
||||
const ID_CTX_OPEN: i32 = 720;
|
||||
const ID_CTX_REFRESH: i32 = 732;
|
||||
@@ -108,6 +110,15 @@ 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
|
||||
}
|
||||
|
||||
/// Human-facing algorithm name for the hashrate KPI label. asic-rs renders the
|
||||
/// SHA-256 variant as "SHA256"; everything else already reads well as-is.
|
||||
fn pretty_algo(algo: &str) -> String {
|
||||
match algo {
|
||||
"SHA256" => "SHA-256".to_string(),
|
||||
other => other.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
@@ -286,6 +297,13 @@ pub struct App {
|
||||
kpi_not: Widget,
|
||||
kpi_paused: Widget,
|
||||
kpi_hashrate: Widget,
|
||||
// The hashrate card's caption label, retitled to "<Algo> Hashrate" as the
|
||||
// per-algorithm cycle advances (the card itself is re-laid-out with the rest
|
||||
// in refresh_kpis).
|
||||
kpi_hashrate_lbl: Widget,
|
||||
// Which per-algorithm total the hashrate card is currently showing; clicking
|
||||
// the card advances it, wrapping around the fleet's running algorithms.
|
||||
hashrate_algo_idx: usize,
|
||||
kpi_power: Widget,
|
||||
progress: Widget,
|
||||
pub table: Option<Widget>,
|
||||
@@ -310,10 +328,11 @@ pub struct App {
|
||||
pal: Palette,
|
||||
kpi_cards: Vec<(Widget, Widget, Widget, ColorKind)>,
|
||||
// The 4 status KPI cards that double as quick-filters: (status text, its
|
||||
// ButtonClicked id, its card panel -- for binding the click and for
|
||||
// tinting the active one). `active_kpi_filter` is set iff view.filters
|
||||
// holds exactly that single-value Status filter.
|
||||
kpi_filter_cards: [(&'static str, i32, Widget); 4],
|
||||
// ButtonClicked id, card panel, value text, label text). The three widgets
|
||||
// are all painted for the active-filter highlight (so the whole box tints,
|
||||
// not just the panel behind the text). `active_kpi_filter` is set iff
|
||||
// view.filters holds exactly that single-value Status filter.
|
||||
kpi_filter_cards: [(&'static str, i32, Widget, Widget, Widget); 4],
|
||||
active_kpi_filter: Option<&'static str>,
|
||||
// A context menu built on right-click, popped up outside the App borrow.
|
||||
pending_popup: Option<(Widget, Widget)>,
|
||||
@@ -398,17 +417,18 @@ pub fn build(frame: Widget) -> App {
|
||||
// KPI header: a row of equal-width cards, each a big value over a small
|
||||
// label. Health KPIs are colour-coded (green/amber/red); hashrate uses the
|
||||
// accent colour so totals stand apart from counts.
|
||||
// wrap_sizer (not box_sizer): at phone-ish widths the cards reflow onto a
|
||||
// second line instead of squeezing/clipping.
|
||||
let kpi_row = Widget::wrap_sizer(false);
|
||||
// Horizontal box sizer with every card at proportion 1 + EXPAND, so the
|
||||
// cards are always equal width AND grow to span the full window; a per-card
|
||||
// min size floors them at their largest content's width.
|
||||
let kpi_row = Widget::box_sizer(false);
|
||||
let mut kpi_cards: Vec<(Widget, Widget, Widget, ColorKind)> = Vec::new();
|
||||
let mut mk_card = |label: &str, kind: ColorKind| -> (Widget, Widget) {
|
||||
let vc = kind_color(&pal, kind);
|
||||
let card = Widget::panel(panel);
|
||||
card.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
|
||||
// Uniform size so every KPI box is identical regardless of its content
|
||||
// (wide enough for the largest value, e.g. "685 TH/s" / "21.3 kW").
|
||||
card.set_min_size(150, 62);
|
||||
// Min-content floor (the widest label/value); cards grow equally past
|
||||
// this to fill the window (proportion 1 + EXPAND on add).
|
||||
card.set_min_size(116, 62);
|
||||
let cs = Widget::box_sizer(true);
|
||||
let value = Widget::static_text(card, "0");
|
||||
value.set_font_size(19);
|
||||
@@ -433,7 +453,7 @@ pub fn build(frame: Widget) -> App {
|
||||
cs.add_sizer(centre(lbl), 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_BOTTOM | sf::BORDER_RIGHT, 8);
|
||||
cs.add_stretch(1);
|
||||
cs.set_sizer_on(card);
|
||||
kpi_row.add(card, 0, sf::BORDER_ALL, 4);
|
||||
kpi_row.add(card, 1, sf::EXPAND | sf::BORDER_ALL, 4);
|
||||
kpi_cards.push((card, value, lbl, kind));
|
||||
(card, value)
|
||||
};
|
||||
@@ -442,19 +462,37 @@ pub fn build(frame: Widget) -> App {
|
||||
let (card_slow, kpi_slow) = mk_card("Slow", ColorKind::Amber);
|
||||
let (card_not, kpi_not) = mk_card("Not hashing", ColorKind::Red);
|
||||
let (card_paused, kpi_paused) = mk_card("Paused", ColorKind::Blue);
|
||||
let (_card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Accent);
|
||||
let (card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Accent);
|
||||
let (_card_power, kpi_power) = mk_card("Est. power", ColorKind::Neutral);
|
||||
drop(mk_card);
|
||||
// The 4 status cards double as quick-filters: clicking one narrows the
|
||||
// table to that status (see `toggle_kpi_filter`).
|
||||
let kpi_filter_cards: [(&'static str, i32, Widget); 4] = [
|
||||
("hashing", ID_KPI_HASHING, card_hashing),
|
||||
("slow", ID_KPI_SLOW, card_slow),
|
||||
("not hashing", ID_KPI_NOT, card_not),
|
||||
("paused", ID_KPI_PAUSED, card_paused),
|
||||
let _ = (card_hashing, card_slow, card_not, card_paused);
|
||||
// The hashrate card is kpi_cards[5] in build order (Total, Hashing, Slow,
|
||||
// Not, Paused, Hashrate, Power); its caption is retitled per algorithm.
|
||||
let kpi_hashrate_lbl = kpi_cards[5].2;
|
||||
// The hashrate card cycles per-algorithm totals on click; bind the card and
|
||||
// both its texts (so a click on the number or the label registers too).
|
||||
card_hashrate.bind_click(ID_KPI_HASHRATE);
|
||||
kpi_hashrate.bind_click(ID_KPI_HASHRATE);
|
||||
kpi_hashrate_lbl.bind_click(ID_KPI_HASHRATE);
|
||||
// The 4 status cards double as quick-filters: clicking one narrows the table
|
||||
// to that status (see `toggle_kpi_filter`). They are kpi_cards[1..=4] in this
|
||||
// order. Bind the click on the card AND its value/label texts (a click on the
|
||||
// text must register too), and keep all three widgets so the highlight can
|
||||
// fill the whole box, not just the panel behind the text.
|
||||
let filter_ids = [
|
||||
("hashing", ID_KPI_HASHING),
|
||||
("slow", ID_KPI_SLOW),
|
||||
("not hashing", ID_KPI_NOT),
|
||||
("paused", ID_KPI_PAUSED),
|
||||
];
|
||||
for &(_, id, card) in &kpi_filter_cards {
|
||||
let mut kpi_filter_cards: [(&'static str, i32, Widget, Widget, Widget); 4] =
|
||||
[("", 0, panel, panel, panel); 4];
|
||||
for (i, &(status, id)) in filter_ids.iter().enumerate() {
|
||||
let (card, value, lbl, _) = kpi_cards[i + 1];
|
||||
card.bind_click(id);
|
||||
value.bind_click(id);
|
||||
lbl.bind_click(id);
|
||||
kpi_filter_cards[i] = (status, id, card, value, lbl);
|
||||
}
|
||||
root.add_sizer(kpi_row, 0, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
|
||||
@@ -498,8 +536,11 @@ pub fn build(frame: Widget) -> App {
|
||||
frame_sizer.set_sizer_on(frame);
|
||||
frame.set_min_size(640, 480);
|
||||
|
||||
// A status bar carries scan state (was an inline label).
|
||||
// A status bar carries scan state (was an inline label). A second,
|
||||
// colour-tinted field pinned to the bottom-right corner carries scan/apply
|
||||
// errors (red) and warnings (amber) so they don't overwrite the scan state.
|
||||
wx_rs::create_status_bar();
|
||||
wx_rs::status_indicator_init(frame);
|
||||
wx_rs::set_status_text("starting scan...");
|
||||
|
||||
// Repaint custom-coloured widgets when the OS switches light/dark.
|
||||
@@ -516,6 +557,8 @@ pub fn build(frame: Widget) -> App {
|
||||
kpi_not,
|
||||
kpi_paused,
|
||||
kpi_hashrate,
|
||||
kpi_hashrate_lbl,
|
||||
hashrate_algo_idx: 0,
|
||||
kpi_power,
|
||||
progress,
|
||||
table: None,
|
||||
@@ -747,9 +790,44 @@ impl App {
|
||||
self.kpi_slow.set_label(&k.slow.to_string());
|
||||
self.kpi_not.set_label(&k.not_hashing.to_string());
|
||||
self.kpi_paused.set_label(&k.paused.to_string());
|
||||
// No "/s" suffix on the KPI (per UI request): "685 TH", "1.2 PH".
|
||||
self.kpi_hashrate.set_label(&format_si(k.total_hashrate_ths * 1e12, "H"));
|
||||
// Hashrate KPI: no "/s" suffix (per UI request) -> "685 TH", "1.2 PH".
|
||||
// With a single algorithm running (the common case) the card shows that
|
||||
// algorithm's total under a "<Algo> Hashrate" caption; when several are
|
||||
// running, clicking the card cycles `hashrate_algo_idx` through them.
|
||||
let (algo_label, algo_ths) = if k.hashrate_by_algo.is_empty() {
|
||||
("SHA-256".to_string(), 0.0)
|
||||
} else {
|
||||
let i = self.hashrate_algo_idx % k.hashrate_by_algo.len();
|
||||
let (a, t) = &k.hashrate_by_algo[i];
|
||||
(pretty_algo(a), *t)
|
||||
};
|
||||
self.kpi_hashrate.set_label(&format_si(algo_ths * 1e12, "H"));
|
||||
self.kpi_hashrate_lbl.set_label(&format!("{algo_label} Hashrate"));
|
||||
self.kpi_power.set_label(&format_si(k.total_power_w, "W"));
|
||||
// set_label resizes the static text; re-run each card's sizer so the
|
||||
// centring spacers recompute around the new width (otherwise the value
|
||||
// drifts off-centre when a filter changes a count's digit width).
|
||||
for (card, _, _, _) in &self.kpi_cards {
|
||||
card.layout();
|
||||
}
|
||||
}
|
||||
|
||||
/// Show a scan/apply error (red) in the bottom-right status indicator,
|
||||
/// separate from the left-hand scan-status text.
|
||||
fn set_error_indicator(&self, msg: &str) {
|
||||
let c = self.pal.red;
|
||||
wx_rs::status_indicator_set(msg, c.0, c.1, c.2);
|
||||
}
|
||||
|
||||
/// Show a scan/apply warning (amber) in the bottom-right status indicator.
|
||||
fn set_warning_indicator(&self, msg: &str) {
|
||||
let c = self.pal.amber;
|
||||
wx_rs::status_indicator_set(msg, c.0, c.1, c.2);
|
||||
}
|
||||
|
||||
/// Clear the bottom-right status indicator.
|
||||
fn clear_indicator(&self) {
|
||||
wx_rs::status_indicator_set("", 0, 0, 0);
|
||||
}
|
||||
|
||||
/// Re-apply the theme palette to the KPI cards and table rows after the OS
|
||||
@@ -776,13 +854,29 @@ impl App {
|
||||
/// so the active quick-filter is visible at a glance; every other status
|
||||
/// card resets to the normal card background.
|
||||
fn highlight_kpi_filter(&self) {
|
||||
for &(status, _, card) in &self.kpi_filter_cards {
|
||||
for &(status, _, card, value, lbl) in &self.kpi_filter_cards {
|
||||
let bg = if Some(status) == self.active_kpi_filter {
|
||||
tint_toward(self.pal.card_bg, status_kind_color(&self.pal, status), 0.35)
|
||||
} else {
|
||||
self.pal.card_bg
|
||||
};
|
||||
// Paint the panel and both static texts so the whole box tints; a
|
||||
// static_text keeps its own background, so tinting only the card
|
||||
// would leave an untinted rectangle behind the number and label.
|
||||
card.set_bg(bg.0, bg.1, bg.2);
|
||||
value.set_bg(bg.0, bg.1, bg.2);
|
||||
lbl.set_bg(bg.0, bg.1, bg.2);
|
||||
}
|
||||
}
|
||||
|
||||
/// Click on the hashrate KPI card: advance to the next running algorithm's
|
||||
/// total (wrapping around). A no-op when fewer than two algorithms are
|
||||
/// running, since there is nothing to cycle to.
|
||||
fn cycle_hashrate_algo(&mut self) {
|
||||
let n = compute_kpis(&self.rows, &self.view_idx).hashrate_by_algo.len();
|
||||
if n > 1 {
|
||||
self.hashrate_algo_idx = (self.hashrate_algo_idx + 1) % n;
|
||||
self.refresh_kpis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,7 +902,7 @@ impl App {
|
||||
self.active_kpi_filter = match self.view.filters.get(&Column::Status) {
|
||||
Some(ColFilter::Values(set)) if set.len() == 1 => {
|
||||
let v = set.iter().next().map(String::as_str);
|
||||
self.kpi_filter_cards.iter().map(|&(s, _, _)| s).find(|&s| Some(s) == v)
|
||||
self.kpi_filter_cards.iter().map(|&(s, _, _, _, _)| s).find(|&s| Some(s) == v)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
@@ -919,6 +1013,9 @@ impl App {
|
||||
let msg = format!("applying {} to {} miner(s)...", action.label(), ips.len());
|
||||
self.action_targets = ips.clone();
|
||||
self.action = Some(scan::start_config_action(ips, action));
|
||||
// Clear any stale error/warning from a previous operation; the new
|
||||
// outcome repopulates the indicator when this action finishes.
|
||||
self.clear_indicator();
|
||||
wx_rs::set_status_text(&msg);
|
||||
}
|
||||
|
||||
@@ -1476,6 +1573,9 @@ impl App {
|
||||
let Some(h) = &self.action else { return };
|
||||
let mut status: Option<String> = None;
|
||||
let mut finished = false;
|
||||
// Bottom-right indicator to apply after the `h` borrow is released:
|
||||
// None = leave as-is, Some(None) = clear, Some(Some((is_error, msg))).
|
||||
let mut indicator: Option<Option<(bool, String)>> = None;
|
||||
loop {
|
||||
match h.rx.try_recv() {
|
||||
Ok(scan::ActionMsg::Started { total }) => {
|
||||
@@ -1498,6 +1598,15 @@ impl App {
|
||||
} else {
|
||||
format!("applied to {ok}/{total} miner(s), {} failed", total - ok)
|
||||
});
|
||||
// Surface the outcome in the bottom-right indicator: a total
|
||||
// failure is red, a partial failure amber, full success clears.
|
||||
indicator = Some(if total == 0 || ok == total {
|
||||
None
|
||||
} else if ok == 0 {
|
||||
Some((true, format!("apply failed on all {total} miner(s)")))
|
||||
} else {
|
||||
Some((false, format!("apply: {}/{total} miner(s) failed", total - ok)))
|
||||
});
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
@@ -1527,6 +1636,14 @@ impl App {
|
||||
self.start_refresh(targets);
|
||||
}
|
||||
}
|
||||
// Apply the captured indicator now the `h` borrow is gone.
|
||||
if let Some(ind) = indicator {
|
||||
match ind {
|
||||
None => self.clear_indicator(),
|
||||
Some((true, msg)) => self.set_error_indicator(&msg),
|
||||
Some((false, msg)) => self.set_warning_indicator(&msg),
|
||||
}
|
||||
}
|
||||
if let Some(s) = status {
|
||||
wx_rs::set_status_text(&s);
|
||||
}
|
||||
@@ -1600,6 +1717,8 @@ impl App {
|
||||
self.progress.gauge_set_value(0);
|
||||
self.progress.show(true);
|
||||
self.table_parent.layout();
|
||||
// A fresh scan supersedes any prior error/warning.
|
||||
wx_rs::status_indicator_set("", 0, 0, 0);
|
||||
wx_rs::set_status_text(&format!("scanning {total} addresses..."));
|
||||
}
|
||||
Ok(ScanMsg::Progress { done, total, ip }) => {
|
||||
@@ -1631,6 +1750,9 @@ impl App {
|
||||
self.progress.show(false);
|
||||
self.table_parent.layout();
|
||||
wx_rs::set_status_text(&format!("scan failed: {e}"));
|
||||
// Surface the failure in the bottom-right indicator (red).
|
||||
let c = self.pal.red;
|
||||
wx_rs::status_indicator_set(&format!("scan failed: {e}"), c.0, c.1, c.2);
|
||||
self.countdown = if self.playing { self.auto_secs } else { 0 };
|
||||
}
|
||||
Err(std::sync::mpsc::TryRecvError::Empty) => break,
|
||||
@@ -2155,7 +2277,9 @@ impl App {
|
||||
let dlg = Widget::dialog(frame, "Filter");
|
||||
let root = Widget::box_sizer(true);
|
||||
|
||||
self.filter_cols = self.view.display_columns();
|
||||
// Offer every column (not just the visible ones) so any metric --
|
||||
// Algorithm included -- can be filtered without first un-hiding it.
|
||||
self.filter_cols = self.view.filter_columns();
|
||||
self.filter_working = self.view.filters.clone();
|
||||
self.filter_cur = 0;
|
||||
|
||||
@@ -2462,6 +2586,7 @@ impl App {
|
||||
ID_KPI_SLOW => self.toggle_kpi_filter("slow"),
|
||||
ID_KPI_NOT => self.toggle_kpi_filter("not hashing"),
|
||||
ID_KPI_PAUSED => self.toggle_kpi_filter("paused"),
|
||||
ID_KPI_HASHRATE => self.cycle_hashrate_algo(),
|
||||
ID_PLAY => {
|
||||
// Resume/start the scan loop: scan now (unless one is
|
||||
// already running) + auto-rescan on.
|
||||
|
||||
+18
-1
@@ -10,7 +10,7 @@
|
||||
+pub use widgets::*;
|
||||
--- a/src/widgets.rs
|
||||
+++ b/src/widgets.rs
|
||||
@@ -0,0 +1,728 @@
|
||||
@@ -0,0 +1,745 @@
|
||||
+// 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).
|
||||
@@ -116,6 +116,8 @@
|
||||
+ pub fn wxbr_destroy(win: *mut c_void);
|
||||
+ pub fn wxbr_destroy_children(win: *mut c_void);
|
||||
+ pub fn wxbr_call_after(id: c_int);
|
||||
+ pub fn wxbr_status_indicator_init(frame: *mut c_void);
|
||||
+ pub fn wxbr_status_indicator_set(text: *const c_char, r: c_int, g: c_int, b: c_int);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
@@ -188,6 +190,21 @@
|
||||
+ unsafe { notsafe::wxbr_call_after(id as c_int) }
|
||||
+}
|
||||
+
|
||||
+/// Reconfigure the frame's status bar to two fields and attach a colour-tinted
|
||||
+/// label pinned to the right-hand field (bottom-right corner). Call once after
|
||||
+/// `create_status_bar()`. The main scan status keeps using the left field via
|
||||
+/// the upstream `set_status_text` path.
|
||||
+pub fn status_indicator_init(frame: Widget) {
|
||||
+ unsafe { notsafe::wxbr_status_indicator_init(frame.0) }
|
||||
+}
|
||||
+
|
||||
+/// Set the bottom-right status indicator's text and colour (an empty string
|
||||
+/// clears it). Used for scan/apply errors (red) and warnings (amber).
|
||||
+pub fn status_indicator_set(text: &str, r: u8, g: u8, b: u8) {
|
||||
+ let c = CString::new(text).unwrap_or_default();
|
||||
+ unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), 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();
|
||||
|
||||
+51
-1
@@ -1,6 +1,6 @@
|
||||
--- a/cpp_src/widgets_bridge.cpp
|
||||
+++ b/cpp_src/widgets_bridge.cpp
|
||||
@@ -0,0 +1,1083 @@
|
||||
@@ -0,0 +1,1133 @@
|
||||
+// 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).
|
||||
@@ -32,6 +32,7 @@
|
||||
+#include <wx/graphics.h>
|
||||
+#include <wx/wrapsizer.h>
|
||||
+#include <wx/filedlg.h>
|
||||
+#include <wx/statusbr.h>
|
||||
+#include <cstring>
|
||||
+#include <cstdio>
|
||||
+#include <map>
|
||||
@@ -1075,6 +1076,55 @@
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// ---- status-bar error/warning indicator -------------------------------------
|
||||
+// A colour-tinted static text pinned to the RIGHT-hand field of the frame's
|
||||
+// status bar, so scan/apply errors surface in the bottom-right corner without
|
||||
+// overwriting the main (left) scan-status text. The status bar is reconfigured
|
||||
+// to two fields: field 0 (stretch) carries the scan status set via the upstream
|
||||
+// SetStatusText path; field 1 (fixed) hosts this coloured label, which we
|
||||
+// reposition into that field's rect whenever the bar is resized.
|
||||
+static wxStaticText* g_status_indicator = nullptr;
|
||||
+
|
||||
+static void reposition_status_indicator() {
|
||||
+ if (!g_status_indicator) return;
|
||||
+ wxStatusBar* sb = wxDynamicCast(g_status_indicator->GetParent(), wxStatusBar);
|
||||
+ if (!sb) return;
|
||||
+ wxRect r;
|
||||
+ if (!sb->GetFieldRect(1, r)) return;
|
||||
+ wxSize best = g_status_indicator->GetBestSize();
|
||||
+ int h = best.GetHeight();
|
||||
+ int y = r.y + (r.height - h) / 2;
|
||||
+ g_status_indicator->SetSize(r.x + 4, y, r.width - 8, h);
|
||||
+}
|
||||
+
|
||||
+void wxbr_status_indicator_init(void* frame_ptr) {
|
||||
+ wxFrame* frame = (wxFrame*)frame_ptr;
|
||||
+ wxStatusBar* sb = frame->GetStatusBar();
|
||||
+ if (!sb) sb = frame->CreateStatusBar();
|
||||
+ int widths[2] = { -1, 340 };
|
||||
+ sb->SetFieldsCount(2);
|
||||
+ sb->SetStatusWidths(2, widths);
|
||||
+ if (!g_status_indicator) {
|
||||
+ g_status_indicator = new wxStaticText(sb, wxID_ANY, wxEmptyString,
|
||||
+ wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
|
||||
+ sb->Bind(wxEVT_SIZE, [](wxSizeEvent& ev) {
|
||||
+ reposition_status_indicator();
|
||||
+ ev.Skip();
|
||||
+ });
|
||||
+ }
|
||||
+ reposition_status_indicator();
|
||||
+}
|
||||
+
|
||||
+// Set the bottom-right indicator text and its colour. An empty string clears it.
|
||||
+void wxbr_status_indicator_set(const char* text, int r, int g, int b) {
|
||||
+ if (!g_status_indicator) return;
|
||||
+ g_status_indicator->SetLabel(wxString::FromUTF8(text ? text : ""));
|
||||
+ g_status_indicator->SetForegroundColour(
|
||||
+ wxColour((unsigned char)r, (unsigned char)g, (unsigned char)b));
|
||||
+ reposition_status_indicator();
|
||||
+ g_status_indicator->Refresh();
|
||||
+}
|
||||
+
|
||||
+// ---- deferred destroy (safe from event handlers) ----------------------------
|
||||
+
|
||||
+void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <wx/graphics.h>
|
||||
#include <wx/wrapsizer.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/statusbr.h>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
@@ -1072,6 +1073,55 @@ void wxbr_call_after(int id) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- status-bar error/warning indicator -------------------------------------
|
||||
// A colour-tinted static text pinned to the RIGHT-hand field of the frame's
|
||||
// status bar, so scan/apply errors surface in the bottom-right corner without
|
||||
// overwriting the main (left) scan-status text. The status bar is reconfigured
|
||||
// to two fields: field 0 (stretch) carries the scan status set via the upstream
|
||||
// SetStatusText path; field 1 (fixed) hosts this coloured label, which we
|
||||
// reposition into that field's rect whenever the bar is resized.
|
||||
static wxStaticText* g_status_indicator = nullptr;
|
||||
|
||||
static void reposition_status_indicator() {
|
||||
if (!g_status_indicator) return;
|
||||
wxStatusBar* sb = wxDynamicCast(g_status_indicator->GetParent(), wxStatusBar);
|
||||
if (!sb) return;
|
||||
wxRect r;
|
||||
if (!sb->GetFieldRect(1, r)) return;
|
||||
wxSize best = g_status_indicator->GetBestSize();
|
||||
int h = best.GetHeight();
|
||||
int y = r.y + (r.height - h) / 2;
|
||||
g_status_indicator->SetSize(r.x + 4, y, r.width - 8, h);
|
||||
}
|
||||
|
||||
void wxbr_status_indicator_init(void* frame_ptr) {
|
||||
wxFrame* frame = (wxFrame*)frame_ptr;
|
||||
wxStatusBar* sb = frame->GetStatusBar();
|
||||
if (!sb) sb = frame->CreateStatusBar();
|
||||
int widths[2] = { -1, 340 };
|
||||
sb->SetFieldsCount(2);
|
||||
sb->SetStatusWidths(2, widths);
|
||||
if (!g_status_indicator) {
|
||||
g_status_indicator = new wxStaticText(sb, wxID_ANY, wxEmptyString,
|
||||
wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
|
||||
sb->Bind(wxEVT_SIZE, [](wxSizeEvent& ev) {
|
||||
reposition_status_indicator();
|
||||
ev.Skip();
|
||||
});
|
||||
}
|
||||
reposition_status_indicator();
|
||||
}
|
||||
|
||||
// Set the bottom-right indicator text and its colour. An empty string clears it.
|
||||
void wxbr_status_indicator_set(const char* text, int r, int g, int b) {
|
||||
if (!g_status_indicator) return;
|
||||
g_status_indicator->SetLabel(wxString::FromUTF8(text ? text : ""));
|
||||
g_status_indicator->SetForegroundColour(
|
||||
wxColour((unsigned char)r, (unsigned char)g, (unsigned char)b));
|
||||
reposition_status_indicator();
|
||||
g_status_indicator->Refresh();
|
||||
}
|
||||
|
||||
// ---- deferred destroy (safe from event handlers) ----------------------------
|
||||
|
||||
void wxbr_destroy(void* win) { ((wxWindow*)win)->Destroy(); }
|
||||
|
||||
@@ -103,6 +103,8 @@ mod notsafe {
|
||||
pub fn wxbr_destroy(win: *mut c_void);
|
||||
pub fn wxbr_destroy_children(win: *mut c_void);
|
||||
pub fn wxbr_call_after(id: c_int);
|
||||
pub fn wxbr_status_indicator_init(frame: *mut c_void);
|
||||
pub fn wxbr_status_indicator_set(text: *const c_char, r: c_int, g: c_int, b: c_int);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +177,21 @@ pub fn call_after(id: i32) {
|
||||
unsafe { notsafe::wxbr_call_after(id as c_int) }
|
||||
}
|
||||
|
||||
/// Reconfigure the frame's status bar to two fields and attach a colour-tinted
|
||||
/// label pinned to the right-hand field (bottom-right corner). Call once after
|
||||
/// `create_status_bar()`. The main scan status keeps using the left field via
|
||||
/// the upstream `set_status_text` path.
|
||||
pub fn status_indicator_init(frame: Widget) {
|
||||
unsafe { notsafe::wxbr_status_indicator_init(frame.0) }
|
||||
}
|
||||
|
||||
/// Set the bottom-right status indicator's text and colour (an empty string
|
||||
/// clears it). Used for scan/apply errors (red) and warnings (amber).
|
||||
pub fn status_indicator_set(text: &str, r: u8, g: u8, b: u8) {
|
||||
let c = CString::new(text).unwrap_or_default();
|
||||
unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), 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();
|
||||
|
||||
Reference in New Issue
Block a user