[][src]Struct cursive::views::Dialog

pub struct Dialog { /* fields omitted */ }

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

impl Dialog[src]

pub fn new() -> Dialog[src]

Creates a new Dialog with empty content.

You should probably call content() next.

pub fn around<V>(view: V) -> Dialog where
    V: IntoBoxedView
[src]

Creates a new Dialog with the given content.

pub fn content<V>(self, view: V) -> Dialog where
    V: IntoBoxedView
[src]

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

pub fn get_content(&self) -> &(dyn View + 'static)[src]

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

pub fn get_content_mut(&mut self) -> &mut (dyn View + 'static)[src]

Gets mutable access to the content.

pub fn into_content(self) -> Box<dyn View + 'static, Global>[src]

Consumes self and returns the boxed content view.

Examples

use cursive_core::views::{Dialog, TextView};
use cursive_core::view::View;

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) where
    V: IntoBoxedView
[src]

Sets the content for this dialog.

Previous content will be dropped.

pub fn text<S>(text: S) -> Dialog where
    S: Into<SpannedString<Style>>, 
[src]

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

pub fn info<S>(text: S) -> Dialog where
    S: Into<SpannedString<Style>>, 
[src]

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

pub fn button<F, S>(self, label: S, cb: F) -> Dialog where
    F: 'static + Fn(&mut Cursive),
    S: Into<String>, 
[src]

Adds a button to the dialog with the given label and callback.

Consumes and returns self for easy chaining.

pub fn add_button<F, S>(&mut self, label: S, cb: F) where
    F: 'static + Fn(&mut Cursive),
    S: Into<String>, 
[src]

Adds a button to the dialog with the given label and callback.

pub fn buttons_len(&self) -> usize[src]

Returns the number of buttons on this dialog.

pub fn clear_buttons(&mut self)[src]

Removes any button from self.

pub fn remove_button(&mut self, i: usize)[src]

Removes a button from this dialog.

Panics

Panics if i >= self.buttons_len().

pub fn h_align(self, h: HAlign) -> Dialog[src]

Sets the horizontal alignment for the buttons, if any.

Only works if the buttons are as a row at the bottom of the dialog.

pub fn dismiss_button<S>(self, label: S) -> Dialog where
    S: Into<String>, 
[src]

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

pub fn title<S>(self, label: S) -> Dialog where
    S: Into<String>, 
[src]

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

pub fn set_title<S>(&mut self, label: S) where
    S: Into<String>, 
[src]

Sets the title of the dialog.

pub fn title_position(self, align: HAlign) -> Dialog[src]

Sets the horizontal position of the title in the dialog. The default position is HAlign::Center

pub fn set_title_position(&mut self, align: HAlign)[src]

Sets the horizontal position of the title in the dialog. The default position is HAlign::Center

pub fn padding(self, padding: Margins) -> Dialog[src]

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)

pub fn padding_lrtb(
    self,
    left: usize,
    right: usize,
    top: usize,
    bottom: usize
) -> Dialog
[src]

Sets the padding in the dialog.

Takes Left, Right, Top, Bottom fields.

pub fn set_padding(&mut self, padding: Margins)[src]

Sets the padding in the dialog (around content and buttons).

Chainable variant.

pub fn padding_top(self, padding: usize) -> Dialog[src]

Sets the top padding in the dialog (under the title).

pub fn set_padding_top(&mut self, padding: usize)[src]

Sets the top padding in the dialog (under the title).

pub fn padding_bottom(self, padding: usize) -> Dialog[src]

Sets the bottom padding in the dialog (under buttons).

pub fn set_padding_bottom(&mut self, padding: usize)[src]

Sets the bottom padding in the dialog (under buttons).

pub fn padding_left(self, padding: usize) -> Dialog[src]

Sets the left padding in the dialog.

pub fn set_padding_left(&mut self, padding: usize)[src]

Sets the left padding in the dialog.

pub fn padding_right(self, padding: usize) -> Dialog[src]

Sets the right padding in the dialog.

pub fn set_padding_right(&mut self, padding: usize)[src]

Sets the right padding in the dialog.

pub fn buttons_mut(&mut self) -> impl Iterator<Item = &mut Button>[src]

Returns an iterator on this buttons for this dialog.

pub fn focus(&self) -> DialogFocus[src]

Returns currently focused element

Trait Implementations

impl Default for Dialog[src]

impl View for Dialog[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> AnyView for T where
    T: View
[src]

pub fn as_any(&self) -> &(dyn Any + 'static)[src]

Downcast self to a Any.

pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)[src]

Downcast self to a mutable Any.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> Finder for T where
    T: View
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoBoxedView for T where
    T: View
[src]

impl<T> Nameable for T where
    T: View
[src]

impl<T> Resizable for T where
    T: View
[src]

impl<T> Scrollable for T where
    T: View
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> With for T[src]