From a3fe7ffed9183d254fb1c80b42415f08932f3c3e Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 19 Sep 2026 23:55:37 -0600 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh --- crates/alkane-gui/assets/icons/lock.svg | 1 + crates/alkane-gui/assets/icons/unlock.svg | 1 + crates/alkane-gui/src/ui.rs | 73 ++++++++++++- .../wx-rs/patches/0002-widget-bridge-rs.patch | 14 ++- .../patches/0003-widget-bridge-cpp.patch | 103 ++++++++++++++++-- .../cpp_src/widgets_bridge.cpp | 101 +++++++++++++++-- .../wx-rs/wx-rs-0.2.0-patched/src/widgets.rs | 12 ++ 7 files changed, 284 insertions(+), 21 deletions(-) create mode 100644 crates/alkane-gui/assets/icons/lock.svg create mode 100644 crates/alkane-gui/assets/icons/unlock.svg diff --git a/crates/alkane-gui/assets/icons/lock.svg b/crates/alkane-gui/assets/icons/lock.svg new file mode 100644 index 00000000..2a38c797 --- /dev/null +++ b/crates/alkane-gui/assets/icons/lock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/alkane-gui/assets/icons/unlock.svg b/crates/alkane-gui/assets/icons/unlock.svg new file mode 100644 index 00000000..b26ec9fe --- /dev/null +++ b/crates/alkane-gui/assets/icons/unlock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 13a3314b..4bcb60e1 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -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 = 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) -> 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 diff --git a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch index d678cf5c..916f249c 100644 --- a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch +++ b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch @@ -10,7 +10,7 @@ +pub use widgets::*; --- a/src/widgets.rs +++ b/src/widgets.rs -@@ -0,0 +1,794 @@ +@@ -0,0 +1,806 @@ +// 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). @@ -117,6 +117,7 @@ + pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int); + pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void; + pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void; ++ pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int); + pub fn wxbr_bind_sys_colour(win: *mut c_void); + pub fn wxbr_destroy(win: *mut c_void); + pub fn wxbr_destroy_children(win: *mut c_void); @@ -213,6 +214,17 @@ + unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), r as c_int, g as c_int, b as c_int) } +} + ++/// Register a raw SVG for a table-cell shape sentinel (a control-char code point) ++/// so the segment renderer can draw it recoloured to each cell's segment colour. ++/// `vbw`/`vbh` are the SVG viewBox dimensions, used to keep the icon's aspect ++/// ratio when it is rasterised at the cell height (round 12 #9/#11). ++pub fn register_shape_svg(sentinel: u32, svg: &str, vbw: i32, vbh: i32) { ++ let c = CString::new(svg).unwrap_or_default(); ++ unsafe { ++ notsafe::wxbr_register_shape_svg(sentinel as c_int, c.as_ptr(), vbw as c_int, vbh 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(); diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index a58a6183..d4749d10 100644 --- a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch +++ b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch @@ -1,6 +1,6 @@ --- a/cpp_src/widgets_bridge.cpp +++ b/cpp_src/widgets_bridge.cpp -@@ -0,0 +1,1460 @@ +@@ -0,0 +1,1547 @@ +// 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). @@ -159,27 +159,95 @@ +const wxUniChar SHAPE_DOT = 0x07; // filled status dot (hashboards, locate light) +const wxUniChar SHAPE_LOCK = 0x02; // closed padlock (locked / view-only) +const wxUniChar SHAPE_UNLOCK = 0x03; // open padlock (unlocked / writable) ++// Status-column KPI icons (round 12 #11): each renders the same Font Awesome ++// glyph as its dashboard KPI card, drawn from an SVG registered by the Rust side ++// (see wxbr_register_shape_svg). No vector fallback -- if unregistered the cell ++// is simply blank. ++const wxUniChar SHAPE_HASHING = 0x04; // rabbit (hashing) ++const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow) ++const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing) ++const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused) +const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies + +bool IsShapeSentinel(const wxString& s, wxUniChar& out) { + if (s.length() != 1) return false; + wxUniChar c = s[0]; -+ if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK) { ++ if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK || ++ c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING || ++ c == SHAPE_PAUSED) { + out = c; + return true; + } + return false; +} + -+// Draw one shape sentinel, centred in the SHAPE_ADVANCE-wide slot at x. -+void DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) { ++// Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status ++// icons). The Rust side registers a raw SVG (with its viewBox dims for aspect) ++// per sentinel; DrawShape recolours it to the segment colour, rasterises once ++// per (sentinel, colour, height), caches the bitmap, and draws it. The access ++// padlocks (0x02/0x03) fall back to a hand-drawn vector when unregistered. ++struct ShapeSvg { ++ wxString svg; ++ int vbw; ++ int vbh; ++}; ++std::map g_shape_svgs; ++std::map g_shape_bmp_cache; ++ ++const ShapeSvg* LookupShapeSvg(wxUniChar shape) { ++ auto it = g_shape_svgs.find((int)shape.GetValue()); ++ return it == g_shape_svgs.end() ? nullptr : &it->second; ++} ++ ++// Recolour an SVG to `c`, matching the Rust svg_recolored(): replace ++// fill="currentColor" and inject a root fill so shapes that omit a fill inherit ++// the colour too (e.g. the Font Awesome Free otter). ++wxString RecolorShapeSvg(const wxString& svg, const wxColour& c) { ++ wxString hex = wxString::Format("#%02X%02X%02X", (int)c.Red(), (int)c.Green(), (int)c.Blue()); ++ wxString s = svg; ++ s.Replace("currentColor", hex); ++ int pos = s.Find("second; ++ wxString colored = RecolorShapeSvg(sv.svg, col); ++ wxBitmapBundle bundle = wxBitmapBundle::FromSVG(colored.ToUTF8().data(), wxSize(w, h)); ++ wxBitmap bmp = bundle.GetBitmap(wxSize(w, h)); ++ return g_shape_bmp_cache.emplace(key, bmp).first->second; ++} ++ ++// Draw one shape sentinel centred at x; returns the horizontal space it used ++// (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon). ++int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) { + int cy = cell.y + cell.height / 2; ++ // SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the ++ // segment colour, rasterise (cached), and draw centred in its slot. ++ if (const ShapeSvg* sv = LookupShapeSvg(shape)) { ++ int h = cell.height - 4; ++ if (h > 15) h = 15; ++ if (h < 8) h = 8; ++ int w = (sv->vbh > 0) ? (int)((double)h * sv->vbw / sv->vbh + 0.5) : h; ++ if (w < 1) w = 1; ++ const wxBitmap& bmp = ShapeBitmap(shape, *sv, colour, w, h); ++ if (bmp.IsOk()) { ++ int slot = (w > SHAPE_ADVANCE) ? w : SHAPE_ADVANCE; ++ dc->DrawBitmap(bmp, x + (slot - w) / 2, cy - h / 2, true); ++ return slot; ++ } ++ } + int cx = x + SHAPE_ADVANCE / 2; + if (shape == SHAPE_DOT) { + dc->SetPen(*wxTRANSPARENT_PEN); + dc->SetBrush(wxBrush(colour)); + dc->DrawCircle(cx, cy, 4); -+ return; ++ return SHAPE_ADVANCE; + } + // Padlock: a filled body with a staple shackle above. The colour carries the + // state (green = unlocked, red = locked); the shackle is drawn ajar when open. @@ -201,6 +269,7 @@ + dc->DrawLine(rx, legTop, rx, legTop + sr); // ajar: right leg lifted + else + dc->DrawLine(rx, legTop, rx, by); // closed: right leg to body ++ return SHAPE_ADVANCE; +} + +} // namespace @@ -275,8 +344,7 @@ + // selection highlight (round 11 #10/#13). + wxUniChar shape; + if (IsShapeSentinel(seg.text, shape)) { -+ DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain); -+ x += SHAPE_ADVANCE; ++ x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain); + continue; + } + if (seg.text.IsEmpty()) continue; @@ -294,7 +362,13 @@ + for (const ColorSegment& seg : ParseColorSegments(m_value)) { + wxUniChar shape; + if (IsShapeSentinel(seg.text, shape)) { -+ w += SHAPE_ADVANCE; ++ int adv = SHAPE_ADVANCE; ++ if (const ShapeSvg* sv = LookupShapeSvg(shape)) { ++ int hh = 15; ++ int ww = (sv->vbh > 0) ? (int)((double)hh * sv->vbw / sv->vbh + 0.5) : hh; ++ if (ww > adv) adv = ww; ++ } ++ w += adv; + if (h < 12) h = 12; + continue; + } @@ -1381,6 +1455,19 @@ + return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp); +} + ++// Register a raw SVG (with its viewBox width/height for aspect) for a table-cell ++// shape sentinel, so the SegmentRenderer can draw it recoloured to the cell's ++// segment colour (round 12 #9 access padlocks, #11 status KPI icons). Replaces ++// any prior registration for that sentinel and invalidates the bitmap cache. ++void wxbr_register_shape_svg(int sentinel, const char* svg, int vbw, int vbh) { ++ ShapeSvg s; ++ s.svg = wxString::FromUTF8(svg); ++ s.vbw = vbw; ++ s.vbh = vbh; ++ g_shape_svgs[sentinel] = s; ++ g_shape_bmp_cache.clear(); ++} ++ +// ---- live theme changes ----------------------------------------------------- + +// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp index 2a9ce17f..beac2606 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp @@ -156,27 +156,95 @@ std::vector ParseColorSegments(const wxString& value) { const wxUniChar SHAPE_DOT = 0x07; // filled status dot (hashboards, locate light) const wxUniChar SHAPE_LOCK = 0x02; // closed padlock (locked / view-only) const wxUniChar SHAPE_UNLOCK = 0x03; // open padlock (unlocked / writable) +// Status-column KPI icons (round 12 #11): each renders the same Font Awesome +// glyph as its dashboard KPI card, drawn from an SVG registered by the Rust side +// (see wxbr_register_shape_svg). No vector fallback -- if unregistered the cell +// is simply blank. +const wxUniChar SHAPE_HASHING = 0x04; // rabbit (hashing) +const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow) +const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing) +const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused) const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies bool IsShapeSentinel(const wxString& s, wxUniChar& out) { if (s.length() != 1) return false; wxUniChar c = s[0]; - if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK) { + if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK || + c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING || + c == SHAPE_PAUSED) { out = c; return true; } return false; } -// Draw one shape sentinel, centred in the SHAPE_ADVANCE-wide slot at x. -void DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) { +// Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status +// icons). The Rust side registers a raw SVG (with its viewBox dims for aspect) +// per sentinel; DrawShape recolours it to the segment colour, rasterises once +// per (sentinel, colour, height), caches the bitmap, and draws it. The access +// padlocks (0x02/0x03) fall back to a hand-drawn vector when unregistered. +struct ShapeSvg { + wxString svg; + int vbw; + int vbh; +}; +std::map g_shape_svgs; +std::map g_shape_bmp_cache; + +const ShapeSvg* LookupShapeSvg(wxUniChar shape) { + auto it = g_shape_svgs.find((int)shape.GetValue()); + return it == g_shape_svgs.end() ? nullptr : &it->second; +} + +// Recolour an SVG to `c`, matching the Rust svg_recolored(): replace +// fill="currentColor" and inject a root fill so shapes that omit a fill inherit +// the colour too (e.g. the Font Awesome Free otter). +wxString RecolorShapeSvg(const wxString& svg, const wxColour& c) { + wxString hex = wxString::Format("#%02X%02X%02X", (int)c.Red(), (int)c.Green(), (int)c.Blue()); + wxString s = svg; + s.Replace("currentColor", hex); + int pos = s.Find("second; + wxString colored = RecolorShapeSvg(sv.svg, col); + wxBitmapBundle bundle = wxBitmapBundle::FromSVG(colored.ToUTF8().data(), wxSize(w, h)); + wxBitmap bmp = bundle.GetBitmap(wxSize(w, h)); + return g_shape_bmp_cache.emplace(key, bmp).first->second; +} + +// Draw one shape sentinel centred at x; returns the horizontal space it used +// (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon). +int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) { int cy = cell.y + cell.height / 2; + // SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the + // segment colour, rasterise (cached), and draw centred in its slot. + if (const ShapeSvg* sv = LookupShapeSvg(shape)) { + int h = cell.height - 4; + if (h > 15) h = 15; + if (h < 8) h = 8; + int w = (sv->vbh > 0) ? (int)((double)h * sv->vbw / sv->vbh + 0.5) : h; + if (w < 1) w = 1; + const wxBitmap& bmp = ShapeBitmap(shape, *sv, colour, w, h); + if (bmp.IsOk()) { + int slot = (w > SHAPE_ADVANCE) ? w : SHAPE_ADVANCE; + dc->DrawBitmap(bmp, x + (slot - w) / 2, cy - h / 2, true); + return slot; + } + } int cx = x + SHAPE_ADVANCE / 2; if (shape == SHAPE_DOT) { dc->SetPen(*wxTRANSPARENT_PEN); dc->SetBrush(wxBrush(colour)); dc->DrawCircle(cx, cy, 4); - return; + return SHAPE_ADVANCE; } // Padlock: a filled body with a staple shackle above. The colour carries the // state (green = unlocked, red = locked); the shackle is drawn ajar when open. @@ -198,6 +266,7 @@ void DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const w dc->DrawLine(rx, legTop, rx, legTop + sr); // ajar: right leg lifted else dc->DrawLine(rx, legTop, rx, by); // closed: right leg to body + return SHAPE_ADVANCE; } } // namespace @@ -272,8 +341,7 @@ class SegmentRenderer : public wxDataViewCustomRenderer { // selection highlight (round 11 #10/#13). wxUniChar shape; if (IsShapeSentinel(seg.text, shape)) { - DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain); - x += SHAPE_ADVANCE; + x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain); continue; } if (seg.text.IsEmpty()) continue; @@ -291,7 +359,13 @@ class SegmentRenderer : public wxDataViewCustomRenderer { for (const ColorSegment& seg : ParseColorSegments(m_value)) { wxUniChar shape; if (IsShapeSentinel(seg.text, shape)) { - w += SHAPE_ADVANCE; + int adv = SHAPE_ADVANCE; + if (const ShapeSvg* sv = LookupShapeSvg(shape)) { + int hh = 15; + int ww = (sv->vbh > 0) ? (int)((double)hh * sv->vbw / sv->vbh + 0.5) : hh; + if (ww > adv) adv = ww; + } + w += adv; if (h < 12) h = 12; continue; } @@ -1378,6 +1452,19 @@ void* wxbr_svg_icon(void* parent, const char* svg, int w, int h) { return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp); } +// Register a raw SVG (with its viewBox width/height for aspect) for a table-cell +// shape sentinel, so the SegmentRenderer can draw it recoloured to the cell's +// segment colour (round 12 #9 access padlocks, #11 status KPI icons). Replaces +// any prior registration for that sentinel and invalidates the bitmap cache. +void wxbr_register_shape_svg(int sentinel, const char* svg, int vbw, int vbh) { + ShapeSvg s; + s.svg = wxString::FromUTF8(svg); + s.vbw = vbw; + s.vbh = vbh; + g_shape_svgs[sentinel] = s; + g_shape_bmp_cache.clear(); +} + // ---- live theme changes ----------------------------------------------------- // Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs index 1f6618f0..5495e6dd 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs @@ -104,6 +104,7 @@ mod notsafe { pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int); pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void; pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void; + pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int); pub fn wxbr_bind_sys_colour(win: *mut c_void); pub fn wxbr_destroy(win: *mut c_void); pub fn wxbr_destroy_children(win: *mut c_void); @@ -200,6 +201,17 @@ pub fn status_indicator_set(text: &str, r: u8, g: u8, b: u8) { unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), r as c_int, g as c_int, b as c_int) } } +/// Register a raw SVG for a table-cell shape sentinel (a control-char code point) +/// so the segment renderer can draw it recoloured to each cell's segment colour. +/// `vbw`/`vbh` are the SVG viewBox dimensions, used to keep the icon's aspect +/// ratio when it is rasterised at the cell height (round 12 #9/#11). +pub fn register_shape_svg(sentinel: u32, svg: &str, vbw: i32, vbh: i32) { + let c = CString::new(svg).unwrap_or_default(); + unsafe { + notsafe::wxbr_register_shape_svg(sentinel as c_int, c.as_ptr(), vbw as c_int, vbh 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();