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: usizeThe selected item, should be updated using provided functions. 0 should be the first item
scroll: usizeHow many items to scroll down from the first item, should auto update if selected is
changed with provided functions.
style: StyleThe style of the entire text list including unselected (normal) items
cursor_style: StyleCursor style is the style of the box around the selected item
selected_style: StyleStyle of the selected item
border_type: BorderTypeThe border type of cursor
height: Option<u16>Height avaliable for the widget, should be updated before rendering the widget
ascii_only: boolOnly allow ASCII characters to prevent unicode length issues
non_ascii_replace: charCharacter to replace non ASCII characters with, only useful when ascii_only is true
trim_type: TrimTypeHow to handle items that got a longer length than the width which the widget can render
Implementations§
Source§impl TextList
Movement related functions
impl TextList
Movement related functions
Sourcepub fn update(&mut self) -> Result<(), TextListError>
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
Sourcepub fn up(&mut self) -> Result<(), TextListError>
pub fn up(&mut self) -> Result<(), TextListError>
Move cursor up by 1 item (if there is)
Sourcepub fn down(&mut self) -> Result<(), TextListError>
pub fn down(&mut self) -> Result<(), TextListError>
Move cursor down by 1 item (if there is)
Sourcepub fn pageup(&mut self) -> Result<(), TextListError>
pub fn pageup(&mut self) -> Result<(), TextListError>
Go up 1 page without changing the cursor position on screen
Sourcepub fn pagedown(&mut self) -> Result<(), TextListError>
pub fn pagedown(&mut self) -> Result<(), TextListError>
Go down 1 page without changing the cursor position on screen
Sourcepub fn first(&mut self) -> Result<(), TextListError>
pub fn first(&mut self) -> Result<(), TextListError>
Go to the first item
Sourcepub fn last(&mut self) -> Result<(), TextListError>
pub fn last(&mut self) -> Result<(), TextListError>
Go to the last item
Source§impl TextList
Setters
impl TextList
Setters
set_{feature}()takes ownership of self and returns self{feature}()takes a mutable reference to self
pub fn ascii_only(self, ascii_only: bool) -> Self
pub fn set_ascii_only(&mut self, ascii_only: bool)
pub fn border_type(self, border_type: BorderType) -> Self
pub fn set_border_type(&mut self, border_type: BorderType)
pub fn cursor_style(self, cursor_style: Style) -> Self
pub fn set_cursor_style(&mut self, cursor_style: Style)
pub fn height(self, height: u16) -> Self
pub fn set_height(&mut self, height: u16)
pub fn items<D: Display>(self, items: &[D]) -> Result<Self, Box<dyn Error>>
pub fn set_items<D: Display>( &mut self, items: &[D], ) -> Result<(), Box<dyn Error>>
pub fn selected(self, index: usize) -> Result<Self, TextListError>
pub fn set_selected(&mut self, index: usize) -> Result<(), TextListError>
pub fn non_ascii_replace(self, non_ascii_replace: char) -> Self
pub fn set_non_ascii_replace(&mut self, non_ascii_replace: char)
pub fn selected_style(self, selected_style: Style) -> Self
pub fn set_selected_style(&mut self, selected_style: Style)
pub fn style(self, style: Style) -> Self
pub fn set_style(&mut self, style: Style)
pub fn trim_type(self, trim_type: TrimType) -> Self
pub fn set_trim_type(&mut self, trim_type: TrimType)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TextList
impl RefUnwindSafe for TextList
impl Send for TextList
impl Sync for TextList
impl Unpin for TextList
impl UnwindSafe for TextList
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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