Skip to main content

KeyHintsState

Struct KeyHintsState 

Source
pub struct KeyHintsState { /* private fields */ }
Expand description

State for a KeyHints component.

Contains all hints and display configuration.

§Example

use envision::component::{KeyHintsState, KeyHintsLayout};

let state = KeyHintsState::new()
    .with_layout(KeyHintsLayout::Inline)
    .hint("Enter", "Select")
    .hint("Esc", "Cancel");

Implementations§

Source§

impl KeyHintsState

Source

pub fn new() -> Self

Creates a new empty KeyHints state.

§Example
use envision::component::KeyHintsState;

let state = KeyHintsState::new();
assert!(state.is_empty());
Source

pub fn with_hints(hints: Vec<KeyHint>) -> Self

Creates a new state with the given hints.

§Example
use envision::component::{KeyHintsState, KeyHint};

let hints = vec![KeyHint::new("q", "Quit")];
let state = KeyHintsState::with_hints(hints);
assert_eq!(state.len(), 1);
Source

pub fn with_layout(self, layout: KeyHintsLayout) -> Self

Sets the layout style.

§Example
use envision::component::{KeyHintsState, KeyHintsLayout};

let state = KeyHintsState::new().with_layout(KeyHintsLayout::Inline);
assert_eq!(state.layout(), KeyHintsLayout::Inline);
Source

pub fn with_key_action_separator(self, sep: impl Into<String>) -> Self

Sets the separator between key and action.

Source

pub fn with_hint_separator(self, sep: impl Into<String>) -> Self

Sets the separator between hints.

Source

pub fn with_key_style(self, style: Style) -> Self

Sets the style for keys.

Source

pub fn with_action_style(self, style: Style) -> Self

Sets the style for actions.

Source

pub fn hint(self, key: impl Into<String>, action: impl Into<String>) -> Self

Adds a hint using builder pattern.

§Example
use envision::component::KeyHintsState;

let state = KeyHintsState::new()
    .hint("Enter", "Select")
    .hint("Esc", "Cancel")
    .hint("q", "Quit");

assert_eq!(state.len(), 3);
Source

pub fn hint_with_priority( self, key: impl Into<String>, action: impl Into<String>, priority: u8, ) -> Self

Adds a hint with priority using builder pattern.

Source

pub fn hints(&self) -> &[KeyHint]

Returns all hints.

Source

pub fn visible_hints(&self) -> Vec<&KeyHint>

Returns only enabled hints, sorted by priority.

Source

pub fn layout(&self) -> KeyHintsLayout

Returns the layout style.

Source

pub fn len(&self) -> usize

Returns the number of hints.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no hints.

Source

pub fn set_hints(&mut self, hints: Vec<KeyHint>)

Sets the hints.

Source

pub fn add_hint(&mut self, hint: KeyHint)

Adds a hint.

Source

pub fn remove_hint(&mut self, key: &str)

Removes a hint by key.

Source

pub fn enable_hint(&mut self, key: &str)

Enables a hint by key.

Source

pub fn disable_hint(&mut self, key: &str)

Disables a hint by key.

Source

pub fn set_layout(&mut self, layout: KeyHintsLayout)

Sets the layout.

Source

pub fn clear(&mut self)

Clears all hints.

Source

pub fn key_style(&self) -> Style

Returns the key style.

Source

pub fn action_style(&self) -> Style

Returns the action style.

Source

pub fn set_key_style(&mut self, style: Style)

Sets the key style.

Source

pub fn set_action_style(&mut self, style: Style)

Sets the action style.

Source

pub fn is_disabled(&self) -> bool

Returns true if the key hints are 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.

§Example
use envision::component::KeyHintsState;

let state = KeyHintsState::new()
    .with_disabled(true);
assert!(state.is_disabled());

Trait Implementations§

Source§

impl Clone for KeyHintsState

Source§

fn clone(&self) -> KeyHintsState

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 KeyHintsState

Source§

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

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

impl Default for KeyHintsState

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for KeyHintsState

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 KeyHintsState

Source§

fn eq(&self, other: &KeyHintsState) -> 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 KeyHintsState

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 KeyHintsState

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