Struct cursive::views::Dialog [−][src]
pub struct Dialog { /* fields omitted */ }
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
Creates a new Dialog
with empty content.
You should probably call content()
next.
Creates a new Dialog
with the given content.
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());
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!");
Gets mutable access to the content.
pub fn into_content(self) -> Box<dyn View + 'static, Global>ⓘ
pub fn into_content(self) -> Box<dyn View + 'static, Global>ⓘ
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");
pub fn set_content<V>(&mut self, view: V) -> Box<dyn View + 'static, Global>ⓘ where
V: IntoBoxedView,
pub fn set_content<V>(&mut self, view: V) -> Box<dyn View + 'static, Global>ⓘ where
V: IntoBoxedView,
Sets the content for this dialog.
Previous content will be returned.
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());
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
.
Sets the horizontal alignment for the buttons, if any.
Only works if the buttons are as a row at the bottom of the dialog.
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");
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!");
Sets the horizontal position of the title in the dialog.
The default position is HAlign::Center
Sets the horizontal position of the title in the dialog.
The default position is HAlign::Center
Gets the alignment of the title
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)
Gets the padding in the dialog (around content and buttons).
Sets the padding in the dialog.
Takes Left, Right, Top, Bottom fields.
Sets the padding in the dialog (around content and buttons).
Chainable variant.
Sets the top padding in the dialog (under the title).
Sets the top padding in the dialog (under the title).
Sets the bottom padding in the dialog (under buttons).
Sets the bottom padding in the dialog (under buttons).
Sets the left padding in the dialog.
Sets the left padding in the dialog.
Sets the right padding in the dialog.
Sets the right padding in the dialog.
Iterate the buttons of this dialog.
Mutably iterate the buttons of this dialog.
Returns currently focused element
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
Draws the view with the given printer (includes bounds) and focus. Read more
Returns the minimum size the view requires with the given restrictions. Read more
Called once the size for this view has been decided. Read more
Called when an event is received (key press, mouse event, …). Read more
Attempt to give this view the focus. Read more
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub 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
Moves the focus to the view identified by the given selector. Read more
What part of the view is important and should be visible? Read more
Should return true
if the view content changed since the last call
to layout()
. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Dialog
impl !UnwindSafe for Dialog
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘ
pub fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘ
Returns a Box<View>
.
Wraps self
in a ResizedView
with the given size constraints.
Wraps self
into a fixed-size ResizedView
.
Wraps self
into a fixed-width ResizedView
.
Wraps self
into a fixed-width ResizedView
.
Wraps self
into a full-screen ResizedView
.
Wraps self
into a full-width ResizedView
.
Wraps self
into a full-height ResizedView
.
Wraps self
into a limited-size ResizedView
.
Wraps self
into a limited-width ResizedView
.
Wraps self
into a limited-height ResizedView
.
Wraps self
into a ResizedView
at least sized size
.
Wraps self
in a ResizedView
at least min_width
wide.
Wraps self
in a ResizedView
at least min_height
tall.
Wraps self
in a ScrollView
.
Calls the given closure and return the result. Read more
Calls the given closure on self
.