Skip to main content

Gauge

Struct Gauge 

Source
pub struct Gauge<'a> { /* private fields */ }
Expand description

A labeled gauge: a label, then a bar filling ratio (0.0-1.0) of the remaining width, colored by super::Meter, with a trailing percentage.

Only the first row of area is used. Generalizes ProgressBar with a load-colored fill and inline label/readout. For a current/max integer stat (health, mana) rather than a 0.0..=1.0 load ratio, see super::StatBar. label_style defaults to Theme::DARK’s dim role (as if Gauge::theme had been called); set it with Gauge::label_style. The fill (and readout) color defaults to super::Meter’s green→yellow→red load ramp; override it with Gauge::fill_color for a gauge that isn’t load-shaped (e.g. a health bar, where full should read as safe, not danger).

§Examples

use retroglyph_core::grid::{Grid, Rect};
use retroglyph_ui::{Gauge, Surface, Widget};

let area = Rect::new(0, 0, 20, 1);
let mut grid = Grid::new(20, 1);
Gauge::new("CPU", 0.75).render(&mut Surface::new(&mut grid, area, 0));

Implementations§

Source§

impl<'a> Gauge<'a>

Source

pub fn new(label: &'a str, ratio: f32) -> Self

A gauge for label, filled to ratio (0.0-1.0), with label_style styled from Theme::DARK (as if Gauge::theme had been called).

Source

pub const fn label_style(self, style: Style) -> Self

Set the label’s style.

Source

pub const fn fill_color(self, fill_color: fn(f32) -> Color) -> Self

Overrides the bar’s fill (and readout text) color from super::Meter’s default green→yellow→red load ramp to fill_color, called with the clamped 0.0..=1.0 ratio.

For gauges that aren’t load-shaped, where the default ramp would read backwards (a full health bar reading as danger rather than safe): supply a ramp that fits, e.g. |r| Color::lerp(Color::RED, Color::GREEN, r). A plain fn pointer rather than a boxed closure, so Gauge stays Copy; a non-capturing closure like the one above coerces to it automatically.

Source

pub fn theme(self, theme: Theme) -> Self

Sets label_style to theme.dim on theme.panel_bg: the same de-emphasized role 09_widgets_dashboard already uses for the plain-text label next to this gauge’s sparkline. The bar’s own fill stays load-colored via super::Meter regardless of theme (matching every other gauge/meter-backed widget here; see super::Sparkline’s doc comment for why that coloring is not part of the Theme role palette), unless overridden separately with Gauge::fill_color.

label_style sets an explicit background rather than leaving it at Style::new()’s default: an unset background isn’t “transparent” once a real backend draws it (a bare Color::Default cell paints as solid black behind the glyph; see retroglyph-software’s DEFAULT_BG), so this widget assumes it’s drawn on theme.panel_bg, true when composed with a themed super::Panel/super::Modal. Drawing this gauge directly on the raw screen background instead needs a manual .label_style(...) override afterwards.

Call before any manual Gauge::label_style override you want to keep.

Source

pub fn theme_on(self, theme: Theme, bg: Color) -> Self

Same as Gauge::theme, but label_style is drawn on bg instead of theme.panel_bg, for a gauge drawn directly on a backdrop other than a themed super::Panel/ super::Modal’s fill. Gauge::theme is exactly theme_on(theme, theme.panel_bg).

Trait Implementations§

Source§

impl<'a> Clone for Gauge<'a>

Source§

fn clone(&self) -> Gauge<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Gauge<'a>

Source§

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

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

impl Widget for Gauge<'_>

Source§

fn render(&self, surface: &mut Surface<'_>)

Draw this widget into surface, filling surface.area(). Read more
Source§

impl<'a> Copy for Gauge<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Gauge<'a>

§

impl<'a> RefUnwindSafe for Gauge<'a>

§

impl<'a> Send for Gauge<'a>

§

impl<'a> Sync for Gauge<'a>

§

impl<'a> Unpin for Gauge<'a>

§

impl<'a> UnsafeUnpin for Gauge<'a>

§

impl<'a> UnwindSafe for Gauge<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).