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.

Source

pub fn message(&self) -> &str

Returns the dialog message.

Source

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

Returns the dialog buttons.

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.

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

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> 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.