pub struct Gauge<'a> { /* private fields */ }Expand description
A widget to display a progress bar.
A Gauge renders a bar filled according to the value given to Gauge::percent or
Gauge::ratio. The bar width and height are defined by the Rect it is
rendered in.
The associated label is always centered horizontally and vertically. If not set with
Gauge::label, the label is the percentage of the bar filled.
You might want to have a higher precision bar using Gauge::use_unicode.
This can be useful to indicate the progression of a task, like a download.
§Example
use ratatui::{
style::{Style, Stylize},
widgets::{Block, Gauge},
};
Gauge::default()
.block(Block::bordered().title("Progress"))
.gauge_style(Style::new().white().on_black().italic())
.percent(20);§See also
LineGaugefor a thin progress bar
Implementations§
Source§impl<'a> Gauge<'a>
impl<'a> Gauge<'a>
Sourcepub fn block(self, block: Block<'a>) -> Self
pub fn block(self, block: Block<'a>) -> Self
Surrounds the Gauge with a Block.
The gauge is rendered in the inner portion of the block once space for borders and padding is reserved. Styles set on the block do not affect the bar itself.
Sourcepub fn percent(self, percent: u16) -> Self
pub fn percent(self, percent: u16) -> Self
Sets the bar progression from a percentage.
§Panics
This method panics if percent is not between 0 and 100 inclusively.
§See also
See Gauge::ratio to set from a float.
Sourcepub fn ratio(self, ratio: f64) -> Self
pub fn ratio(self, ratio: f64) -> Self
Sets the bar progression from a ratio (float).
ratio is the ratio between filled bar over empty bar (i.e. 3/4 completion is 0.75).
This is more easily seen as a floating point percentage (e.g. 42% = 0.42).
§Panics
This method panics if ratio is not between 0 and 1 inclusively.
§See also
See Gauge::percent to set from a percentage.
Sourcepub fn label<T>(self, label: T) -> Self
pub fn label<T>(self, label: T) -> Self
Sets the label to display in the center of the bar.
For a left-aligned label, see LineGauge.
If the label is not defined, it is the percentage filled.
Sourcepub fn style<S: Into<Style>>(self, style: S) -> Self
pub fn style<S: Into<Style>>(self, style: S) -> Self
Sets the widget style.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This will style the block (if any non-styled) and background of the widget (everything
except the bar itself). Block style set with Gauge::block takes precedence.
Sourcepub fn gauge_style<S: Into<Style>>(self, style: S) -> Self
pub fn gauge_style<S: Into<Style>>(self, style: S) -> Self
Sets 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>).
Sourcepub const fn use_unicode(self, unicode: bool) -> Self
pub const fn use_unicode(self, unicode: bool) -> Self
Sets whether to use unicode characters to display the progress bar.
This enables the use of unicode block characters. This is useful to display a higher precision bar (8 extra fractional parts per cell).
Trait Implementations§
Source§impl WidgetRef for Gauge<'_>
impl WidgetRef for Gauge<'_>
Source§fn render_ref(&self, area: Rect, buf: &mut Buffer)
fn render_ref(&self, area: Rect, buf: &mut Buffer)
impl<'a> StructuralPartialEq 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> 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,
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 moreSource§impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
fn bg<C>(self, color: C) -> T
fn fg<C>(self, color: C) -> T
fn add_modifier(self, modifier: Modifier) -> T
fn remove_modifier(self, modifier: Modifier) -> T
fn reset(self) -> T
Source§fn on_magenta(self) -> T
fn on_magenta(self) -> T
magenta.Source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
dark_gray.Source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
light_red.Source§fn light_green(self) -> T
fn light_green(self) -> T
light_green.Source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
light_green.Source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
light_yellow.Source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
light_yellow.Source§fn light_blue(self) -> T
fn light_blue(self) -> T
light_blue.Source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
light_blue.Source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
light_magenta.Source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
light_magenta.Source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
light_cyan.Source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
light_cyan.Source§fn not_italic(self) -> T
fn not_italic(self) -> T
ITALIC modifier.Source§fn underlined(self) -> T
fn underlined(self) -> T
UNDERLINED modifier.Source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
UNDERLINED modifier.Source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
REVERSED modifier.HIDDEN modifier.HIDDEN modifier.Source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
CROSSED_OUT modifier.Source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
CROSSED_OUT modifier.