Skip to main content

PickerState

Struct PickerState 

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

The internal state of the picker widget.

All sections are flattened into a single entries vec of headers and items. Navigation moves the cursor between nav stops — visible items plus the headers of collapsed sections — so a collapsed section can still be focused and re-expanded. When nothing is collapsed, the nav stops are exactly the items, matching a plain multi-select list.

Implementations§

Source§

impl PickerState

Source

pub fn new(sections: Vec<Section>) -> Self

Create a new picker state from the given sections.

Source

pub fn is_empty(&self) -> bool

True if there are no focusable entries.

Source

pub fn move_up(&mut self)

Move the cursor up to the previous nav stop.

Source

pub fn move_down(&mut self)

Move the cursor down to the next nav stop.

Source

pub fn toggle(&mut self)

Toggle the checked state of the item under the cursor.

In a radio section, checking an item first unchecks every other item in the section; toggling an already-checked item unchecks it when it’s the only selection (so empty is reachable), but keeps it checked when multiple items were selected (resolving a pre-existing conflict by confirming the toggled choice). A no-op when the cursor is on a header.

Source

pub fn toggle_current_section(&mut self)

Toggle all items in the section that contains the cursor.

In a checkbox section: if any item is unchecked, checks all; otherwise unchecks all. In a radio section this is a no-op — a radio section can never have every item selected.

Source

pub fn clear_current_section(&mut self)

Uncheck every item in the section that contains the cursor.

Bound to Backspace in radio sections to clear the current pick.

Source

pub fn backspace(&mut self)

Backspace handler: clears the current section only when it is radio.

Source

pub fn current_coordinates(&self) -> (usize, usize)

The (section_idx, item_idx) for the current cursor position.

When the cursor rests on a collapsed header, the item index is 0.

Source

pub fn has_any_checked(&self) -> bool

True if at least one item is checked across all sections.

Source

pub fn collapse_current(&mut self)

Collapse the section that contains the cursor and focus its header, so the section can be re-expanded from that position.

Source

pub fn expand_current(&mut self)

Expand the section that contains the cursor and focus its first item (if any), restoring normal traversal through the section.

Source

pub fn radio_conflict_title(&self) -> Option<&str>

The title of the first radio section with more than one item checked, if any. Used to show a warning banner for a pre-existing conflicting state.

Source

pub fn try_confirm(&mut self) -> Result<Vec<Vec<bool>>, String>

Validate radio constraints and, if satisfied, extract the results.

Returns Err naming the offending section when a radio section has more than one item checked.

Source

pub fn into_results(&mut self) -> Vec<Vec<bool>>

Extract checked state grouped by section (matching original input order).

Collapsed sections are included — collapse only hides items from the UI, never from the results.

Source

pub fn cursor(&self) -> usize

Current cursor index (for testing).

Source

pub fn scroll_offset(&self) -> usize

Current scroll offset (for testing).

Source

pub fn set_visible_height(&mut self, h: usize)

Set the visible height (normally set during render; exposed for testing).

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.