Skip to main content

StatCard

Struct StatCard 

Source
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>

Source

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.

Source

pub fn accent(self, accent: Accent) -> Self

Set the accent colour driving the sparkline tint. Default: Accent::Blue.

Source

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.).

Source

pub fn unit(self, unit: impl Into<WidgetText>) -> Self

Set a small unit suffix rendered next to the value (%, ms, req/s, …). Default: none.

Source

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.

Source

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.

Source

pub fn trend(self, trend: impl Into<WidgetText>) -> Self

Set the small subtitle below the value (e.g. "vs last 7 days").

Source

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.

Source

pub fn sparkline_color(self, color: Color32) -> Self

Override the sparkline’s tint. Defaults to the accent colour.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for StatCard<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Widget for StatCard<'_>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for StatCard<'a>

§

impl<'a> RefUnwindSafe for StatCard<'a>

§

impl<'a> Send for StatCard<'a>

§

impl<'a> Sync for StatCard<'a>

§

impl<'a> Unpin for StatCard<'a>

§

impl<'a> UnsafeUnpin for StatCard<'a>

§

impl<'a> UnwindSafe for StatCard<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.