GUI round 12 (#9, #11): SVG icons in table cells (access padlocks + status)

Adds an SVG-backed icon path to the table's segment renderer: the Rust side
registers a raw SVG per shape sentinel (with its viewBox dims), and the renderer
recolours it to the cell's segment colour, rasterises once per (sentinel, colour,
height) and caches the bitmap. The recolour matches the KPI cards' svg_recolored
(replace currentColor + inject a root fill so fill-less SVGs inherit the colour).

- #9: the Access column padlocks now use the operator-supplied Font Awesome
  lock/unlock SVGs (red closed = view-only, green open = writable) instead of the
  hand-drawn vector padlock. The vector padlock remains as a fallback if the SVG
  is somehow unregistered.
- #11: the Status column renders its KPI icon (green rabbit = hashing, amber
  turtle = slow, red cracked wine glass = not hashing, blue otter = paused)
  instead of the status text, matching the dashboard cards. An unrecognised
  status still falls back to coloured text.

The status dots (hashboards, locate light) stay vector so the round-12 #6 fade
can drive them later. Self-test updated (Status is now a shape cell, verified
structurally like the other icon columns) and still passes. Verified under Xvfb:
the Access column shows the FA padlocks and, with the Status column enabled, the
four status icons render in their KPI colours. wx-rs patches 0002/0003
regenerated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
2026-09-19 23:55:37 -06:00
co-authored by Claude Opus 4.8
parent b7a77cbed8
commit 1857a9e1a0
7 changed files with 284 additions and 21 deletions
+68 -5
View File
@@ -242,6 +242,48 @@ fn encode_flag_cell(plain: &str, color: Option<(u8, u8, u8)>) -> String {
const SHAPE_DOT: &str = "\u{0007}";
const SHAPE_LOCK: &str = "\u{0002}";
const SHAPE_UNLOCK: &str = "\u{0003}";
// Status-column KPI icons (round 12 #11): one sentinel per status, each drawn
// from the same SVG as its dashboard KPI card. Registered with the bridge in
// `register_cell_icons` at startup.
const SHAPE_HASHING: &str = "\u{0004}";
const SHAPE_SLOW: &str = "\u{0005}";
const SHAPE_NOTHASHING: &str = "\u{0006}";
const SHAPE_PAUSED: &str = "\u{0008}";
/// Register every SVG-backed table-cell icon with the bridge (round 12 #9/#11):
/// the access padlocks and the four status KPI icons. Called once at startup;
/// the renderer recolours each per cell. The sentinel code points MUST match the
/// `\u{..}` constants above and the SHAPE_* set in widgets_bridge.cpp.
fn register_cell_icons() {
// (sentinel first char, svg) pairs; the bridge reads the viewBox dims we pass
// to keep each icon's aspect ratio when it rasterises at the cell height.
let icons: [(&str, &str); 6] = [
(SHAPE_LOCK, SVG_LOCK),
(SHAPE_UNLOCK, SVG_UNLOCK),
(SHAPE_HASHING, SVG_RABBIT),
(SHAPE_SLOW, SVG_TURTLE),
(SHAPE_NOTHASHING, SVG_WINE_CRACK),
(SHAPE_PAUSED, SVG_OTTER),
];
for (sentinel, svg) in icons {
let cp = sentinel.chars().next().map(|c| c as u32).unwrap_or(0);
let (vbw, vbh) = svg_viewbox(svg);
wx_rs::register_shape_svg(cp, svg, vbw, vbh);
}
}
/// Parse an SVG's viewBox width/height (round 12 #9/#11), defaulting to a square
/// when absent so the bridge can preserve the icon aspect at any cell height.
fn svg_viewbox(svg: &str) -> (i32, i32) {
svg.split("viewBox=\"")
.nth(1)
.and_then(|s| s.split('"').next())
.and_then(|vb| {
let n: Vec<f64> = vb.split_whitespace().filter_map(|x| x.parse().ok()).collect();
(n.len() == 4 && n[2] > 0.0 && n[3] > 0.0).then(|| (n[2].round() as i32, n[3].round() as i32))
})
.unwrap_or((1, 1))
}
/// Boards column: one status dot per hashboard (round 11 #10). Board 1 is the
/// rightmost dot, so boards render high-position-first (left to right). green =
@@ -285,6 +327,20 @@ fn encode_light_dot(pal: &Palette, flashing: Option<bool>) -> String {
}
}
/// Status column: the status rendered as its KPI icon in the status colour
/// (round 12 #11) -- rabbit=hashing, turtle=slow, cracked wine glass=not
/// hashing, otter=paused. An unrecognised status falls back to coloured text.
fn encode_status_icon(pal: &Palette, status: &str) -> String {
let shape = match status {
"hashing" => SHAPE_HASHING,
"slow" => SHAPE_SLOW,
"not hashing" => SHAPE_NOTHASHING,
"paused" => SHAPE_PAUSED,
_ => return encode_segments(&[(Some(status_kind_color(pal, status)), status.to_string())]),
};
encode_segments(&[(Some(status_kind_color(pal, status)), shape.to_string())])
}
// KPI card icons (round 11 #15). The animal/wine-glass SVGs are Font Awesome Pro
// (operator-supplied); bolt/hive are matching in-repo SVGs. All use
// fill="currentColor", recoloured per card at render time.
@@ -294,6 +350,10 @@ const SVG_WINE_CRACK: &str = include_str!("../assets/icons/wine-glass-crack.svg"
const SVG_OTTER: &str = include_str!("../assets/icons/otter.svg");
const SVG_HIVE: &str = include_str!("../assets/icons/hive.svg");
const SVG_BOLT: &str = include_str!("../assets/icons/bolt.svg");
// Access-column padlocks (round 12 #9): operator-supplied Font Awesome padlocks
// that replace the hand-drawn vector padlocks in the table.
const SVG_LOCK: &str = include_str!("../assets/icons/lock.svg");
const SVG_UNLOCK: &str = include_str!("../assets/icons/unlock.svg");
/// KPI card minimum widths. The count cards (Total/Hashing/...) are narrow; the
/// two wide cards (SHA-256 Hashrate, Est. power) need more room so their
@@ -554,6 +614,9 @@ pub struct App {
pub fn build(frame: Widget) -> App {
let pal = palette();
// Register the SVG-backed table-cell icons once (access padlocks + status KPI
// icons, round 12 #9/#11) before any row is rendered.
register_cell_icons();
let panel = Widget::panel(frame);
let root = Widget::box_sizer(true);
@@ -979,9 +1042,9 @@ impl App {
}
Column::Firmware => encode_flag_cell(&c.cell(r), firmware_color(&r.firmware)),
Column::Status => {
// Status keeps its status colour on its own cell (the
// row is no longer tinted wholesale).
encode_flag_cell(&c.cell(r), Some(status_kind_color(&self.pal, r.status())))
// The status reads as its KPI icon (round 12 #11), drawn
// in the status colour so it matches the dashboard card.
encode_status_icon(&self.pal, r.status())
}
_ => continue,
};
@@ -2960,12 +3023,12 @@ impl App {
// Icon/dot columns (round 11 #10/#13) render shape sentinels, not
// text, so they don't round-trip to c.cell(r); they're verified
// structurally in the icon-column spot-check below.
if matches!(c, Column::Hashboards | Column::Locked | Column::Light) {
if matches!(c, Column::Hashboards | Column::Locked | Column::Light | Column::Status) {
continue;
}
let want = c.cell(r);
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
let got = if matches!(c, Column::Hashrate | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Error | Column::Status | Column::Firmware) {
let got = if matches!(c, Column::Hashrate | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Error | Column::Firmware) {
decode_segments_plain(&raw)
} else {
raw