diff --git a/crates/alkane-gui/assets/icons/bolt.svg b/crates/alkane-gui/assets/icons/bolt.svg new file mode 100644 index 00000000..1d3f07a0 --- /dev/null +++ b/crates/alkane-gui/assets/icons/bolt.svg @@ -0,0 +1 @@ + diff --git a/crates/alkane-gui/assets/icons/hive.svg b/crates/alkane-gui/assets/icons/hive.svg new file mode 100644 index 00000000..97e12874 --- /dev/null +++ b/crates/alkane-gui/assets/icons/hive.svg @@ -0,0 +1 @@ + diff --git a/crates/alkane-gui/assets/icons/otter.svg b/crates/alkane-gui/assets/icons/otter.svg new file mode 100644 index 00000000..5f47c741 --- /dev/null +++ b/crates/alkane-gui/assets/icons/otter.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/alkane-gui/assets/icons/rabbit.svg b/crates/alkane-gui/assets/icons/rabbit.svg new file mode 100644 index 00000000..882491c4 --- /dev/null +++ b/crates/alkane-gui/assets/icons/rabbit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/alkane-gui/assets/icons/turtle.svg b/crates/alkane-gui/assets/icons/turtle.svg new file mode 100644 index 00000000..e5a9740e --- /dev/null +++ b/crates/alkane-gui/assets/icons/turtle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/alkane-gui/assets/icons/wine-glass-crack.svg b/crates/alkane-gui/assets/icons/wine-glass-crack.svg new file mode 100644 index 00000000..e766b20a --- /dev/null +++ b/crates/alkane-gui/assets/icons/wine-glass-crack.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/alkane-gui/src/model.rs b/crates/alkane-gui/src/model.rs index 8f4c4271..bee91604 100644 --- a/crates/alkane-gui/src/model.rs +++ b/crates/alkane-gui/src/model.rs @@ -682,7 +682,21 @@ impl Column { Column::FanCount => SortKey::Num(r.fan_count.map(|v| v as f64).unwrap_or(none)), Column::ExpectedFans => SortKey::Num(r.expected_fans.map(|v| v as f64).unwrap_or(none)), Column::TotalChips => SortKey::Num(r.total_chips.map(|v| v as f64).unwrap_or(none)), - Column::Hashboards => SortKey::Num(r.hashboards.map(|v| v as f64).unwrap_or(none)), + // The Boards column shows per-hashboard health dots, so sort by the + // number of ONLINE (green) boards -- surfacing units with dead/missing + // boards -- with the total board count as a tiebreaker (so full-health + // units still order by how many boards they have). Falls back to the + // reported board count when no per-board health is available (round 11). + Column::Hashboards => { + if r.board_status.is_empty() { + SortKey::Num(r.hashboards.map(|v| v as f64).unwrap_or(none)) + } else { + let online = + r.board_status.iter().filter(|h| matches!(h, BoardHealth::Ok)).count(); + let total = r.board_status.len(); + SortKey::Num((online * 100 + total) as f64) + } + } Column::Uptime => SortKey::Num(if r.uptime_secs > 0 { r.uptime_secs as f64 } else { none }), Column::BestShare => SortKey::Num(r.best_share.unwrap_or(none)), Column::SessionBestShare => SortKey::Num(r.session_best_share.unwrap_or(none)), diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index 88296c78..aef4845b 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -285,6 +285,38 @@ fn encode_light_dot(pal: &Palette, flashing: Option) -> 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. +const SVG_RABBIT: &str = include_str!("../assets/icons/rabbit.svg"); +const SVG_TURTLE: &str = include_str!("../assets/icons/turtle.svg"); +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"); + +/// Replace an SVG's `currentColor` fill with an explicit hex colour so it renders +/// in the KPI card's colour (round 11 #15). +fn svg_recolored(svg: &str, color: (u8, u8, u8)) -> String { + svg.replace( + "currentColor", + &format!("#{:02X}{:02X}{:02X}", color.0, color.1, color.2), + ) +} + +/// Width to render an SVG at, preserving its viewBox aspect ratio at height `h`. +fn svg_width_for_height(svg: &str, h: 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[3] > 0.0).then(|| ((h as f64) * n[2] / n[3]).round() as i32) + }) + .unwrap_or(h) + .max(1) +} + /// Build the segment-encoded cell text for the Cooling column: each fan's RPM /// gets its own grey-to-blue colour by speed, and the "/" separators between /// them stay in the default text colour. @@ -522,7 +554,7 @@ pub fn build(frame: Widget) -> App { // 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, icon: Option| -> (Widget, Widget) { + let mut mk_card = |label: &str, kind: ColorKind, icon: Option<&'static str>| -> (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); @@ -559,9 +591,12 @@ pub fn build(frame: Widget) -> App { let value_row = { let row = Widget::box_sizer(false); row.add_stretch(1); - if let Some(ik) = icon { + if let Some(svg) = icon { + // Neutral cards (Est. power) colour the icon amber so the bolt + // reads; the rest take the card's value colour. let icol = if matches!(kind, ColorKind::Neutral) { pal.amber } else { vc }; - let ic = Widget::kpi_icon(card, ik, icol); + let h = 20; + let ic = Widget::svg_icon(card, &svg_recolored(svg, icol), svg_width_for_height(svg, h), h); row.add(ic, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_RIGHT, 5); } row.add(value, 0, sf::ALIGN_CENTRE_VERTICAL, 0); @@ -577,15 +612,15 @@ pub fn build(frame: Widget) -> App { kpi_cards.push((card, value, lbl, kind)); (card, value) }; - // Icons (round 11 #15): rabbit=hashing, turtle=slow, broken glass=not + // Icons (round 11 #15): rabbit=hashing, turtle=slow, cracked wine glass=not // hashing, otter=paused, hive=hashrate, lightning=power; Total has none. let (_card_total, kpi_total) = mk_card("Total", ColorKind::Neutral, None); - let (card_hashing, kpi_hashing) = mk_card("Hashing", ColorKind::Green, Some(0)); - let (card_slow, kpi_slow) = mk_card("Slow", ColorKind::Amber, Some(1)); - let (card_not, kpi_not) = mk_card("Not hashing", ColorKind::Red, Some(2)); - let (card_paused, kpi_paused) = mk_card("Paused", ColorKind::Blue, Some(3)); - let (card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Accent, Some(4)); - let (_card_power, kpi_power) = mk_card("Est. power", ColorKind::Neutral, Some(5)); + let (card_hashing, kpi_hashing) = mk_card("Hashing", ColorKind::Green, Some(SVG_RABBIT)); + let (card_slow, kpi_slow) = mk_card("Slow", ColorKind::Amber, Some(SVG_TURTLE)); + let (card_not, kpi_not) = mk_card("Not hashing", ColorKind::Red, Some(SVG_WINE_CRACK)); + let (card_paused, kpi_paused) = mk_card("Paused", ColorKind::Blue, Some(SVG_OTTER)); + let (card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Accent, Some(SVG_HIVE)); + let (_card_power, kpi_power) = mk_card("Est. power", ColorKind::Neutral, Some(SVG_BOLT)); drop(mk_card); let _ = (card_hashing, card_slow, card_not, card_paused); // The hashrate card is kpi_cards[5] in build order (Total, Hashing, Slow, diff --git a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch index 1df8b895..d678cf5c 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,800 @@ +@@ -0,0 +1,794 @@ +// 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,7 +116,7 @@ + pub fn wxbr_choice_get_selection(win: *mut c_void) -> c_int; + 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_kpi_icon(parent: *mut c_void, 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_bind_sys_colour(win: *mut c_void); + pub fn wxbr_destroy(win: *mut c_void); + pub fn wxbr_destroy_children(win: *mut c_void); @@ -781,18 +781,12 @@ + }) + } + -+ /// A small drawn KPI icon (static bitmap). kind: 0 rabbit, 1 turtle, -+ /// 2 broken wine glass, 3 otter, 4 hive, 5 lightning bolt (round 11 #15). -+ pub fn kpi_icon(parent: Widget, kind: i32, color: (u8, u8, u8)) -> Widget { -+ Widget(unsafe { -+ notsafe::wxbr_kpi_icon( -+ parent.0, -+ kind, -+ color.0 as c_int, -+ color.1 as c_int, -+ color.2 as c_int, -+ ) -+ }) ++ /// Render an SVG string (recolour it first -- its fill must be an explicit ++ /// colour, not "currentColor") into a static-bitmap icon at `w`x`h` px ++ /// (round 11 #15). ++ pub fn svg_icon(parent: Widget, svg: &str, w: i32, h: i32) -> Widget { ++ let c = CString::new(svg).unwrap_or_default(); ++ Widget(unsafe { notsafe::wxbr_svg_icon(parent.0, c.as_ptr(), w as c_int, h as c_int) }) + } + + /// Listen for OS light/dark theme changes on this window (emits `SysColour`). diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index a47a7d11..6cb2ddee 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,1483 @@ +@@ -0,0 +1,1413 @@ +// 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). @@ -27,6 +27,7 @@ +#include +#include +#include ++#include +#include +#include +#include @@ -230,16 +231,20 @@ + dc->SetBrush(wxBrush(GetAttr().GetBackgroundColour())); + dc->SetPen(*wxTRANSPARENT_PEN); + // The `cell` rect wx hands a custom renderer is shrunk to the content -+ // (text/shape) size by the alignment logic, so filling it alone left the -+ // zebra covering only the text and looking inconsistent with the full-cell -+ // native columns. Fill the whole column-wide cell instead; wxGTK clips the -+ // cell DC to the visible cell area, so the over-wide rect lands exactly on -+ // this cell without bleeding into the next column (round 11 #3). ++ // (text/shape) size in BOTH dimensions by the alignment logic, so filling ++ // it alone left the zebra covering only a content-sized band -- and since ++ // shape cells (dots) and text cells have different content heights, the ++ // stripes ended up unequal across columns. Fill an over-sized rect (full ++ // column width, and well beyond the row vertically); wxGTK clips the cell ++ // DC to the real cell background area, so this lands exactly on the full ++ // row height of this cell without bleeding into neighbours (round 11 #1/#3). + wxRect bg = cell; + if (wxDataViewColumn* owner = const_cast(this)->GetOwner()) { + int cw = owner->GetWidth(); + if (cw > bg.width) bg.width = cw; + } ++ bg.y -= 40; ++ bg.height += 80; + dc->DrawRectangle(bg); + } + wxColour highlight = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); @@ -313,12 +318,23 @@ + if (col && col->GetOwner()) { + GtkWidget* tv = col->GetOwner()->GtkGetTreeView(); + if (tv && GTK_IS_WIDGET(tv)) { ++ // The treeview's own state flags do NOT reliably carry ++ // GTK_STATE_FLAG_BACKDROP (that lives on the toplevel), so query the ++ // toplevel window's active state directly and force BACKDROP onto the ++ // style-context state when it is inactive. Then the themed cell text ++ // colour matches what GTK paints on the native columns when the window ++ // loses focus (round 11 #1/#7). ++ GtkWidget* top = gtk_widget_get_toplevel(tv); ++ bool active = GTK_IS_WINDOW(top) && gtk_window_is_active(GTK_WINDOW(top)); + GtkStyleContext* ctx = gtk_widget_get_style_context(tv); + GtkStateFlags st = gtk_widget_get_state_flags(tv); ++ st = active ? (GtkStateFlags)(st & ~GTK_STATE_FLAG_BACKDROP) ++ : (GtkStateFlags)(st | GTK_STATE_FLAG_BACKDROP); + GdkRGBA c; -+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS -+ gtk_style_context_get_color(ctx, st, &c); -+ G_GNUC_END_IGNORE_DEPRECATIONS ++ gtk_style_context_save(ctx); ++ gtk_style_context_set_state(ctx, st); ++ gtk_style_context_get_color(ctx, gtk_style_context_get_state(ctx), &c); ++ gtk_style_context_restore(ctx); + return wxColour((unsigned char)(c.red * 255.0 + 0.5), + (unsigned char)(c.green * 255.0 + 0.5), + (unsigned char)(c.blue * 255.0 + 0.5)); @@ -1309,98 +1325,12 @@ + return (void*)btn; +} + -+// A small vector icon drawn into a transparent bitmap and wrapped in a -+// wxStaticBitmap, for the KPI cards (round 11 #15). kind: 0 rabbit (hashing), -+// 1 turtle (slow), 2 broken wine glass (not hashing), 3 otter (paused), -+// 4 hive (hashrate), 5 lightning bolt (power). Drawn as simple silhouettes so -+// they read at ~22px; the colour matches the card's value colour. -+void* wxbr_kpi_icon(void* parent, int kind, int r, int g, int b) { -+ const int sz = 22; -+ wxImage img(sz, sz); -+ img.InitAlpha(); -+ unsigned char* a = img.GetAlpha(); -+ if (a) memset(a, 0, (size_t)sz * sz); -+ wxBitmap bmp(img); -+ { -+ wxMemoryDC mdc(bmp); -+ wxGraphicsContext* gc = wxGraphicsContext::Create(mdc); -+ if (gc) { -+ gc->SetAntialiasMode(wxANTIALIAS_DEFAULT); -+ wxColour col(r, g, b); -+ wxColour dark((unsigned char)(r * 0.5), (unsigned char)(g * 0.5), (unsigned char)(b * 0.5)); -+ gc->SetBrush(wxBrush(col)); -+ gc->SetPen(wxPen(col, 1.0)); -+ switch (kind) { -+ case 0: { // rabbit: low haunch body + head + two long spread ears -+ gc->DrawEllipse(4, 12, 14, 8); // haunch (low, wide) -+ gc->DrawEllipse(6.5, 7, 8, 8); // head -+ gc->DrawEllipse(6, 0, 2.6, 9); // left ear (long) -+ gc->DrawEllipse(12, 0, 2.6, 9); // right ear (long, spread) -+ break; -+ } -+ case 1: { // turtle: wide shell + head + two visible legs -+ gc->DrawEllipse(4, 6, 13, 9); -+ gc->DrawEllipse(15.5, 8, 4.5, 4.5); // head -+ gc->DrawEllipse(4.5, 12.5, 4, 4); // front leg -+ gc->DrawEllipse(11, 12.5, 4, 4); // back leg -+ break; -+ } -+ case 2: { // broken wine glass: bowl + stem + base, with a crack -+ wxGraphicsPath bowl = gc->CreatePath(); -+ bowl.MoveToPoint(5, 3); -+ bowl.AddLineToPoint(17, 3); -+ bowl.AddLineToPoint(11, 12); -+ bowl.CloseSubpath(); -+ gc->FillPath(bowl); -+ gc->DrawRectangle(10.2, 12, 1.6, 6); -+ gc->DrawRoundedRectangle(7, 18, 8, 2, 1); -+ wxGraphicsPath crack = gc->CreatePath(); // jagged crack across the bowl -+ crack.MoveToPoint(11, 3); -+ crack.AddLineToPoint(9, 6); -+ crack.AddLineToPoint(12.5, 8); -+ crack.AddLineToPoint(10.5, 11.5); -+ gc->SetPen(wxPen(dark, 1.4)); -+ gc->StrokePath(crack); -+ break; -+ } -+ case 3: { // otter: upright tapered body + head + small ears + thick tail -+ wxGraphicsPath tail = gc->CreatePath(); // thick tapering tail curving right -+ tail.MoveToPoint(13, 17); -+ tail.AddCurveToPoint(19, 16, 21, 20, 19, 21); -+ tail.AddCurveToPoint(17, 21, 15, 20, 12, 19); -+ tail.CloseSubpath(); -+ gc->FillPath(tail); -+ gc->DrawEllipse(6, 8, 10, 13); // body (tapered upright) -+ gc->DrawEllipse(7, 3, 8, 8); // head (wide) -+ gc->DrawEllipse(7, 2.5, 2.6, 2.6); // ear L -+ gc->DrawEllipse(12.4, 2.5, 2.6, 2.6);// ear R -+ break; -+ } -+ case 4: { // hive (skep): three stacked bands narrowing upward + entrance -+ gc->DrawRoundedRectangle(6, 2.5, 10, 4, 2); -+ gc->DrawRoundedRectangle(4, 7, 14, 4, 2); -+ gc->DrawRoundedRectangle(2.5, 11.5, 17, 5, 2.5); -+ gc->SetBrush(wxBrush(dark)); -+ gc->SetPen(wxPen(dark, 1.0)); -+ gc->DrawEllipse(9.3, 13, 3.4, 3.6); -+ break; -+ } -+ default: { // 5 lightning bolt -+ wxGraphicsPath p = gc->CreatePath(); -+ p.MoveToPoint(13, 2); -+ p.AddLineToPoint(5, 12); -+ p.AddLineToPoint(10, 12); -+ p.AddLineToPoint(8, 20); -+ p.AddLineToPoint(17, 9); -+ p.AddLineToPoint(11, 9); -+ p.CloseSubpath(); -+ gc->FillPath(p); -+ break; -+ } -+ } -+ delete gc; -+ } -+ } ++// Render an SVG (already recoloured on the Rust side -- its fill is an explicit ++// #RRGGBB) into a wxStaticBitmap for the KPI cards (round 11 #15). The caller ++// passes the target pixel size (w chosen from the SVG aspect ratio, h fixed). ++void* wxbr_svg_icon(void* parent, const char* svg, int w, int h) { ++ wxBitmapBundle bundle = wxBitmapBundle::FromSVG(svg, wxSize(w, h)); ++ wxBitmap bmp = bundle.GetBitmap(wxSize(w, h)); + return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp); +} + 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 ff5e6455..5a652d75 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 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -227,16 +228,20 @@ class SegmentRenderer : public wxDataViewCustomRenderer { dc->SetBrush(wxBrush(GetAttr().GetBackgroundColour())); dc->SetPen(*wxTRANSPARENT_PEN); // The `cell` rect wx hands a custom renderer is shrunk to the content - // (text/shape) size by the alignment logic, so filling it alone left the - // zebra covering only the text and looking inconsistent with the full-cell - // native columns. Fill the whole column-wide cell instead; wxGTK clips the - // cell DC to the visible cell area, so the over-wide rect lands exactly on - // this cell without bleeding into the next column (round 11 #3). + // (text/shape) size in BOTH dimensions by the alignment logic, so filling + // it alone left the zebra covering only a content-sized band -- and since + // shape cells (dots) and text cells have different content heights, the + // stripes ended up unequal across columns. Fill an over-sized rect (full + // column width, and well beyond the row vertically); wxGTK clips the cell + // DC to the real cell background area, so this lands exactly on the full + // row height of this cell without bleeding into neighbours (round 11 #1/#3). wxRect bg = cell; if (wxDataViewColumn* owner = const_cast(this)->GetOwner()) { int cw = owner->GetWidth(); if (cw > bg.width) bg.width = cw; } + bg.y -= 40; + bg.height += 80; dc->DrawRectangle(bg); } wxColour highlight = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); @@ -310,12 +315,23 @@ class SegmentRenderer : public wxDataViewCustomRenderer { if (col && col->GetOwner()) { GtkWidget* tv = col->GetOwner()->GtkGetTreeView(); if (tv && GTK_IS_WIDGET(tv)) { + // The treeview's own state flags do NOT reliably carry + // GTK_STATE_FLAG_BACKDROP (that lives on the toplevel), so query the + // toplevel window's active state directly and force BACKDROP onto the + // style-context state when it is inactive. Then the themed cell text + // colour matches what GTK paints on the native columns when the window + // loses focus (round 11 #1/#7). + GtkWidget* top = gtk_widget_get_toplevel(tv); + bool active = GTK_IS_WINDOW(top) && gtk_window_is_active(GTK_WINDOW(top)); GtkStyleContext* ctx = gtk_widget_get_style_context(tv); GtkStateFlags st = gtk_widget_get_state_flags(tv); + st = active ? (GtkStateFlags)(st & ~GTK_STATE_FLAG_BACKDROP) + : (GtkStateFlags)(st | GTK_STATE_FLAG_BACKDROP); GdkRGBA c; - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_style_context_get_color(ctx, st, &c); - G_GNUC_END_IGNORE_DEPRECATIONS + gtk_style_context_save(ctx); + gtk_style_context_set_state(ctx, st); + gtk_style_context_get_color(ctx, gtk_style_context_get_state(ctx), &c); + gtk_style_context_restore(ctx); return wxColour((unsigned char)(c.red * 255.0 + 0.5), (unsigned char)(c.green * 255.0 + 0.5), (unsigned char)(c.blue * 255.0 + 0.5)); @@ -1306,98 +1322,12 @@ void* wxbr_media_button(void* parent, int id, int kind, int r, int g, int b) { return (void*)btn; } -// A small vector icon drawn into a transparent bitmap and wrapped in a -// wxStaticBitmap, for the KPI cards (round 11 #15). kind: 0 rabbit (hashing), -// 1 turtle (slow), 2 broken wine glass (not hashing), 3 otter (paused), -// 4 hive (hashrate), 5 lightning bolt (power). Drawn as simple silhouettes so -// they read at ~22px; the colour matches the card's value colour. -void* wxbr_kpi_icon(void* parent, int kind, int r, int g, int b) { - const int sz = 22; - wxImage img(sz, sz); - img.InitAlpha(); - unsigned char* a = img.GetAlpha(); - if (a) memset(a, 0, (size_t)sz * sz); - wxBitmap bmp(img); - { - wxMemoryDC mdc(bmp); - wxGraphicsContext* gc = wxGraphicsContext::Create(mdc); - if (gc) { - gc->SetAntialiasMode(wxANTIALIAS_DEFAULT); - wxColour col(r, g, b); - wxColour dark((unsigned char)(r * 0.5), (unsigned char)(g * 0.5), (unsigned char)(b * 0.5)); - gc->SetBrush(wxBrush(col)); - gc->SetPen(wxPen(col, 1.0)); - switch (kind) { - case 0: { // rabbit: low haunch body + head + two long spread ears - gc->DrawEllipse(4, 12, 14, 8); // haunch (low, wide) - gc->DrawEllipse(6.5, 7, 8, 8); // head - gc->DrawEllipse(6, 0, 2.6, 9); // left ear (long) - gc->DrawEllipse(12, 0, 2.6, 9); // right ear (long, spread) - break; - } - case 1: { // turtle: wide shell + head + two visible legs - gc->DrawEllipse(4, 6, 13, 9); - gc->DrawEllipse(15.5, 8, 4.5, 4.5); // head - gc->DrawEllipse(4.5, 12.5, 4, 4); // front leg - gc->DrawEllipse(11, 12.5, 4, 4); // back leg - break; - } - case 2: { // broken wine glass: bowl + stem + base, with a crack - wxGraphicsPath bowl = gc->CreatePath(); - bowl.MoveToPoint(5, 3); - bowl.AddLineToPoint(17, 3); - bowl.AddLineToPoint(11, 12); - bowl.CloseSubpath(); - gc->FillPath(bowl); - gc->DrawRectangle(10.2, 12, 1.6, 6); - gc->DrawRoundedRectangle(7, 18, 8, 2, 1); - wxGraphicsPath crack = gc->CreatePath(); // jagged crack across the bowl - crack.MoveToPoint(11, 3); - crack.AddLineToPoint(9, 6); - crack.AddLineToPoint(12.5, 8); - crack.AddLineToPoint(10.5, 11.5); - gc->SetPen(wxPen(dark, 1.4)); - gc->StrokePath(crack); - break; - } - case 3: { // otter: upright tapered body + head + small ears + thick tail - wxGraphicsPath tail = gc->CreatePath(); // thick tapering tail curving right - tail.MoveToPoint(13, 17); - tail.AddCurveToPoint(19, 16, 21, 20, 19, 21); - tail.AddCurveToPoint(17, 21, 15, 20, 12, 19); - tail.CloseSubpath(); - gc->FillPath(tail); - gc->DrawEllipse(6, 8, 10, 13); // body (tapered upright) - gc->DrawEllipse(7, 3, 8, 8); // head (wide) - gc->DrawEllipse(7, 2.5, 2.6, 2.6); // ear L - gc->DrawEllipse(12.4, 2.5, 2.6, 2.6);// ear R - break; - } - case 4: { // hive (skep): three stacked bands narrowing upward + entrance - gc->DrawRoundedRectangle(6, 2.5, 10, 4, 2); - gc->DrawRoundedRectangle(4, 7, 14, 4, 2); - gc->DrawRoundedRectangle(2.5, 11.5, 17, 5, 2.5); - gc->SetBrush(wxBrush(dark)); - gc->SetPen(wxPen(dark, 1.0)); - gc->DrawEllipse(9.3, 13, 3.4, 3.6); - break; - } - default: { // 5 lightning bolt - wxGraphicsPath p = gc->CreatePath(); - p.MoveToPoint(13, 2); - p.AddLineToPoint(5, 12); - p.AddLineToPoint(10, 12); - p.AddLineToPoint(8, 20); - p.AddLineToPoint(17, 9); - p.AddLineToPoint(11, 9); - p.CloseSubpath(); - gc->FillPath(p); - break; - } - } - delete gc; - } - } +// Render an SVG (already recoloured on the Rust side -- its fill is an explicit +// #RRGGBB) into a wxStaticBitmap for the KPI cards (round 11 #15). The caller +// passes the target pixel size (w chosen from the SVG aspect ratio, h fixed). +void* wxbr_svg_icon(void* parent, const char* svg, int w, int h) { + wxBitmapBundle bundle = wxBitmapBundle::FromSVG(svg, wxSize(w, h)); + wxBitmap bmp = bundle.GetBitmap(wxSize(w, h)); return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp); } 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 d0871d84..1f6618f0 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 @@ -103,7 +103,7 @@ mod notsafe { pub fn wxbr_choice_get_selection(win: *mut c_void) -> c_int; 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_kpi_icon(parent: *mut c_void, 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_bind_sys_colour(win: *mut c_void); pub fn wxbr_destroy(win: *mut c_void); pub fn wxbr_destroy_children(win: *mut c_void); @@ -768,18 +768,12 @@ impl Widget { }) } - /// A small drawn KPI icon (static bitmap). kind: 0 rabbit, 1 turtle, - /// 2 broken wine glass, 3 otter, 4 hive, 5 lightning bolt (round 11 #15). - pub fn kpi_icon(parent: Widget, kind: i32, color: (u8, u8, u8)) -> Widget { - Widget(unsafe { - notsafe::wxbr_kpi_icon( - parent.0, - kind, - color.0 as c_int, - color.1 as c_int, - color.2 as c_int, - ) - }) + /// Render an SVG string (recolour it first -- its fill must be an explicit + /// colour, not "currentColor") into a static-bitmap icon at `w`x`h` px + /// (round 11 #15). + pub fn svg_icon(parent: Widget, svg: &str, w: i32, h: i32) -> Widget { + let c = CString::new(svg).unwrap_or_default(); + Widget(unsafe { notsafe::wxbr_svg_icon(parent.0, c.as_ptr(), w as c_int, h as c_int) }) } /// Listen for OS light/dark theme changes on this window (emits `SysColour`).