1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! This project provides a wrapper view with a loading screen for
//! [gyscos/cursive](https://github.com/gyscos/cursive) views. The loading screen will
//! disappear once the wrapped view is fully loaded. This is useful for displaying views
//! which may take long to construct or depend on e.g. the network.
//!
//! # Asynchronous view loading without progress information
//!
//! If you can't tell the progress during a long taking creation of a view, you may
//! wrap the creation of this view in an `AsyncView`. This will display a loading
//! animation until the inner view is ready to be drawn.
//!
//! ```
//! use cursive::{views::TextView, Cursive};
//! use cursive_async_view::AsyncView;
//!
//! 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!")
//! });
//!
//! siv.add_layer(async_view);
//! // siv.run();
//! ```
//!
//! # Asynchronous view loading with a progress bar
//!
//! If you have information about the progress a long taking view creation has made,
//! you can wrap the creation in an `AsyncProgressView`. This will display a progress
//! bar until the inner view is ready to be drawn.
//!
//! ```
//! use crossbeam::Sender;
//! use cursive::{views::TextView, Cursive};
//! use cursive_async_view::AsyncProgressView;
//!
//! let mut siv = Cursive::default();
//! let async_view = AsyncProgressView::new(&siv, |s: Sender<f32>| {
//!     std::thread::sleep(std::time::Duration::from_secs(1));
//!     s.send(0.2).unwrap();
//!     std::thread::sleep(std::time::Duration::from_secs(1));
//!     s.send(0.4).unwrap();
//!     std::thread::sleep(std::time::Duration::from_secs(1));
//!     s.send(0.6).unwrap();
//!     std::thread::sleep(std::time::Duration::from_secs(1));
//!     s.send(0.8).unwrap();
//!     std::thread::sleep(std::time::Duration::from_secs(1));
//!     s.send(1.0).unwrap();
//!     TextView::new("Yay, the content has loaded!")
//! });
//!
//! siv.add_layer(async_view);
//! // siv.run();
//! ```

mod infinite;
mod progress;
mod utils;

pub use infinite::{default_animation, AsyncView, AnimationFrame};
pub use progress::{default_progress, AsyncProgressView};