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

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.

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");

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.

Removes a button from this dialog.

Panics

Panics if i >= self.buttons_len().

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 title of the dialog.

Get the title of the dialog.

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

Returns the “default value” for a type. Read more

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

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

Returns the type of this view. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Downcast self to a Any.

Downcast self to a mutable Any.

Returns a boxed any from a boxed self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Runs a callback on all views identified by sel. Read more

Runs a callback on the view identified by sel. Read more

Convenient method to use call_on with a view::Selector::Name.

Convenient method to find a view wrapped in an NamedView.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Returns a Box<View>.

Wraps this view into an NamedView with the given id. Read more

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.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Calls the given closure and return the result. Read more

Calls the given closure on self.

Calls the given closure on self.

Calls the given closure if condition == true.