Skip to main content

List

Struct List 

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

⚠️ Experimental ⚠️ Another variant of a Container designed to display data in a vertical list format. A List is scrollable, allowing it to handle a dynamic number of elements. It can be created using the ListBuilder, and new elements can be added using the add method.

§Usage

Use List to present information in a vertically ordered list.

1. Item one
2. Item two
3. Item three

Implementations§

Source§

impl List

Source

pub fn add( &mut self, label: &str, flags: impl Into<Option<TextFlags>>, ) -> FtuiResult<u16>

Adds a new element to the List.

§Parameters
  • label: A &str representing the element label.
  • flags: A set of TextFlags combined using the bitwise OR operator.
§Notes
  • The bitwise OR operator combines flags like this: flag1 | flag2 | flag3
  • A List element is just a Text component.
§Returns
  • Ok(u16): Return the ID of the added element.
  • Err(FtuiError): Returns an error.
§Example
// Create a new `List`.
let mut list = ListBuilder::new().build();
 
// Add an element labeled "Element" with red text and bold styling.
list.add("Element", TextFlags::COLOR_RED | TextFlags::STYLE_BOLD)?;
Source

pub fn scroll_up(&mut self) -> bool

Attempts to scroll the List up by one position.

§Returns
  • true if the list was successfully scrolled up.
  • false: The List fail to scroll up (already at the top).
§Example
// Create a new `List`.
let mut list = ListBuilder::new().build();

// Add two elements to the list.
list.add(...)?;
list.add(...)?;

// Initially, the list is at the bottom after scrolling down.
list.scroll_down();

// Now it can scroll back up.
assert_eq!(list.scroll_up(), true);
Source

pub fn scroll_down(&mut self) -> bool

Attempts to scroll the List down by one position.

§Returns
  • true if the list was successfully scrolled down.
  • false: The List fail to scroll down (already at the bottom).
§Example
// Create a new `List`.
let mut list = ListBuilder::new().build();

// Add two elements to the list.
list.add(...)?;
list.add(...)?;

// The list can scroll down since it's not at the bottom yet.
assert_eq!(list.scroll_down(), true);
Source

pub fn find(&self, id: u16) -> FtuiResult<usize>

Finds the index of an element by its ID.

§Parameters
  • id: The ID of the Text component to search for.
§Returns
  • Ok(usize): The index of the element with the specified ID.
  • Err(FtuiError): Return an error.
§Example
// Create a new `List`.
let mut list = ListBuilder::new().build();

// Add an element to the list and retrieve its ID.
let id = list.add(...)?;

// Find the index of the element by its ID.
let index = list.find(id)?;
Source

pub fn at(&self, i: usize) -> FtuiResult<&Text>

Returns a reference to the element at the given index, if it exists.

§Parameters
  • i: The index of the element to retrieve.
§Returns
  • Ok(&Text): A reference to the element at the specified index.
  • Err(FtuiError): Returns an error.
§Example
// Create a new `List`.
let mut list = ListBuilder::new().build();

// Add elements to the list.
list.add(...)?;
list.add(...)?;

// Access the first element.
list.at(0)?;
Source

pub fn remove(&mut self, i: usize) -> FtuiResult<()>

Removes the element at the specified index, if it exists.

§Parameters
  • i: The index of the element to remove.
§Returns
  • Ok(()): If the element was successfully removed.
  • Err(FtuiError): If the index is out of bounds.
§Example
// Create a new `List`.
let mut list = ListBuilder::new().build();

// Add elements to the list.
list.add(...)?;
list.add(...)?;

// Remove the first element from the list.
list.remove(0)?;

Auto Trait Implementations§

§

impl Freeze for List

§

impl RefUnwindSafe for List

§

impl Send for List

§

impl Sync for List

§

impl Unpin for List

§

impl UnsafeUnpin for List

§

impl UnwindSafe for List

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.