pub struct Bar<'a> { /* private fields */ }
Expand description
A bar to be shown by the BarChart
widget.
Here is an explanation of a Bar
’s components.
███ ┐
█2█ <- text_value or value │ bar
foo <- label ┘
Note that every element can be styled individually.
§Example
The following example creates a bar with the label “Bar 1”, a value “10”, red background and a white value foreground.
use ratatui::{
style::{Style, Stylize},
widgets::Bar,
};
Bar::default()
.label("Bar 1".into())
.value(10)
.style(Style::new().red())
.value_style(Style::new().red().on_white())
.text_value("10°C".to_string());
Implementations§
Source§impl<'a> Bar<'a>
impl<'a> Bar<'a>
Sourcepub const fn value(self, value: u64) -> Self
pub const fn value(self, value: u64) -> Self
Set the value of this bar.
The value will be displayed inside the bar.
§See also
Bar::value_style
to style the value.
Bar::text_value
to set the displayed value.
Sourcepub fn label(self, label: Line<'a>) -> Self
pub fn label(self, label: Line<'a>) -> Self
Set the label of the bar.
For Vertical
bars,
display the label under the bar.
For Horizontal
bars,
display the label in the bar.
See BarChart::direction
to set the direction.
Sourcepub fn style<S: Into<Style>>(self, style: S) -> Self
pub fn style<S: Into<Style>>(self, style: S) -> Self
Set the style of the bar.
style
accepts any type that is convertible to Style
(e.g. Style
, Color
, or
your own type that implements Into<Style>
).
This will apply to every non-styled element. It can be seen and used as a default value.
Sourcepub fn value_style<S: Into<Style>>(self, style: S) -> Self
pub fn value_style<S: Into<Style>>(self, style: S) -> Self
Set the style of the value.
style
accepts any type that is convertible to Style
(e.g. Style
, Color
, or
your own type that implements Into<Style>
).
§See also
Bar::value
to set the value.
Sourcepub fn text_value(self, text_value: String) -> Self
pub fn text_value(self, text_value: String) -> Self
Set the text value printed in the bar.
If text_value
is not set, then the ToString
representation of value
will be shown on
the bar.
§See also
Bar::value
to set the value.
Trait Implementations§
impl<'a> Eq for Bar<'a>
impl<'a> StructuralPartialEq for Bar<'a>
Auto Trait Implementations§
impl<'a> Freeze for Bar<'a>
impl<'a> RefUnwindSafe for Bar<'a>
impl<'a> Send for Bar<'a>
impl<'a> Sync for Bar<'a>
impl<'a> Unpin for Bar<'a>
impl<'a> UnwindSafe for Bar<'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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more