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() -> Dialog
pub fn new() -> Dialog
Creates a new Dialog
with empty content.
You should probably call content()
next.
Sourcepub fn around<V>(view: V) -> Dialogwhere
V: IntoBoxedView,
pub fn around<V>(view: V) -> Dialogwhere
V: IntoBoxedView,
Creates a new Dialog
with the given content.
Sourcepub fn content<V>(self, view: V) -> Dialogwhere
V: IntoBoxedView,
pub fn content<V>(self, view: V) -> Dialogwhere
V: IntoBoxedView,
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 + 'static)
pub fn get_content(&self) -> &(dyn View + 'static)
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 + 'static)
pub fn get_content_mut(&mut self) -> &mut (dyn View + 'static)
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>(&mut self, view: V) -> Box<dyn View>where
V: IntoBoxedView,
pub fn set_content<V>(&mut self, view: V) -> Box<dyn View>where
V: IntoBoxedView,
Sets the content for this dialog.
Previous content will be returned.
Sourcepub fn text<S>(text: S) -> Dialog
pub fn text<S>(text: S) -> Dialog
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>(text: S) -> Dialog
pub fn info<S>(text: S) -> Dialog
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) -> Dialog
pub fn h_align(self, h: HAlign) -> Dialog
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>(self, label: S) -> Dialog
pub fn title<S>(self, label: S) -> Dialog
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) -> Dialog
pub fn title_position(self, align: HAlign) -> Dialog
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) -> Dialog
pub fn padding(self, padding: Margins) -> Dialog
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,
) -> Dialog
pub fn padding_lrtb( self, left: usize, right: usize, top: usize, bottom: usize, ) -> Dialog
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) -> Dialog
pub fn padding_top(self, padding: usize) -> Dialog
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) -> Dialog
pub fn padding_bottom(self, padding: usize) -> Dialog
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) -> Dialog
pub fn padding_left(self, padding: usize) -> Dialog
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) -> Dialog
pub fn padding_right(self, padding: usize) -> Dialog
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: XY<usize>) -> XY<usize>
fn required_size(&mut self, req: XY<usize>) -> XY<usize>
Source§fn layout(&mut self, size: XY<usize>)
fn layout(&mut self, size: XY<usize>)
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: &mut dyn FnMut(&mut (dyn View + 'static)),
)
fn call_on_any( &mut self, selector: &Selector<'_>, callback: &mut dyn FnMut(&mut (dyn View + 'static)), )
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, _: XY<usize>) -> Rect
fn important_area(&self, _: XY<usize>) -> 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>(self, size: S) -> ResizedView<Self>
fn fixed_size<S>(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>(self, size: S) -> ResizedView<Self>
fn max_size<S>(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>(self, size: S) -> ResizedView<Self>
fn min_size<S>(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
.