pub struct SelectState { /* private fields */ }Expand description
The state for a SelectPrompt.
Rendering a SelectPrompt keeps the focused index within the rendered
options. Until the prompt has been rendered at least once, explicit focused-index changes are
accepted and clamped on the next render. Once the state is completed or aborted,
SelectState::handle_key_event ignores later key events.
Implementations§
Source§impl SelectState
impl SelectState
Sourcepub const fn new() -> SelectState
pub const fn new() -> SelectState
Creates a pending, unfocused select state.
Sourcepub fn move_up(&mut self)
pub fn move_up(&mut self)
Moves focus to the previous option.
Focus stays at index 0 when the first option is already focused.
Sourcepub fn move_down(&mut self)
pub fn move_down(&mut self)
Moves focus to the next option.
Focus stays at the last rendered option. The prompt learns the option count during render, so this is a no-op until the state has been rendered with at least one visible option.
Sourcepub const fn with_status(self, status: Status) -> SelectState
pub const fn with_status(self, status: Status) -> SelectState
Sets the prompt status.
Sourcepub const fn with_focus(self, focus: FocusState) -> SelectState
pub const fn with_focus(self, focus: FocusState) -> SelectState
Sets whether the prompt is focused.
Sourcepub const fn focused_index(&self) -> usize
pub const fn focused_index(&self) -> usize
Returns the currently focused option index.
Sourcepub fn set_focused_index(&mut self, index: usize)
pub fn set_focused_index(&mut self, index: usize)
Sets the focused option index.
If the state has already been rendered with options, the index is clamped to the last available option. If the state has not been rendered yet, the value is accepted and clamped during the next render.
Sourcepub const fn is_finished(&self) -> bool
pub const fn is_finished(&self) -> bool
Returns whether the select prompt has completed or aborted.
Sourcepub fn focus(&mut self)
pub fn focus(&mut self)
Sets focus to FocusState::Focused.
Sourcepub fn blur(&mut self)
pub fn blur(&mut self)
Sets focus to FocusState::Unfocused.
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Returns whether the select prompt is focused.
Sourcepub fn handle_key_event(&mut self, key: KeyEvent)
pub fn handle_key_event(&mut self, key: KeyEvent)
Handles a key event for select prompt navigation and completion.
Pressing Up or Down moves the focused option, Enter completes the prompt when an option is visible, and Escape or Ctrl+C aborts the prompt. Key release events and events routed after completion or abort are ignored.
Trait Implementations§
Source§impl Clone for SelectState
impl Clone for SelectState
Source§fn clone(&self) -> SelectState
fn clone(&self) -> SelectState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SelectState
impl Debug for SelectState
Source§impl Default for SelectState
impl Default for SelectState
Source§fn default() -> SelectState
fn default() -> SelectState
impl Eq for SelectState
Source§impl Hash for SelectState
impl Hash for SelectState
Source§impl PartialEq for SelectState
impl PartialEq for SelectState
Source§fn eq(&self, other: &SelectState) -> bool
fn eq(&self, other: &SelectState) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for SelectState
Auto Trait Implementations§
impl Freeze for SelectState
impl RefUnwindSafe for SelectState
impl Send for SelectState
impl Sync for SelectState
impl Unpin for SelectState
impl UnsafeUnpin for SelectState
impl UnwindSafe for SelectState
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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