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() -> Self
pub fn new() -> Self
Creates a new Dialog
with empty content.
You should probably call content()
next.
sourcepub fn content<V: View + 'static>(self, view: V) -> Self
pub fn content<V: View + 'static>(self, view: V) -> Self
Sets the content for this dialog.
Chainable variant.
sourcepub fn get_content(&self) -> &dyn View
pub fn get_content(&self) -> &dyn View
Gets the content of this dialog.
use cursive::views::{Dialog, TextView};
let dialog = Dialog::around(TextView::new("Hello!"));
let text_view: &TextView = dialog
.get_content()
.as_any()
.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 set_content<V: View + 'static>(&mut self, view: V)
pub fn set_content<V: View + 'static>(&mut self, view: V)
Sets the content for this dialog.
Previous content will be dropped.
sourcepub fn text<S: Into<String>>(text: S) -> Self
pub fn text<S: Into<String>>(text: S) -> Self
Convenient method to create a dialog with a simple text content.
sourcepub fn info<S: Into<String>>(text: S) -> Self
pub fn info<S: Into<String>>(text: S) -> Self
Convenient method to create an infobox.
It will contain the given text and a Ok
dismiss button.
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.
Shortcut method to add a button that will dismiss the dialog.
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.
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 padding<T: Into<Margins>>(self, padding: T) -> Self
pub fn padding<T: Into<Margins>>(self, padding: T) -> Self
Sets the padding in the dialog (around content and buttons).
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 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 padding_left(self, padding: usize) -> Self
pub fn padding_left(self, padding: usize) -> Self
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.
Returns an iterator on this buttons for this dialog.
sourcepub fn focus(&self) -> DialogFocus
pub fn focus(&self) -> DialogFocus
Returns currently focused element
Trait Implementations
sourceimpl View for Dialog
impl View for Dialog
sourcefn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
sourcefn required_size(&mut self, req: Vec2) -> Vec2
fn required_size(&mut self, req: Vec2) -> Vec2
sourcefn layout(&mut self, size: Vec2)
fn layout(&mut self, size: Vec2)
sourcefn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
sourcefn take_focus(&mut self, source: Direction) -> bool
fn take_focus(&mut self, source: Direction) -> bool
sourcefn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>)
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>)
sourcefn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()>
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()>
sourcefn important_area(&self, _: Vec2) -> Rect
fn important_area(&self, _: Vec2) -> Rect
sourcefn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
true
if the view content changed since last layout phase. Read more