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
impl KeyHintsState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty KeyHints state.
§Example
use envision::component::KeyHintsState;
let state = KeyHintsState::new();
assert!(state.is_empty());Sourcepub fn with_hints(hints: Vec<KeyHint>) -> Self
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);Sourcepub fn with_layout(self, layout: KeyHintsLayout) -> Self
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);Sourcepub fn with_key_action_separator(self, sep: impl Into<String>) -> Self
pub fn with_key_action_separator(self, sep: impl Into<String>) -> Self
Sets the separator between key and action.
Sourcepub fn with_hint_separator(self, sep: impl Into<String>) -> Self
pub fn with_hint_separator(self, sep: impl Into<String>) -> Self
Sets the separator between hints.
Sourcepub fn with_key_style(self, style: Style) -> Self
pub fn with_key_style(self, style: Style) -> Self
Sets the style for keys.
Sourcepub fn with_action_style(self, style: Style) -> Self
pub fn with_action_style(self, style: Style) -> Self
Sets the style for actions.
Sourcepub fn hint(self, key: impl Into<String>, action: impl Into<String>) -> Self
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);Sourcepub fn hint_with_priority(
self,
key: impl Into<String>,
action: impl Into<String>,
priority: u8,
) -> Self
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.
Sourcepub fn visible_hints(&self) -> Vec<&KeyHint>
pub fn visible_hints(&self) -> Vec<&KeyHint>
Returns only enabled hints, sorted by priority.
Sourcepub fn layout(&self) -> KeyHintsLayout
pub fn layout(&self) -> KeyHintsLayout
Returns the layout style.
Sourcepub fn remove_hint(&mut self, key: &str)
pub fn remove_hint(&mut self, key: &str)
Removes a hint by key.
Sourcepub fn enable_hint(&mut self, key: &str)
pub fn enable_hint(&mut self, key: &str)
Enables a hint by key.
Sourcepub fn disable_hint(&mut self, key: &str)
pub fn disable_hint(&mut self, key: &str)
Disables a hint by key.
Sourcepub fn set_layout(&mut self, layout: KeyHintsLayout)
pub fn set_layout(&mut self, layout: KeyHintsLayout)
Sets the layout.
Sourcepub fn action_style(&self) -> Style
pub fn action_style(&self) -> Style
Returns the action style.
Sourcepub fn set_key_style(&mut self, style: Style)
pub fn set_key_style(&mut self, style: Style)
Sets the key style.
Sourcepub fn set_action_style(&mut self, style: Style)
pub fn set_action_style(&mut self, style: Style)
Sets the action style.
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Returns true if the key hints are 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.
§Example
use envision::component::KeyHintsState;
let state = KeyHintsState::new()
.with_disabled(true);
assert!(state.is_disabled());Trait Implementations§
Source§impl Clone for KeyHintsState
impl Clone for KeyHintsState
Source§fn clone(&self) -> KeyHintsState
fn clone(&self) -> KeyHintsState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for KeyHintsState
impl Debug for KeyHintsState
Source§impl Default for KeyHintsState
impl Default for KeyHintsState
Source§impl<'de> Deserialize<'de> for KeyHintsState
impl<'de> Deserialize<'de> for KeyHintsState
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for KeyHintsState
impl PartialEq for KeyHintsState
Source§impl Serialize for KeyHintsState
impl Serialize for KeyHintsState
impl StructuralPartialEq for KeyHintsState
Auto Trait Implementations§
impl Freeze for KeyHintsState
impl RefUnwindSafe for KeyHintsState
impl Send for KeyHintsState
impl Sync for KeyHintsState
impl Unpin for KeyHintsState
impl UnsafeUnpin for KeyHintsState
impl UnwindSafe for KeyHintsState
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
Mutably borrows from an owned value. Read more
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>
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 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>
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