Skip to main content

List

Trait List 

Source
pub trait List {
    // Required methods
    fn render_item<B: Backend>(
        &mut self,
        index: usize,
        hovered: bool,
        layout: Layout,
        backend: &mut B,
    ) -> Result<()>;
    fn is_selectable(&self, index: usize) -> bool;
    fn page_size(&self) -> usize;
    fn should_loop(&self) -> bool;
    fn height_at(&mut self, index: usize, layout: Layout) -> u16;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait to represent a renderable list.

See Select

Required Methods§

Source

fn render_item<B: Backend>( &mut self, index: usize, hovered: bool, layout: Layout, backend: &mut B, ) -> Result<()>

Render a single element at some index.

When rendering the element, only at most layout.max_height lines can be used. If more lines are used, the list may not be rendered properly. The place the terminal cursor ends at does not matter.

layout.max_height may be less than the height given by height_at. layout.render_region can be used to determine which part of the element you want to render.

Source

fn is_selectable(&self, index: usize) -> bool

Whether the element at a particular index is selectable. Those that are not selectable are skipped during navigation.

Source

fn page_size(&self) -> usize

The maximum height that can be taken by the list.

If the total height exceeds the page size, the list will be scrollable.

Source

fn should_loop(&self) -> bool

Whether to wrap around when user gets to the last element.

This only applies when the list is scrollable, i.e. page size > total height.

Source

fn height_at(&mut self, index: usize, layout: Layout) -> u16

The height of the element at an index will take to render

Source

fn len(&self) -> usize

The length of the list

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the list has no elements

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§