TextList

Struct TextList 

Source
pub struct TextList {
    pub items: Vec<String>,
    pub selected: usize,
    pub scroll: usize,
    pub style: Style,
    pub cursor_style: Style,
    pub selected_style: Style,
    pub border_type: BorderType,
    pub height: Option<u16>,
    pub ascii_only: bool,
    pub non_ascii_replace: char,
    pub trim_type: TrimType,
}
Expand description

A widget for selecting from a list of items

Copy & paste examples can be found here

The requirement for the text list widget to render are:

  • Minimal height of 3
  • Height should be updated with self.set_height() before rendering

Fields§

§items: Vec<String>

Items that are in the list, set by .items() or .set_items() function

§selected: usize

The selected item, should be updated using provided functions. 0 should be the first item

§scroll: usize

How many items to scroll down from the first item, should auto update if selected is changed with provided functions.

§style: Style

The style of the entire text list including unselected (normal) items

§cursor_style: Style

Cursor style is the style of the box around the selected item

§selected_style: Style

Style of the selected item

§border_type: BorderType

The border type of cursor

§height: Option<u16>

Height avaliable for the widget, should be updated before rendering the widget

§ascii_only: bool

Only allow ASCII characters to prevent unicode length issues

§non_ascii_replace: char

Character to replace non ASCII characters with, only useful when ascii_only is true

§trim_type: TrimType

How to handle items that got a longer length than the width which the widget can render

Implementations§

Source§

impl TextList

Movement related functions

Source

pub fn update(&mut self) -> Result<(), TextListError>

Should run this function after scoll of selected is updated to ensure that the cursor is on screen

Source

pub fn up(&mut self) -> Result<(), TextListError>

Move cursor up by 1 item (if there is)

Source

pub fn down(&mut self) -> Result<(), TextListError>

Move cursor down by 1 item (if there is)

Source

pub fn pageup(&mut self) -> Result<(), TextListError>

Go up 1 page without changing the cursor position on screen

Source

pub fn pagedown(&mut self) -> Result<(), TextListError>

Go down 1 page without changing the cursor position on screen

Source

pub fn first(&mut self) -> Result<(), TextListError>

Go to the first item

Source

pub fn last(&mut self) -> Result<(), TextListError>

Go to the last item

Source§

impl TextList

Setters

  • set_{feature}() takes ownership of self and returns self
  • {feature}() takes a mutable reference to self
Source

pub fn ascii_only(self, ascii_only: bool) -> Self

Source

pub fn set_ascii_only(&mut self, ascii_only: bool)

Source

pub fn border_type(self, border_type: BorderType) -> Self

Source

pub fn set_border_type(&mut self, border_type: BorderType)

Source

pub fn cursor_style(self, cursor_style: Style) -> Self

Source

pub fn set_cursor_style(&mut self, cursor_style: Style)

Source

pub fn height(self, height: u16) -> Self

Source

pub fn set_height(&mut self, height: u16)

Source

pub fn items<D: Display>(self, items: &[D]) -> Result<Self, Box<dyn Error>>

Source

pub fn set_items<D: Display>( &mut self, items: &[D], ) -> Result<(), Box<dyn Error>>

Source

pub fn selected(self, index: usize) -> Result<Self, TextListError>

Source

pub fn set_selected(&mut self, index: usize) -> Result<(), TextListError>

Source

pub fn non_ascii_replace(self, non_ascii_replace: char) -> Self

Source

pub fn set_non_ascii_replace(&mut self, non_ascii_replace: char)

Source

pub fn selected_style(self, selected_style: Style) -> Self

Source

pub fn set_selected_style(&mut self, selected_style: Style)

Source

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

Source

pub fn set_style(&mut self, style: Style)

Source

pub fn trim_type(self, trim_type: TrimType) -> Self

Source

pub fn set_trim_type(&mut self, trim_type: TrimType)

Trait Implementations§

Source§

impl Clone for TextList

Source§

fn clone(&self) -> TextList

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for TextList

Default (blank) text list

Source§

fn default() -> Self

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

impl Widget for TextList

ratatui::widget::Widget implementation

Source§

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

Note that if self.height does not match the actualy height, it will panic instead because there is no way to return a Result<T, E> out of this function

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> CloneAny for T
where T: Any + Clone,

Source§

fn clone_any(&self) -> Box<dyn CloneAny>

Source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

Source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

Source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Send + Sync>
where T: Send + Sync,

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 = 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.
Source§

impl<T> UnsafeAny for T
where T: Any,