Struct cursive_core::views::Dialog
source · 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§
source§impl Dialog
impl Dialog
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Dialog
with empty content.
You should probably call content()
next.
sourcepub fn around<V: IntoBoxedView>(view: V) -> Self
pub fn around<V: IntoBoxedView>(view: V) -> Self
Creates a new Dialog
with the given content.
sourcepub fn content<V: IntoBoxedView>(self, view: V) -> Self
pub fn content<V: IntoBoxedView>(self, view: V) -> Self
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
pub fn get_content(&self) -> &dyn View
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
pub fn get_content_mut(&mut self) -> &mut dyn View
Gets mutable access to the content.
sourcepub fn into_content(self) -> Box<dyn View>
pub fn into_content(self) -> Box<dyn View>
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: IntoBoxedView>(&mut self, view: V) -> Box<dyn View>
pub fn set_content<V: IntoBoxedView>(&mut self, view: V) -> Box<dyn View>
Sets the content for this dialog.
Previous content will be returned.
sourcepub fn text<S: Into<StyledString>>(text: S) -> Self
pub fn text<S: Into<StyledString>>(text: S) -> Self
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: Into<StyledString>>(text: S) -> Self
pub fn info<S: Into<StyledString>>(text: S) -> Self
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) -> Self
pub fn h_align(self, h: HAlign) -> 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.
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: Into<String>>(self, label: S) -> Self
pub fn title<S: Into<String>>(self, label: S) -> Self
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) -> Self
pub fn title_position(self, align: HAlign) -> Self
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) -> Self
pub fn padding(self, padding: Margins) -> Self
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
) -> Self
pub fn padding_lrtb(
self,
left: usize,
right: usize,
top: usize,
bottom: usize
) -> Self
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) -> Self
pub fn padding_top(self, padding: usize) -> Self
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) -> Self
pub fn padding_bottom(self, padding: usize) -> Self
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) -> Self
pub fn padding_left(self, padding: usize) -> Self
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) -> Self
pub fn padding_right(self, padding: usize) -> Self
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).