pub struct StatCard<'a> { /* private fields */ }Expand description
A dashboard stat tile.
Renders an upper-cased label, a headline value (with optional unit
suffix), a coloured delta chip, a short comparison subtitle, and an
optional filled-area sparkline of recent values, all inside a rounded
card surface. The accent colour tints the sparkline. While the
underlying metric is still loading, call StatCard::loading to
render a shimmer placeholder in place of the value and sparkline.
let series = [12.0, 14.0, 13.0, 15.0, 17.0, 16.0, 18.0, 22.0_f32];
ui.add(
StatCard::new("Active deploys")
.accent(Accent::Blue)
.value("24")
.delta(0.12)
.trend("vs last 7 days")
.sparkline(&series),
);Implementations§
Source§impl<'a> StatCard<'a>
impl<'a> StatCard<'a>
Sourcepub fn new(label: impl Into<WidgetText>) -> Self
pub fn new(label: impl Into<WidgetText>) -> Self
Create a new stat card with the given label.
The label is rendered in upper-case (matching the mockup’s
"ACTIVE DEPLOYS" treatment) regardless of the case the caller
passes in. Defaults: blue accent, no value, no delta, no trend, no
sparkline.
Sourcepub fn accent(self, accent: Accent) -> Self
pub fn accent(self, accent: Accent) -> Self
Set the accent colour driving the sparkline tint. Default:
Accent::Blue.
Sourcepub fn value(self, value: impl Into<WidgetText>) -> Self
pub fn value(self, value: impl Into<WidgetText>) -> Self
Set the headline value text. The caller is responsible for any numeric formatting (rounding, locale separators, etc.).
Sourcepub fn unit(self, unit: impl Into<WidgetText>) -> Self
pub fn unit(self, unit: impl Into<WidgetText>) -> Self
Set a small unit suffix rendered next to the value (%, ms,
req/s, …). Default: none.
Sourcepub fn delta(self, delta: f32) -> Self
pub fn delta(self, delta: f32) -> Self
Set the fractional change to display as a coloured delta chip
(e.g. 0.12 for a +12.0% rise). Sign drives the arrow direction
(up / down / flat); magnitude is rendered as a percentage with one
decimal. Default: no chip.
Sourcepub fn invert_delta(self, invert: bool) -> Self
pub fn invert_delta(self, invert: bool) -> Self
When set, a negative delta is treated as the good direction (chip renders green) and a positive delta as bad (chip renders red). Useful for metrics where down is good, like latency or error rate. Default: false.
Sourcepub fn trend(self, trend: impl Into<WidgetText>) -> Self
pub fn trend(self, trend: impl Into<WidgetText>) -> Self
Set the small subtitle below the value (e.g. "vs last 7 days").
Sourcepub fn sparkline(self, series: &'a [f32]) -> Self
pub fn sparkline(self, series: &'a [f32]) -> Self
Render an inline filled-area sparkline of recent values beneath
the trend line. The series is read at the point of ui.add(...)
and not retained. At least two points are required.
Sourcepub fn sparkline_color(self, color: Color32) -> Self
pub fn sparkline_color(self, color: Color32) -> Self
Override the sparkline’s tint. Defaults to the accent colour.
Sourcepub fn width(self, width: f32) -> Self
pub fn width(self, width: f32) -> Self
Pin the card width. Defaults to the parent’s available width,
which lets the card flow inside grid cells or horizontal_wrapped
rows.
Sourcepub fn loading(self, loading: bool) -> Self
pub fn loading(self, loading: bool) -> Self
Render a shimmer skeleton in place of the value, trend, and sparkline. Use while the underlying metric is loading.
Sourcepub fn info_tooltip(self, tooltip: impl Into<WidgetText>) -> Self
pub fn info_tooltip(self, tooltip: impl Into<WidgetText>) -> Self
Attach a tooltip shown on card hover, plus a small painted info indicator next to the label.