pub struct StatBar<'a> { /* private fields */ }Expand description
A labeled stat bar: label, a bar filling current / max of the
remaining width colored by super::Meter, and a trailing
"current/max" readout.
Only the first row of area is used. Same layout and coloring as
super::Gauge, but for integer current/max pairs (health, mana,
stamina) with a literal readout instead of a percentage: "45/100"
reads as a stat, not a load. max == 0 renders as an empty, unfilled bar
with a "0/0" readout rather than a special-cased blank output. If
current exceeds max (e.g. a temporarily buffed stat), the bar fill
still caps at 100%, but the readout shows the true, uncapped numbers
("120/100") so the overflow stays visible in text. label_style defaults to
Theme::DARK’s dim role (as if StatBar::theme had been called); set it with
StatBar::label_style. The fill (and readout) color defaults to super::Meter’s
green→yellow→red load ramp, which reads backwards for a health/mana/stamina stat (full
renders as danger, not safe); override it with StatBar::fill_color.
§Examples
use retroglyph_core::grid::{Grid, Rect};
use retroglyph_ui::{StatBar, Surface, Widget};
let area = Rect::new(0, 0, 20, 1);
let mut grid = Grid::new(20, 1);
StatBar::new("HP", 45, 100).render(&mut Surface::new(&mut grid, area, 0));Implementations§
Source§impl<'a> StatBar<'a>
impl<'a> StatBar<'a>
Sourcepub fn new(label: &'a str, current: u32, max: u32) -> Self
pub fn new(label: &'a str, current: u32, max: u32) -> Self
A stat bar for label, reading current out of max, with label_style styled from
Theme::DARK (as if StatBar::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 current / max clamped to
0.0..=1.0.
The default ramp reads backwards for a descending stat like health: full renders as
danger (red), not safe. Supply a ramp that fits instead, e.g.
|r| Color::lerp(Color::RED, Color::GREEN, r). A plain fn pointer rather than a
boxed closure, so StatBar 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 mapping (and the same
“assumes it’s drawn on theme.panel_bg” caveat) as super::Gauge::theme; see its
doc comment for the full explanation, including why the bar’s own load-colored fill stays
outside theme’s role palette, unless overridden separately with StatBar::fill_color.
Call before any manual StatBar::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 StatBar::theme, but label_style is drawn on bg instead of
theme.panel_bg: for a stat bar drawn directly on a backdrop other than a themed
super::Panel/super::Modal’s fill. StatBar::theme is exactly
theme_on(theme, theme.panel_bg).
Trait Implementations§
impl<'a> Copy for StatBar<'a>
Auto Trait Implementations§
impl<'a> Freeze for StatBar<'a>
impl<'a> RefUnwindSafe for StatBar<'a>
impl<'a> Send for StatBar<'a>
impl<'a> Sync for StatBar<'a>
impl<'a> Unpin for StatBar<'a>
impl<'a> UnsafeUnpin for StatBar<'a>
impl<'a> UnwindSafe for StatBar<'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]).