Struct cursive_core::views::ProgressBar
source · pub struct ProgressBar { /* private fields */ }
Expand description
Animated bar showing a progress value.
This bar has an internal counter, and adapts the length of the displayed bar to the relative position of the counter between a minimum and maximum values.
It also prints a customizable text in the center of the bar, which defaults to the progression percentage.
The bar defaults to the current theme’s highlight color, but that can be customized.
§Example
let bar = ProgressBar::new().with_task(|counter| {
// This closure is called in parallel.
for _ in 0..100 {
// Here we can communicate some
// advancement back to the bar.
counter.tick(1);
}
});
Implementations§
source§impl ProgressBar
impl ProgressBar
sourcepub fn with_value(self, value: Counter) -> Self
pub fn with_value(self, value: Counter) -> Self
Sets the value to follow.
Use this to manually control the progress to display
by directly modifying the value pointed to by value
.
sourcepub fn start<F: FnOnce(Counter) + Send + 'static>(&mut self, f: F)
pub fn start<F: FnOnce(Counter) + Send + 'static>(&mut self, f: F)
Starts a function in a separate thread, and monitor the progress.
f
will be given a Counter
to increment the bar’s progress.
This does not reset the value, so it can be called several times to advance the progress in multiple sessions.
sourcepub fn with_task<F: FnOnce(Counter) + Send + 'static>(self, task: F) -> Self
pub fn with_task<F: FnOnce(Counter) + Send + 'static>(self, task: F) -> Self
Starts a function in a separate thread, and monitor the progress.
Chainable variant.
sourcepub fn with_label<F: Fn(usize, (usize, usize)) -> String + 'static + Send + Sync>(
self,
label_maker: F,
) -> Self
pub fn with_label<F: Fn(usize, (usize, usize)) -> String + 'static + Send + Sync>( self, label_maker: F, ) -> Self
Sets the label generator.
The given function will be called with (value, (min, max))
.
Its output will be used as the label to print inside the progress bar.
The default one shows a percentage progress:
fn make_progress(value: usize, (min, max): (usize, usize)) -> String {
let percent = 101 * (value - min) / (1 + max - min);
format!("{} %", percent)
}
sourcepub fn set_label<F: Fn(usize, (usize, usize)) -> String + 'static + Send + Sync>(
&mut self,
label_maker: F,
)
pub fn set_label<F: Fn(usize, (usize, usize)) -> String + 'static + Send + Sync>( &mut self, label_maker: F, )
Sets the label generator.
The given function will be called with (value, (min, max))
.
Its output will be used as the label to print inside the progress bar.
sourcepub fn label_cb<F: Fn(usize, (usize, usize)) -> String + 'static + Send + Sync>(
label_maker: F,
) -> Arc<dyn Fn(usize, (usize, usize)) -> String + Send + Sync>
pub fn label_cb<F: Fn(usize, (usize, usize)) -> String + 'static + Send + Sync>( label_maker: F, ) -> Arc<dyn Fn(usize, (usize, usize)) -> String + Send + Sync>
Helper method to store a callback of the correct type for Self::set_label
.
This is mostly useful when using this view in a template.
sourcepub fn set_label_cb(
&mut self,
label_maker: Arc<dyn Fn(usize, (usize, usize)) -> String + Send + Sync>,
)
pub fn set_label_cb( &mut self, label_maker: Arc<dyn Fn(usize, (usize, usize)) -> String + Send + Sync>, )
Helper method to call Self::set_label
with a variable from a config.
This is mostly useful when writing a cursive blueprint for this view.
sourcepub fn min(self, min: usize) -> Self
pub fn min(self, min: usize) -> Self
Sets the minimum value.
When value
equals min
, the bar is at the minimum level.
If self.min > max
, self.min
is set to max
.
Chainable variant.
sourcepub fn set_min(&mut self, min: usize)
pub fn set_min(&mut self, min: usize)
Sets the minimum value.
When value
equals min
, the bar is at the minimum level.
If self.min > max
, self.min
is set to max
.
sourcepub fn max(self, max: usize) -> Self
pub fn max(self, max: usize) -> Self
Sets the maximum value.
When value
equals max
, the bar is at the maximum level.
If min > self.max
, self.max
is set to min
.
Chainable variant.
sourcepub fn set_max(&mut self, max: usize)
pub fn set_max(&mut self, max: usize)
Sets the maximum value.
When value
equals max
, the bar is at the maximum level.
If min > self.max
, self.max
is set to min
.
sourcepub fn range(self, min: usize, max: usize) -> Self
pub fn range(self, min: usize, max: usize) -> Self
Sets the min
and max
range for the value.
If min > max
, swap the two values.
Chainable variant.
sourcepub fn set_range(&mut self, min: usize, max: usize)
pub fn set_range(&mut self, min: usize, max: usize)
Sets the min
and max
range for the value.
If min > max
, swap the two values.
sourcepub fn set_value(&mut self, value: usize)
pub fn set_value(&mut self, value: usize)
Sets the current value.
Value is clamped between min
and max
.
sourcepub fn set_counter(&mut self, value: Counter)
pub fn set_counter(&mut self, value: Counter)
Sets the value to follow.
Use this to manually control the progress to display
by directly modifying the value pointed to by value
.
sourcepub fn set_color<C>(&mut self, color: C)
pub fn set_color<C>(&mut self, color: C)
Sets the color style.
The default color is PaletteColor::Highlight
.
sourcepub fn with_color<C>(self, color: C) -> Self
pub fn with_color<C>(self, color: C) -> Self
Sets the color style.
Chainable variant of set_color
.
Trait Implementations§
source§impl Default for ProgressBar
impl Default for ProgressBar
source§impl View for ProgressBar
impl View for ProgressBar
source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
source§fn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
source§fn required_size(&mut self, constraint: Vec2) -> Vec2
fn required_size(&mut self, constraint: Vec2) -> Vec2
source§fn on_event(&mut self, _: Event) -> EventResult
fn on_event(&mut self, _: Event) -> EventResult
source§fn call_on_any(&mut self, _: &Selector<'_>, _: AnyCb<'_>)
fn call_on_any(&mut self, _: &Selector<'_>, _: AnyCb<'_>)
source§fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
source§fn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
Auto Trait Implementations§
impl Freeze for ProgressBar
impl !RefUnwindSafe for ProgressBar
impl Send for ProgressBar
impl Sync for ProgressBar
impl Unpin 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
source§impl<T> Finder for Twhere
T: View,
impl<T> Finder for Twhere
T: View,
source§fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
sel
. Read moresource§fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
sel
. Read moresource§fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
call_on
with a view::Selector::Name
.source§impl<T> IntoBoxedView for Twhere
T: View,
impl<T> IntoBoxedView for Twhere
T: View,
source§fn into_boxed_view(self) -> Box<dyn View>
fn into_boxed_view(self) -> Box<dyn View>
Box<View>
.source§impl<T> Resizable for Twhere
T: View,
impl<T> Resizable for Twhere
T: View,
source§fn resized(
self,
width: SizeConstraint,
height: SizeConstraint,
) -> ResizedView<Self>
fn resized( self, width: SizeConstraint, height: SizeConstraint, ) -> ResizedView<Self>
self
in a ResizedView
with the given size constraints.source§fn fixed_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
fn fixed_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
self
into a fixed-size ResizedView
.source§fn fixed_width(self, width: usize) -> ResizedView<Self>
fn fixed_width(self, width: usize) -> ResizedView<Self>
self
into a fixed-width ResizedView
.source§fn fixed_height(self, height: usize) -> ResizedView<Self>
fn fixed_height(self, height: usize) -> ResizedView<Self>
self
into a fixed-width ResizedView
.source§fn full_screen(self) -> ResizedView<Self>
fn full_screen(self) -> ResizedView<Self>
self
into a full-screen ResizedView
.source§fn full_width(self) -> ResizedView<Self>
fn full_width(self) -> ResizedView<Self>
self
into a full-width ResizedView
.source§fn full_height(self) -> ResizedView<Self>
fn full_height(self) -> ResizedView<Self>
self
into a full-height ResizedView
.source§fn max_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
fn max_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
self
into a limited-size ResizedView
.source§fn max_width(self, max_width: usize) -> ResizedView<Self>
fn max_width(self, max_width: usize) -> ResizedView<Self>
self
into a limited-width ResizedView
.source§fn max_height(self, max_height: usize) -> ResizedView<Self>
fn max_height(self, max_height: usize) -> ResizedView<Self>
self
into a limited-height ResizedView
.source§fn min_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
fn min_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
self
into a ResizedView
at least sized size
.source§fn min_width(self, min_width: usize) -> ResizedView<Self>
fn min_width(self, min_width: usize) -> ResizedView<Self>
self
in a ResizedView
at least min_width
wide.source§fn min_height(self, min_height: usize) -> ResizedView<Self>
fn min_height(self, min_height: usize) -> ResizedView<Self>
self
in a ResizedView
at least min_height
tall.source§impl<T> Scrollable for Twhere
T: View,
impl<T> Scrollable for Twhere
T: View,
source§fn scrollable(self) -> ScrollView<Self>
fn scrollable(self) -> ScrollView<Self>
self
in a ScrollView
.