[−][src]Function cursive_async_view::default_progress
pub fn default_progress(
width: usize,
_height: usize,
progress: f32,
pos: usize,
frame_idx: usize
) -> AnimationProgressFrame
The default progress animation for a AsyncProgressView
.
Creating your own progress function
As an example a very basic progress function would look like this:
use crossbeam::Sender; use cursive::Cursive; use cursive::views::TextView; use cursive::utils::markup::StyledString; use cursive_async_view::{AnimationProgressFrame, AsyncProgressView, AsyncProgressState}; fn my_progress_function( _width: usize, _height: usize, progress: f32, _pos: usize, frame_idx: usize, ) -> AnimationProgressFrame { AnimationProgressFrame { content: StyledString::plain(format!("{:.0}%", progress * 100.0)), pos: 0, next_frame_idx: frame_idx, } } let mut siv = Cursive::default(); let start = std::time::Instant::now(); let async_view = AsyncProgressView::new(&mut siv, move || { if start.elapsed().as_secs() > 5 { AsyncProgressState::Pending(start.elapsed().as_secs() as f32 /5f32) } else { AsyncProgressState::Available(TextView::new("Loaded!")) } }) .with_progress_fn(my_progress_function);
The progress function will display the progress in percent as a simple string.
The width
and height
parameters contain the maximum size the content may have
(in characters). The progress
parameter is guaranteed to be a f32
between 0 and 1.
The pos
and frame_idx
parameter are always from the animation frame of the previous iteration.