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
impl List
Sourcepub fn add(
&mut self,
label: &str,
flags: impl Into<Option<TextFlags>>,
) -> FtuiResult<u16>
pub fn add( &mut self, label: &str, flags: impl Into<Option<TextFlags>>, ) -> FtuiResult<u16>
Adds a new element to the List.
§Parameters
label: A&strrepresenting the element label.flags: A set ofTextFlagscombined using the bitwise OR operator.
§Notes
- The bitwise OR operator combines flags like this:
flag1 | flag2 | flag3 - A
Listelement is just aTextcomponent.
§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)?;Sourcepub fn scroll_up(&mut self) -> bool
pub fn scroll_up(&mut self) -> bool
Attempts to scroll the List up by one position.
§Returns
trueif the list was successfully scrolled up.false: TheListfail 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);Sourcepub fn scroll_down(&mut self) -> bool
pub fn scroll_down(&mut self) -> bool
Attempts to scroll the List down by one position.
§Returns
trueif the list was successfully scrolled down.false: TheListfail 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);Sourcepub fn find(&self, id: u16) -> FtuiResult<usize>
pub fn find(&self, id: u16) -> FtuiResult<usize>
Finds the index of an element by its ID.
§Parameters
id: The ID of theTextcomponent 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)?;Sourcepub fn at(&self, i: usize) -> FtuiResult<&Text>
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)?;Sourcepub fn remove(&mut self, i: usize) -> FtuiResult<()>
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> 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