Skip to main content

List

Struct List 

Source
pub struct List<'a, Selection = RowSelection> { /* private fields */ }
Expand description

List widget.

Fully compatible with ratatui List. Adds Scroll, selection models, and event-handling.

Implementations§

Source§

impl<'a, Selection> List<'a, Selection>

Source

pub fn new<T>(items: T) -> Self
where T: IntoIterator, T::Item: Into<ListItem<'a>>,

New list.

Source

pub fn items<T>(self, items: T) -> Self
where T: IntoIterator, T::Item: Into<ListItem<'a>>,

Set items.

Source

pub fn block(self, block: Block<'a>) -> Self

Border support.

Source

pub fn scroll(self, scroll: Scroll<'a>) -> Self

Scroll support.

Source

pub fn styles_opt(self, styles: Option<ListStyle>) -> Self

Set all styles.

Source

pub fn styles(self, styles: ListStyle) -> Self

Set all styles.

Source

pub fn style<S: Into<Style>>(self, style: S) -> Self

Base style

Source

pub fn select_style<S: Into<Style>>(self, select_style: S) -> Self

Select style.

Source

pub fn focus_style<S: Into<Style>>(self, focus_style: S) -> Self

Focused style.

Source

pub fn varying_heights(self, varying: bool) -> Self

If your list uses varying row-heights for each row calculating the correct offset to show a specific item will fail.

With this flag the row-height for each row is stored as part of the state.

Source

pub fn direction(self, direction: ListDirection) -> Self

Defines the direction how the items are displayed.

With bottom to top, the item at offset is rendered at the bottom of the area and moves up for the next items. Navigation with the arrow keys will also reverse and follows the screen directions.

Source

pub fn highlight_symbol<L: Into<Line<'a>>>(self, highlight_symbol: L) -> Self

Set the symbol to be displayed in front of the selected item. By default, there are no highlight symbol.

Source

pub fn highlight_style<S: Into<Style>>(self, style: S) -> Self

Separate style for the highlight symbol.

When no set the symbol uses the list-style and the select-style.

Source

pub fn repeat_highlight_symbol(self, repeat: bool) -> Self

Set whether to repeat the highlight symbol and style over selected multi-line items. This is false by default.

Source

pub fn highlight_spacing(self, value: HighlightSpacing) -> Self

Set when to show the highlight spacing

The highlight spacing is the spacing that is allocated for the selection symbol (if enabled) and is used to shift the list when an item is selected. This method allows you to configure when this spacing is allocated.

  • HighlightSpacing::Always will always allocate the spacing, regardless of whether an item is selected or not. This means that the table will never change size, regardless of if an item is selected or not.
  • HighlightSpacing::WhenSelected will only allocate the spacing if an item is selected. This means that the table will shift when an item is selected. This is the default setting for backwards compatibility, but it is recommended to use HighlightSpacing::Always for a better user experience.
  • HighlightSpacing::Never will never allocate the spacing, regardless of whether an item is selected or not. This means that the highlight symbol will never be drawn.
Source

pub fn scroll_padding(self, padding: usize) -> Self

Sets the number of items around the currently selected item that should be kept visible.

Source

pub fn len(&self) -> usize

Number of items.

Source

pub fn is_empty(&self) -> bool

Empty?

Source

pub fn width(&self) -> u16

Inherent width

Source

pub fn height(&self) -> u16

Inherent height

Trait Implementations§

Source§

impl<'a, Selection: Clone> Clone for List<'a, Selection>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, Selection: Debug> Debug for List<'a, Selection>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, Selection: Default> Default for List<'a, Selection>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, Item, Selection> FromIterator<Item> for List<'a, Selection>
where Item: Into<ListItem<'a>>,

Source§

fn from_iter<Iter: IntoIterator<Item = Item>>(iter: Iter) -> Self

Creates a value from an iterator. Read more
Source§

impl<Selection: ListSelection> StatefulWidget for List<'_, Selection>

Source§

type State = ListState<Selection>

State associated with the stateful widget. Read more
Source§

fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom stateful widget.

Auto Trait Implementations§

§

impl<'a, Selection> Forget for List<'a, Selection>

§

impl<'a, Selection> Freeze for List<'a, Selection>
where PhantomData<Selection>: Freeze,

§

impl<'a, Selection> Move for List<'a, Selection>

§

impl<'a, Selection> RefUnwindSafe for List<'a, Selection>
where PhantomData<Selection>: RefUnwindSafe,

§

impl<'a, Selection> Send for List<'a, Selection>
where PhantomData<Selection>: Send,

§

impl<'a, Selection> Sync for List<'a, Selection>
where PhantomData<Selection>: Sync,

§

impl<'a, Selection> Unpin for List<'a, Selection>
where PhantomData<Selection>: Unpin,

§

impl<'a, Selection> UnsafeUnpin for List<'a, Selection>
where PhantomData<Selection>: UnsafeUnpin,

§

impl<'a, Selection> UnwindSafe for List<'a, Selection>
where PhantomData<Selection>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.