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);Sourcepub fn title(&self) -> &str
pub fn title(&self) -> &str
Returns the dialog title.
§Examples
use envision::prelude::*;
let state = DialogState::alert("Error", "Something went wrong.");
assert_eq!(state.title(), "Error");Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Returns the dialog message.
§Examples
use envision::prelude::*;
let state = DialogState::alert("Error", "File not found.");
assert_eq!(state.message(), "File not found.");Returns the dialog buttons.
§Examples
use envision::prelude::*;
let state = DialogState::confirm("Delete?", "Are you sure?");
assert_eq!(state.buttons().len(), 2);
assert_eq!(state.buttons()[0].id(), "cancel");
assert_eq!(state.buttons()[1].id(), "ok");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.
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Sets the dialog title (builder method).
§Example
use envision::component::DialogState;
let state = DialogState::default().with_title("My Title");
assert_eq!(state.title(), "My Title");Sourcepub fn with_message(self, message: impl Into<String>) -> Self
pub fn with_message(self, message: impl Into<String>) -> Self
Sets the dialog message (builder method).
§Example
use envision::component::DialogState;
let state = DialogState::default().with_message("Important message");
assert_eq!(state.message(), "Important message");Sets the dialog buttons (builder method).
Resets focus to the first button or primary button index.
§Example
use envision::component::{DialogButton, DialogState};
let state = DialogState::default().with_buttons(vec![
DialogButton::new("ok", "OK"),
DialogButton::new("cancel", "Cancel"),
]);
assert_eq!(state.buttons().len(), 2);Sets the primary button index (builder method).
The index is clamped to the valid range.
§Example
use envision::component::{DialogButton, DialogState};
let state = DialogState::new("T", "M", vec![
DialogButton::new("a", "A"),
DialogButton::new("b", "B"),
]).with_primary_button(1);
assert_eq!(state.primary_button(), 1);Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Returns true if the dialog is focused.
§Examples
use envision::prelude::*;
let state = DialogState::alert("Info", "Done.");
assert!(!state.is_focused());Sourcepub fn set_focused(&mut self, focused: bool)
pub fn set_focused(&mut self, focused: bool)
Sets the focus state.
§Examples
use envision::prelude::*;
let mut state = DialogState::alert("Info", "Done.");
state.set_focused(true);
assert!(state.is_focused());Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Returns true if the dialog is disabled.
Sourcepub fn set_disabled(&mut self, disabled: bool)
pub fn set_disabled(&mut self, disabled: bool)
Sets the disabled state.
Sourcepub fn with_disabled(self, disabled: bool) -> Self
pub fn with_disabled(self, disabled: bool) -> Self
Sets the disabled state using builder pattern.
Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Returns true if the dialog is visible.
§Examples
use envision::prelude::*;
let state = DialogState::alert("Info", "Done.");
assert!(!state.is_visible());Sourcepub fn set_visible(&mut self, visible: bool)
pub fn set_visible(&mut self, visible: bool)
Sets the visibility state.
§Examples
use envision::prelude::*;
let mut state = DialogState::alert("Info", "Done.");
state.set_visible(true);
assert!(state.is_visible());Sourcepub fn handle_event(&self, event: &Event) -> Option<DialogMessage>
pub fn handle_event(&self, event: &Event) -> Option<DialogMessage>
Maps an input event to a dialog message.
Sourcepub fn dispatch_event(&mut self, event: &Event) -> Option<DialogOutput>
pub fn dispatch_event(&mut self, event: &Event) -> Option<DialogOutput>
Dispatches an event, updating state and returning any output.
Sourcepub fn update(&mut self, msg: DialogMessage) -> Option<DialogOutput>
pub fn update(&mut self, msg: DialogMessage) -> Option<DialogOutput>
Updates the dialog state with a message, returning any output.
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
Source§impl<'de> Deserialize<'de> for DialogState
impl<'de> Deserialize<'de> for DialogState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for DialogState
impl PartialEq for DialogState
Source§impl Serialize for DialogState
impl Serialize for DialogState
impl StructuralPartialEq for 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 UnsafeUnpin 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