Skip to main content

DialogState

Struct DialogState 

Source
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

Source

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

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

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

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

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

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

pub fn buttons(&self) -> &[DialogButton]

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

pub fn primary_button(&self) -> usize

Returns the index of the primary button.

Source

pub fn focused_button(&self) -> usize

Returns the index of the currently focused button.

Source

pub fn set_title(&mut self, title: impl Into<String>)

Sets the dialog title.

Source

pub fn set_message(&mut self, message: impl Into<String>)

Sets the dialog message.

Source

pub fn set_buttons(&mut self, buttons: Vec<DialogButton>)

Sets the dialog buttons.

Resets focus to the first button or primary button index.

Source

pub fn set_primary_button(&mut self, index: usize)

Sets the primary button index.

The index is clamped to the valid range.

Source

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

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

pub fn with_buttons(self, buttons: Vec<DialogButton>) -> Self

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

pub fn with_primary_button(self, index: usize) -> Self

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

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

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

pub fn is_disabled(&self) -> bool

Returns true if the dialog is disabled.

Source

pub fn set_disabled(&mut self, disabled: bool)

Sets the disabled state.

Source

pub fn with_disabled(self, disabled: bool) -> Self

Sets the disabled state using builder pattern.

Source

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

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

pub fn handle_event(&self, event: &Event) -> Option<DialogMessage>

Maps an input event to a dialog message.

Source

pub fn dispatch_event(&mut self, event: &Event) -> Option<DialogOutput>

Dispatches an event, updating state and returning any output.

Source

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

Source§

fn clone(&self) -> DialogState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DialogState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DialogState

Source§

fn default() -> DialogState

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DialogState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for DialogState

Source§

fn eq(&self, other: &DialogState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for DialogState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for DialogState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,