Skip to main content

ProgressBar

Struct ProgressBar 

Source
pub struct ProgressBar {
    pub current: usize,
    pub total: usize,
    pub label: Option<String>,
    pub show_percentage: bool,
    pub bar_style: Style,
    pub label_style: Style,
}
Expand description

A configurable progress bar widget.

§Rendering modes

FieldEffect
labelRendered after the bar, right-aligned in a row
show_percentageAppends " N%" after the bar (and after label)

Both may be enabled simultaneously.

§Examples

use zlayer_tui::widgets::progress_bar::ProgressBar;

// Minimal usage -- just a bar
let bar = ProgressBar::new(3, 10);

// Builder-style with label
let bar = ProgressBar::new(3, 10).with_label("Step 3/10");

// Deploy-style with percentage
let bar = ProgressBar::new(3, 10).with_percentage();

// Compact string for embedding in table cells
let text = ProgressBar::new(3, 10).with_percentage().to_string_compact(20);

Fields§

§current: usize§total: usize§label: Option<String>§show_percentage: bool§bar_style: Style§label_style: Style

Implementations§

Source§

impl ProgressBar

Source

pub fn new(current: usize, total: usize) -> Self

Create a new progress bar with sensible defaults.

Defaults: no label, no percentage, bar styled with ACCENT foreground, label styled with TEXT foreground.

Source

pub fn with_label(self, label: impl Into<String>) -> Self

Attach a text label that will be rendered after the bar.

Source

pub fn with_percentage(self) -> Self

Enable a trailing percentage indicator (e.g. " 30%").

Source

pub fn to_string_compact(&self, width: usize) -> String

Produce a compact string representation suitable for embedding inside table cells or log lines.

The returned string has the form "████░░░░ label N%" depending on which display options are enabled. The bar itself occupies exactly width columns; the suffix is appended after a space.

If total is zero the bar is empty but still occupies width columns.

Trait Implementations§

Source§

impl Widget for ProgressBar

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.