pub struct Dialog { /* private fields */ }
Expand description
Popup-like view with a main content, and optional buttons under it.
Examples
let dialog =
Dialog::around(TextView::new("Hello!")).button("Ok", |s| s.quit());
Implementations
sourceimpl Dialog
impl Dialog
sourcepub fn new() -> Dialog
pub fn new() -> Dialog
Creates a new Dialog
with empty content.
You should probably call content()
next.
sourcepub fn around<V>(view: V) -> Dialog where
V: IntoBoxedView,
pub fn around<V>(view: V) -> Dialog where
V: IntoBoxedView,
Creates a new Dialog
with the given content.
sourcepub fn content<V>(self, view: V) -> Dialog where
V: IntoBoxedView,
pub fn content<V>(self, view: V) -> Dialog where
V: IntoBoxedView,
Sets the content for this dialog.
Chainable variant.
Examples
use cursive_core::views::{Dialog, TextView};
let dialog = Dialog::new()
.content(TextView::new("Hello!"))
.button("Quit", |s| s.quit());
sourcepub fn get_content(&self) -> &(dyn View + 'static)
pub fn get_content(&self) -> &(dyn View + 'static)
Gets the content of this dialog.
use cursive_core::views::{Dialog, TextView};
let dialog = Dialog::around(TextView::new("Hello!"));
let text_view: &TextView =
dialog.get_content().downcast_ref::<TextView>().unwrap();
assert_eq!(text_view.get_content().source(), "Hello!");
sourcepub fn get_content_mut(&mut self) -> &mut (dyn View + 'static)
pub fn get_content_mut(&mut self) -> &mut (dyn View + 'static)
Gets mutable access to the content.
sourcepub fn into_content(self) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
pub fn into_content(self) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Consumes self
and returns the boxed content view.
Examples
use cursive_core::view::View;
use cursive_core::views::{Dialog, TextView};
let dialog = Dialog::around(TextView::new("abc"));
let content: Box<dyn View> = dialog.into_content();
assert!(content.is::<TextView>());
let content: Box<TextView> = content.downcast().ok().unwrap();
assert_eq!(content.get_content().source(), "abc");
sourcepub fn set_content<V>(&mut self, view: V) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
where
V: IntoBoxedView,
pub fn set_content<V>(&mut self, view: V) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
where
V: IntoBoxedView,
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Sets the content for this dialog.
Previous content will be returned.
sourcepub fn text<S>(text: S) -> Dialog where
S: Into<SpannedString<Style>>,
pub fn text<S>(text: S) -> Dialog where
S: Into<SpannedString<Style>>,
Convenient method to create a dialog with a simple text content.
Examples
use cursive_core::views::Dialog;
let dialog = Dialog::text("Hello!").button("Quit", |s| s.quit());
sourcepub fn info<S>(text: S) -> Dialog where
S: Into<SpannedString<Style>>,
pub fn info<S>(text: S) -> Dialog where
S: Into<SpannedString<Style>>,
Convenient method to create an infobox.
It will contain the given text and a Ok
dismiss button.
Examples
use cursive_core::views::Dialog;
let dialog = Dialog::info("Some very important information!");
Adds a button to the dialog with the given label and callback.
Consumes and returns self for easy chaining.
Adds a button to the dialog with the given label and callback.
Returns the number of buttons on this dialog.
Removes any button from self
.
sourcepub fn h_align(self, h: HAlign) -> Dialog
pub fn h_align(self, h: HAlign) -> Dialog
Sets the horizontal alignment for the buttons, if any.
Only works if the buttons are as a row at the bottom of the dialog.
sourcepub fn get_h_align(&self) -> HAlign
pub fn get_h_align(&self) -> HAlign
Gets the horizontal alignment for the buttons.
Shortcut method to add a button that will dismiss the dialog.
Examples
use cursive_core::views::Dialog;
let dialog = Dialog::text("Hello!").dismiss_button("Close");
sourcepub fn title<S>(self, label: S) -> Dialog where
S: Into<String>,
pub fn title<S>(self, label: S) -> Dialog where
S: Into<String>,
Sets the title of the dialog.
If not empty, it will be visible at the top.
Examples
use cursive_core::views::Dialog;
let dialog = Dialog::info("Some info").title("Read me!");
sourcepub fn title_position(self, align: HAlign) -> Dialog
pub fn title_position(self, align: HAlign) -> Dialog
Sets the horizontal position of the title in the dialog.
The default position is HAlign::Center
sourcepub fn set_title_position(&mut self, align: HAlign)
pub fn set_title_position(&mut self, align: HAlign)
Sets the horizontal position of the title in the dialog.
The default position is HAlign::Center
sourcepub fn get_title_position(&self) -> HAlign
pub fn get_title_position(&self) -> HAlign
Gets the alignment of the title
sourcepub fn padding(self, padding: Margins) -> Dialog
pub fn padding(self, padding: Margins) -> Dialog
Sets the padding in the dialog (around content and buttons).
Examples
use cursive_core::views::Dialog;
use cursive_core::view::Margins;
let dialog = Dialog::info("Hello!")
.padding(Margins::lrtb(1, 1, 0, 0)); // (Left, Right, Top, Bottom)
sourcepub fn get_padding(&self) -> Margins
pub fn get_padding(&self) -> Margins
Gets the padding in the dialog (around content and buttons).
sourcepub fn padding_lrtb(
self,
left: usize,
right: usize,
top: usize,
bottom: usize
) -> Dialog
pub fn padding_lrtb(
self,
left: usize,
right: usize,
top: usize,
bottom: usize
) -> Dialog
Sets the padding in the dialog.
Takes Left, Right, Top, Bottom fields.
sourcepub fn set_padding(&mut self, padding: Margins)
pub fn set_padding(&mut self, padding: Margins)
Sets the padding in the dialog (around content and buttons).
Chainable variant.
sourcepub fn padding_top(self, padding: usize) -> Dialog
pub fn padding_top(self, padding: usize) -> Dialog
Sets the top padding in the dialog (under the title).
sourcepub fn set_padding_top(&mut self, padding: usize)
pub fn set_padding_top(&mut self, padding: usize)
Sets the top padding in the dialog (under the title).
sourcepub fn padding_bottom(self, padding: usize) -> Dialog
pub fn padding_bottom(self, padding: usize) -> Dialog
Sets the bottom padding in the dialog (under buttons).
sourcepub fn set_padding_bottom(&mut self, padding: usize)
pub fn set_padding_bottom(&mut self, padding: usize)
Sets the bottom padding in the dialog (under buttons).
sourcepub fn padding_left(self, padding: usize) -> Dialog
pub fn padding_left(self, padding: usize) -> Dialog
Sets the left padding in the dialog.
sourcepub fn set_padding_left(&mut self, padding: usize)
pub fn set_padding_left(&mut self, padding: usize)
Sets the left padding in the dialog.
sourcepub fn padding_right(self, padding: usize) -> Dialog
pub fn padding_right(self, padding: usize) -> Dialog
Sets the right padding in the dialog.
sourcepub fn set_padding_right(&mut self, padding: usize)
pub fn set_padding_right(&mut self, padding: usize)
Sets the right padding in the dialog.
Iterate the buttons of this dialog.
Mutably iterate the buttons of this dialog.
sourcepub fn focus(&self) -> DialogFocus
pub fn focus(&self) -> DialogFocus
Returns currently focused element
sourcepub fn set_focus(&mut self, new_focus: DialogFocus) -> EventResult
pub fn set_focus(&mut self, new_focus: DialogFocus) -> EventResult
Change the current focus of the dialog.
Please be considerate of the context from which focus is being stolen
when programmatically moving focus. For example, moving focus to a
button when a user is typing something into an EditView
would cause
them to accidentally activate the button.
The given dialog focus will be clamped to a valid range. For example, attempting to focus a button that no longer exists will instead focus one that does (or the content, if no buttons exist).
Trait Implementations
sourceimpl View for Dialog
impl View for Dialog
sourcefn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Draws the view with the given printer (includes bounds) and focus. Read more
sourcefn required_size(&mut self, req: XY<usize>) -> XY<usize>
fn required_size(&mut self, req: XY<usize>) -> XY<usize>
Returns the minimum size the view requires with the given restrictions. Read more
sourcefn layout(&mut self, size: XY<usize>)
fn layout(&mut self, size: XY<usize>)
Called once the size for this view has been decided. Read more
sourcefn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
Called when an event is received (key press, mouse event, …). Read more
sourcefn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
Attempt to give this view the focus. Read more
sourcefn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
Runs a closure on the view identified by the given selector. Read more
sourcefn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<EventResult, ViewNotFound>
fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<EventResult, ViewNotFound>
Moves the focus to the view identified by the given selector. Read more
sourcefn important_area(&self, XY<usize>) -> Rect
fn important_area(&self, XY<usize>) -> Rect
What part of the view is important and should be visible? Read more
sourcefn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
Should return true
if the view content changed since the last call
to layout()
. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Dialog
impl !Send for Dialog
impl !Sync for Dialog
impl Unpin for Dialog
impl !UnwindSafe for Dialog
Blanket Implementations
sourceimpl<T> AnyView for T where
T: View,
impl<T> AnyView for T where
T: View,
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Downcast self to a mutable Any
.
sourcefn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
fn as_boxed_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Returns a boxed any from a boxed self. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Finder for T where
T: View,
impl<T> Finder for T where
T: View,
sourcefn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F) where
V: View,
F: FnMut(&mut V),
fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F) where
V: View,
F: FnMut(&mut V),
Runs a callback on all views identified by sel
. Read more
sourcefn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R> where
V: View,
F: FnOnce(&mut V) -> R,
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R> where
V: View,
F: FnOnce(&mut V) -> R,
Runs a callback on the view identified by sel
. Read more
sourceimpl<T> IntoBoxedView for T where
T: View,
impl<T> IntoBoxedView for T where
T: View,
sourcefn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘNotable traits for Box<I, A>impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;
Returns a Box<View>
.
sourceimpl<T> Resizable for T where
T: View,
impl<T> Resizable for T where
T: View,
sourcefn resized(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
fn resized(
self,
width: SizeConstraint,
height: SizeConstraint
) -> ResizedView<Self>
Wraps self
in a ResizedView
with the given size constraints.
sourcefn fixed_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
fn fixed_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
Wraps self
into a fixed-size ResizedView
.
sourcefn fixed_width(self, width: usize) -> ResizedView<Self>
fn fixed_width(self, width: usize) -> ResizedView<Self>
Wraps self
into a fixed-width ResizedView
.
sourcefn fixed_height(self, height: usize) -> ResizedView<Self>
fn fixed_height(self, height: usize) -> ResizedView<Self>
Wraps self
into a fixed-width ResizedView
.
sourcefn full_screen(self) -> ResizedView<Self>
fn full_screen(self) -> ResizedView<Self>
Wraps self
into a full-screen ResizedView
.
sourcefn full_width(self) -> ResizedView<Self>
fn full_width(self) -> ResizedView<Self>
Wraps self
into a full-width ResizedView
.
sourcefn full_height(self) -> ResizedView<Self>
fn full_height(self) -> ResizedView<Self>
Wraps self
into a full-height ResizedView
.
sourcefn max_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
fn max_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
Wraps self
into a limited-size ResizedView
.
sourcefn max_width(self, max_width: usize) -> ResizedView<Self>
fn max_width(self, max_width: usize) -> ResizedView<Self>
Wraps self
into a limited-width ResizedView
.
sourcefn max_height(self, max_height: usize) -> ResizedView<Self>
fn max_height(self, max_height: usize) -> ResizedView<Self>
Wraps self
into a limited-height ResizedView
.
sourcefn min_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
fn min_size<S>(self, size: S) -> ResizedView<Self> where
S: Into<XY<usize>>,
Wraps self
into a ResizedView
at least sized size
.
sourcefn min_width(self, min_width: usize) -> ResizedView<Self>
fn min_width(self, min_width: usize) -> ResizedView<Self>
Wraps self
in a ResizedView
at least min_width
wide.
sourcefn min_height(self, min_height: usize) -> ResizedView<Self>
fn min_height(self, min_height: usize) -> ResizedView<Self>
Wraps self
in a ResizedView
at least min_height
tall.
sourceimpl<T> Scrollable for T where
T: View,
impl<T> Scrollable for T where
T: View,
sourcefn scrollable(self) -> ScrollView<Self>
fn scrollable(self) -> ScrollView<Self>
Wraps self
in a ScrollView
.