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
| Field | Effect |
|---|---|
label | Rendered after the bar, right-aligned in a row |
show_percentage | Appends " 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: StyleImplementations§
Source§impl ProgressBar
impl ProgressBar
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Attach a text label that will be rendered after the bar.
Sourcepub fn with_percentage(self) -> Self
pub fn with_percentage(self) -> Self
Enable a trailing percentage indicator (e.g. " 30%").
Sourcepub fn to_string_compact(&self, width: usize) -> String
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§
Auto Trait Implementations§
impl Freeze for ProgressBar
impl RefUnwindSafe for ProgressBar
impl Send for ProgressBar
impl Sync for ProgressBar
impl Unpin for ProgressBar
impl UnsafeUnpin for ProgressBar
impl UnwindSafe for ProgressBar
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
Mutably borrows from an owned value. Read more
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>
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 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>
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