pub struct AsyncProgressView<T: View> { /* private fields */ }
Expand description
An AsyncProgressView
is a wrapper view that displays a progress bar, until the
child view is successfully created or an error in the creation progress occured.
To achieve this a poll_ready
callback is passed in the creation of AsyncProgressView
which
returns an AsyncProgressState
that can indicate that the process is still Pending
(this contains a float
between 0 and 1, communicating the progress, this information is displayed in the bar), has been successfully
completed Available
containing the view to be displayed, or if the creation has thrown an Error
containing a message to be shown to the user.
The poll_ready
callback should only check for data to be
available and create the child view when the data got available. It must
never block until the data is available or do heavy calculations!
Otherwise cursive cannot proceed displaying and your
application will have a blocking loading process!
If you have troubles and need some more in-depth examples have a look at the provided examples
in the project.
§Example usage
use cursive::{views::TextView, Cursive, CursiveExt};
use cursive_async_view::{AsyncProgressView, AsyncProgressState};
let mut siv = Cursive::default();
let start = std::time::Instant::now();
let async_view = AsyncProgressView::new(&mut siv, move || {
if start.elapsed().as_secs() < 3 {
AsyncProgressState::Pending(start.elapsed().as_secs() as f32 / 3f32)
} else {
AsyncProgressState::Available(TextView::new("Finally it loaded!"))
}
});
siv.add_layer(async_view);
// siv.run();
Implementations§
Source§impl<T: View> AsyncProgressView<T>
impl<T: View> AsyncProgressView<T>
Sourcepub fn new<F>(siv: &mut Cursive, creator: F) -> Selfwhere
F: FnMut() -> AsyncProgressState<T> + 'static,
pub fn new<F>(siv: &mut Cursive, creator: F) -> Selfwhere
F: FnMut() -> AsyncProgressState<T> + 'static,
Create a new AsyncProgressView
instance. The cursive reference is only used to
update the screen when a progress update is received. In order to show the view,
it has to be directly or indirectly added to a cursive layer like any other view.
The creator function will be executed on a dedicated thread in the background. Make sure that this function will never block indefinitely. Otherwise, the creation thread will get stuck.
Sourcepub fn with_width(self, width: usize) -> Self
pub fn with_width(self, width: usize) -> Self
Mark the maximum allowed width in characters, the progress bar may consume. By default, the width will be inherited by the parent view.
Sourcepub fn with_height(self, height: usize) -> Self
pub fn with_height(self, height: usize) -> Self
Mark the maximum allowed height in characters, the progress bar may consume. By default, the height will be inherited by the parent view.
Sourcepub fn with_progress_fn<F>(self, progress_fn: F) -> Self
pub fn with_progress_fn<F>(self, progress_fn: F) -> Self
Set a custom progress function for this view, indicating the progress of the
wrapped view creation. See the default_progress
function reference for an
example on how to create a custom progress function.
pub fn with_error_fn<F>(self, error_fn: F) -> Self
Sourcepub fn set_width(&mut self, width: usize)
pub fn set_width(&mut self, width: usize)
Set the maximum allowed width in characters, the progress bar may consume.
Sourcepub fn set_height(&mut self, height: usize)
pub fn set_height(&mut self, height: usize)
Set the maximum allowed height in characters, the progress bar may consume.
Sourcepub fn set_progress_fn<F>(&mut self, progress_fn: F)
pub fn set_progress_fn<F>(&mut self, progress_fn: F)
Set a custom progress function for this view, indicating the progress of the
wrapped view creation. See the default_progress
function reference for an
example on how to create a custom progress function.
The function may be set at any time. The progress bar can be changed even if the previous progress bar has already be drawn.
Sourcepub fn set_error_fn<F>(&mut self, error_fn: F)
pub fn set_error_fn<F>(&mut self, error_fn: F)
Set a custom error function for this view, indicating that an error occured during the
wrapped view creation. See the default_progress_error
function reference for an
example on how to create a custom error function.
The function may be set at any time. The progress bar can be changed even if the previous progress bar has already be drawn.
Sourcepub fn inherit_width(&mut self)
pub fn inherit_width(&mut self)
Make the progress bar inherit its width from the parent view. This is the default.
Sourcepub fn inherit_height(&mut self)
pub fn inherit_height(&mut self)
Make the progress bar inherit its height from the parent view. This is the default.
Trait Implementations§
Source§impl<T: View> Drop for AsyncProgressView<T>
impl<T: View> Drop for AsyncProgressView<T>
Source§impl<T: View + Sized> View for AsyncProgressView<T>
impl<T: View + Sized> View for AsyncProgressView<T>
Source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Source§fn layout(&mut self, vec: Vec2)
fn layout(&mut self, vec: Vec2)
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, ev: Event) -> EventResult
fn on_event(&mut self, ev: Event) -> EventResult
Source§fn call_on_any<'a>(&mut self, sel: &Selector<'_>, cb: AnyCb<'a>)
fn call_on_any<'a>(&mut self, sel: &Selector<'_>, cb: AnyCb<'a>)
Source§fn focus_view(
&mut self,
sel: &Selector<'_>,
) -> Result<EventResult, ViewNotFound>
fn focus_view( &mut self, sel: &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<T> Freeze for AsyncProgressView<T>where
T: Freeze,
impl<T> !RefUnwindSafe for AsyncProgressView<T>
impl<T> Send for AsyncProgressView<T>
impl<T> Sync for AsyncProgressView<T>
impl<T> Unpin for AsyncProgressView<T>where
T: Unpin,
impl<T> !UnwindSafe for AsyncProgressView<T>
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> Pointable for T
impl<T> Pointable for T
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>(self, size: S) -> ResizedView<Self>
fn fixed_size<S>(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>(self, size: S) -> ResizedView<Self>
fn max_size<S>(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>(self, size: S) -> ResizedView<Self>
fn min_size<S>(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
.