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.
Helper method to store a callback of the correct type for Self::add_button.
This is mostly useful when using this view in a template.
Helper method to call Self::add_button with a variable from a config.
This is mostly useful when writing a cursive blueprint for this view.
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<StyledString>>(self, label: S) -> Self
pub fn title<S: Into<StyledString>>(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 set_title<S: Into<StyledString>>(&mut self, label: S)
pub fn set_title<S: Into<StyledString>>(&mut self, label: S)
Sets the title of the dialog.
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).
Trait Implementations§
source§impl View for Dialog
impl View for Dialog
source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
source§fn required_size(&mut self, req: Vec2) -> Vec2
fn required_size(&mut self, req: Vec2) -> Vec2
source§fn layout(&mut self, size: Vec2)
fn layout(&mut self, size: Vec2)
source§fn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
source§fn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
source§fn call_on_any(&mut self, selector: &Selector<'_>, callback: AnyCb<'_>)
fn call_on_any(&mut self, selector: &Selector<'_>, callback: AnyCb<'_>)
source§fn focus_view(
&mut self,
selector: &Selector<'_>,
) -> Result<EventResult, ViewNotFound>
fn focus_view( &mut self, selector: &Selector<'_>, ) -> Result<EventResult, ViewNotFound>
source§fn important_area(&self, _: Vec2) -> Rect
fn important_area(&self, _: Vec2) -> Rect
source§fn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
Auto Trait Implementations§
impl Freeze for Dialog
impl !RefUnwindSafe for Dialog
impl Send for Dialog
impl Sync for Dialog
impl Unpin for Dialog
impl !UnwindSafe for Dialog
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Finder for Twhere
T: View,
impl<T> Finder for Twhere
T: View,
source§fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
sel. Read moresource§fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
sel. Read moresource§fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
call_on with a view::Selector::Name.source§impl<T> IntoBoxedView for Twhere
T: View,
impl<T> IntoBoxedView for Twhere
T: View,
source§fn into_boxed_view(self) -> Box<dyn View>
fn into_boxed_view(self) -> Box<dyn View>
Box<View>.source§impl<T> Resizable for Twhere
T: View,
impl<T> Resizable for Twhere
T: View,
source§fn resized(
self,
width: SizeConstraint,
height: SizeConstraint,
) -> ResizedView<Self>
fn resized( self, width: SizeConstraint, height: SizeConstraint, ) -> ResizedView<Self>
self in a ResizedView with the given size constraints.source§fn fixed_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
fn fixed_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
self into a fixed-size ResizedView.source§fn fixed_width(self, width: usize) -> ResizedView<Self>
fn fixed_width(self, width: usize) -> ResizedView<Self>
self into a fixed-width ResizedView.source§fn fixed_height(self, height: usize) -> ResizedView<Self>
fn fixed_height(self, height: usize) -> ResizedView<Self>
self into a fixed-width ResizedView.source§fn full_screen(self) -> ResizedView<Self>
fn full_screen(self) -> ResizedView<Self>
self into a full-screen ResizedView.source§fn full_width(self) -> ResizedView<Self>
fn full_width(self) -> ResizedView<Self>
self into a full-width ResizedView.source§fn full_height(self) -> ResizedView<Self>
fn full_height(self) -> ResizedView<Self>
self into a full-height ResizedView.source§fn max_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
fn max_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
self into a limited-size ResizedView.source§fn max_width(self, max_width: usize) -> ResizedView<Self>
fn max_width(self, max_width: usize) -> ResizedView<Self>
self into a limited-width ResizedView.source§fn max_height(self, max_height: usize) -> ResizedView<Self>
fn max_height(self, max_height: usize) -> ResizedView<Self>
self into a limited-height ResizedView.source§fn min_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
fn min_size<S: Into<Vec2>>(self, size: S) -> ResizedView<Self>
self into a ResizedView at least sized size.source§fn min_width(self, min_width: usize) -> ResizedView<Self>
fn min_width(self, min_width: usize) -> ResizedView<Self>
self in a ResizedView at least min_width wide.source§fn min_height(self, min_height: usize) -> ResizedView<Self>
fn min_height(self, min_height: usize) -> ResizedView<Self>
self in a ResizedView at least min_height tall.source§impl<T> Scrollable for Twhere
T: View,
impl<T> Scrollable for Twhere
T: View,
source§fn scrollable(self) -> ScrollView<Self>
fn scrollable(self) -> ScrollView<Self>
self in a ScrollView.