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>
impl<'a> Gauge<'a>
Sourcepub fn new(label: &'a str, ratio: f32) -> Self
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).
Sourcepub const fn label_style(self, style: Style) -> Self
pub const fn label_style(self, style: Style) -> Self
Set the label’s style.
Sourcepub const fn fill_color(self, fill_color: fn(f32) -> Color) -> Self
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.
Sourcepub fn theme(self, theme: Theme) -> Self
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.
Sourcepub fn theme_on(self, theme: Theme, bg: Color) -> Self
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).