[−][src]Function cursive_async_view::default_animation
pub fn default_animation(
width: usize,
_height: usize,
frame_idx: usize
) -> AnimationFrame
The default loading animation for a AsyncView
.
Creating your own loading function
As an example a very basic loading function would look like this:
use cursive::Cursive; use cursive::views::TextView; use cursive::utils::markup::StyledString; use cursive_async_view::{AsyncView, AnimationFrame}; fn my_loading_animation( _width: usize, _height: usize, frame_idx: usize, ) -> AnimationFrame { let content = if frame_idx < 30 { StyledString::plain("loading") } else { StyledString::plain("content") }; AnimationFrame { content, next_frame_idx: (frame_idx + 1) % 60, } } let mut siv = Cursive::default(); let async_view = AsyncView::new(&siv, move || { std::thread::sleep(std::time::Duration::from_secs(10)); TextView::new("Yay!\n\nThe content has loaded!") }) .with_animation_fn(my_loading_animation);
This animation function will first display loading
for 1 second and then display
content
for 1 second.
The width
and height
parameters contain the maximum size the content may have
(in characters). The initial frame_idx
is 0.