pub struct DialogState { /* private fields */ }Expand description
State for a Dialog component.
Contains all the state needed to render and manage a dialog, including title, message, buttons, and focus state.
Implementations§
Source§impl DialogState
impl DialogState
Sourcepub fn new(
title: impl Into<String>,
message: impl Into<String>,
buttons: Vec<DialogButton>,
) -> Self
pub fn new( title: impl Into<String>, message: impl Into<String>, buttons: Vec<DialogButton>, ) -> Self
Creates a new dialog with the given title, message, and buttons.
The first button is set as the primary button by default.
§Example
use envision::component::{DialogButton, DialogState};
let buttons = vec![
DialogButton::new("ok", "OK"),
DialogButton::new("cancel", "Cancel"),
];
let state = DialogState::new("Title", "Message", buttons);
assert_eq!(state.title(), "Title");
assert_eq!(state.primary_button(), 0);Sourcepub fn with_primary(
title: impl Into<String>,
message: impl Into<String>,
buttons: Vec<DialogButton>,
primary: usize,
) -> Self
pub fn with_primary( title: impl Into<String>, message: impl Into<String>, buttons: Vec<DialogButton>, primary: usize, ) -> Self
Creates a dialog with a primary button specified.
The primary button index is clamped to the valid range.
§Example
use envision::component::{DialogButton, DialogState};
let buttons = vec![
DialogButton::new("cancel", "Cancel"),
DialogButton::new("ok", "OK"),
];
let state = DialogState::with_primary("Title", "Message", buttons, 1);
assert_eq!(state.primary_button(), 1);Sourcepub fn alert(title: impl Into<String>, message: impl Into<String>) -> Self
pub fn alert(title: impl Into<String>, message: impl Into<String>) -> Self
Creates a simple alert dialog with an “OK” button.
§Example
use envision::component::DialogState;
let state = DialogState::alert("Error", "Something went wrong.");
assert_eq!(state.buttons().len(), 1);
assert_eq!(state.buttons()[0].id(), "ok");Sourcepub fn confirm(title: impl Into<String>, message: impl Into<String>) -> Self
pub fn confirm(title: impl Into<String>, message: impl Into<String>) -> Self
Creates a confirmation dialog with “Cancel” and “OK” buttons.
The “OK” button is set as the primary button.
§Example
use envision::component::DialogState;
let state = DialogState::confirm("Delete?", "This cannot be undone.");
assert_eq!(state.buttons().len(), 2);
assert_eq!(state.buttons()[0].id(), "cancel");
assert_eq!(state.buttons()[1].id(), "ok");
assert_eq!(state.primary_button(), 1);Returns the dialog buttons.
Returns the index of the primary button.
Returns the index of the currently focused button.
Sourcepub fn set_message(&mut self, message: impl Into<String>)
pub fn set_message(&mut self, message: impl Into<String>)
Sets the dialog message.
Sets the dialog buttons.
Resets focus to the first button or primary button index.
Sets the primary button index.
The index is clamped to the valid range.
Trait Implementations§
Source§impl Clone for DialogState
impl Clone for DialogState
Source§fn clone(&self) -> DialogState
fn clone(&self) -> DialogState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DialogState
impl Debug for DialogState
Source§impl Default for DialogState
impl Default for DialogState
Source§fn default() -> DialogState
fn default() -> DialogState
Auto Trait Implementations§
impl Freeze for DialogState
impl RefUnwindSafe for DialogState
impl Send for DialogState
impl Sync for DialogState
impl Unpin for DialogState
impl UnwindSafe for DialogState
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more