Skip to main content

Selector

Struct Selector 

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

A UI component use for navigating and selecting Option components. It allows movement up and down between options and selection of an option.

§Usage

A Selector is required for Option components in a Container to work.

§Notes

  • Without a Selector, Option components in a Container cannot be selected or navigated.

Implementations§

Source§

impl Selector

Source

pub fn new(up_trig: Trigger, down_trig: Trigger, selc_trig: Trigger) -> Self

Constructs a new Selector component with triggers functions for navigating up, down, and selecting. Each action is associated with a Trigger, which determines whether the corresponding input (up, down, or select) is activated.

§Example
// A `Trigger` that always activates.
tui::trg_new_trigger_func!(always_true_trigger, _arg, {
    Ok(true)
});

// A `Trigger` that never activates.
tui::trg_new_trigger_func!(always_false_trigger, _arg, {
    Ok(false)
});

// Create a `Selector` that always moves down when evaluated.
let selector = Selector::new(
    Trigger::no_arg(always_false_trigger), // up
    Trigger::no_arg(always_true_trigger),  // down
    Trigger::no_arg(always_false_trigger), // select
);
Source

pub fn no_triggers() -> Self

Creates a new Selector component without any trigger functions. When using this variant, you must manually control its behavior by calling the selector_up, selector_down, and selector_select methods on the Container that contains it.

§Example
// Create a new `Selector` with no triggers.
let _ = Selector::no_triggers();

// Controlling the `Selector` manually.

// Build a container that contains a manual `Selector`.
let mut container = ContainerBuilder::new()
    .selector_no_triggers()
    .build();

// Move the selector up.
container.selector_up()?;

// Move the selector down.
container.selector_down()?;

// Select the currently highlighted option.
container.selector_select()?;
Source

pub fn up_trig_mut(&mut self) -> FtuiResult<&mut Trigger>

Source

pub fn down_trig_mut(&mut self) -> FtuiResult<&mut Trigger>

Source

pub fn select_trig_mut(&mut self) -> FtuiResult<&mut Trigger>

Source

pub fn update_trig_arg<T, U, V>( &mut self, up_arg: T, down_arg: U, selc_arg: V, ) -> FtuiResult<()>
where T: 'static, U: 'static, V: 'static,

Update all of the Selector triggers argument.

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