Meter

A read-only gauge showing a value within a known range.

EXAMPLEwasm · webgpu

This demo runs the real GPUI component on WebGPU, which this browser does not expose.

Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.

You can also run it natively: cargo run -p showcase meter

The demo failed to start in this browser.

You can run it natively instead: cargo run -p showcase meter

Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.

Recent phones with WebGPU may manage it (downloads ~18 MB):

#Anatomy

Import the component's parts and compose them under its root:

use base_gpui::meter::{
    MeterIndicator,
    MeterLabel,
    MeterRoot,
    MeterTrack,
    MeterValue,
};

MeterRoot::new()
    .child(
        MeterLabel::new(),
    )
    .child(
        MeterTrack::new()
                .child(
                    MeterIndicator::new(),
                ),
    )
    .child(
        MeterValue::new(),
    );
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.

#MeterRoot

Coordinates the component's state and supplies context to its child parts.

Source

use base_gpui::meter::MeterRoot;

MeterRoot::new()
    .id("example-id")
    .value(0.0)
    .min(0.0)
    .max(0.0)
    .format(0.0)
    .aria_label("label")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a MeterRoot with its default configuration.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.childpub fn child(mut self, child: impl Into<MeterChild>) -> Self
  • child: impl Into<MeterChild>

Adds one typed child to this part.

.childrenpub fn children(mut self, children: impl IntoIterator<Item = impl Into<MeterChild>>) -> Self
  • children: impl IntoIterator<Item = impl Into<MeterChild>>

Adds multiple typed children in iteration order.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.valuepub fn value(mut self, value: f64) -> Self
  • value: f64

The current value of the meter (Base UI's required value).

.minpub fn min(mut self, min: f64) -> Self
  • min: f64

Sets the min configuration for this part.

.maxpub fn max(mut self, max: f64) -> Self
  • max: f64

Sets the max configuration for this part.

.formatpub fn format(mut self, format: impl Fn(f64) -> String + 'static) -> Self
  • format: impl Fn(f64) -> String + 'static

Custom formatter receiving the raw (unclamped) value.

.aria_labelpub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
  • label: impl Into<SharedString>

Accessible label for the meter; the literal-string replacement for Base UI's aria-labelledby wiring to MeterLabel. Pass the same string rendered inside MeterLabel. The formatted value text is appended automatically as the aria-valuetext fallback.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(MeterStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(MeterStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

MeterRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#MeterIndicator

Visual representation of the component's current state or value.

Source

use base_gpui::meter::MeterIndicator;

MeterIndicator::new()
    .with_meter_context(/* context: MeterContext */)
    .id("example-id")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a MeterIndicator with its default configuration.

.with_meter_contextpub fn with_meter_context(mut self, context: MeterContext) -> Self
  • context: MeterContext

Sets the with meter context configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(MeterStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(MeterStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

MeterIndicator also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#MeterLabel

Provides a visible label and associated accessibility semantics.

Source

use base_gpui::meter::MeterLabel;

MeterLabel::new()
    .with_meter_context(/* context: MeterContext */)
    .id("example-id")
    .text(/* text: impl Into<SharedString> */)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a MeterLabel with its default configuration.

.with_meter_contextpub fn with_meter_context(mut self, context: MeterContext) -> Self
  • context: MeterContext

Sets the with meter context configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.childpub fn child(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one typed child to this part.

.textpub fn text(mut self, text: impl Into<SharedString>) -> Self
  • text: impl Into<SharedString>

Visible label text, kept out of the a11y tree so it is not announced twice — the same string should be passed to MeterRoot::aria_label.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(MeterStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(MeterStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

MeterLabel also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#MeterTrack

Visual track containing the component's indicator or thumb.

Source

use base_gpui::meter::MeterTrack;

MeterTrack::new()
    .with_meter_context(/* context: MeterContext */)
    .id("example-id")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a MeterTrack with its default configuration.

.with_meter_contextpub fn with_meter_context(mut self, context: MeterContext) -> Self
  • context: MeterContext

Sets the with meter context configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.childpub fn child(mut self, child: impl Into<MeterTrackChild>) -> Self
  • child: impl Into<MeterTrackChild>

Adds one typed child to this part.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(MeterStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(MeterStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

MeterTrack also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#MeterValue

Displays or edits the component's current value.

Source

use base_gpui::meter::MeterValue;

MeterValue::new()
    .with_meter_context(/* context: MeterContext */)
    .id("example-id")
    .display(0.0)
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a MeterValue with its default configuration.

.with_meter_contextpub fn with_meter_context(mut self, context: MeterContext) -> Self
  • context: MeterContext

Sets the with meter context configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.displaypub fn display(mut self, display: impl Fn(&str, f64) -> SharedString + 'static) -> Self
  • display: impl Fn(&str, f64) -> SharedString + 'static

Sets the display configuration for this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(MeterStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(MeterStyleState, Div) -> Div + 'static,

Styles the part from its current behavioral state while preserving separation between behavior and visual design.

MeterValue also supports the GPUI traits implemented in its source, such as standard styling or child composition.

#Accessibility

Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.

#Stability

Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.