Struct termimad::ListView

source ·
pub struct ListView<'t, T> {
    pub area: Area,
    pub skin: &'t MadSkin,
    /* private fields */
}
Expand description

A filterable list whose columns can be automatically resized.

Notes:

  • another version will allow more than one style per cell (i.e. make the cells composites rather than compounds). Shout out if you need that now.
  • this version doesn’t allow cell wrapping

Fields§

§area: Area§skin: &'t MadSkin

Implementations§

source§

impl<'t, T> ListView<'t, T>

source

pub fn new( area: Area, columns: Vec<ListViewColumn<'t, T>>, skin: &'t MadSkin ) -> Self

Create a new list view with the passed columns.

The columns can’t be changed afterwards but the area can be modified. When two columns have the same title, those titles are merged (but the columns below stay separated).

source

pub fn sort(&mut self, sort: Box<dyn Fn(&T, &T) -> Ordering>)

set a comparator for row sorting

source

pub const fn tbody_height(&self) -> u16

return the height which is available for rows

source

pub fn scrollbar(&self) -> Option<(u16, u16)>

return an option which when filled contains a tupple with the top and bottom of the vertical scrollbar. Return none when the content fits the available space.

source

pub fn add_row(&mut self, data: T)

source

pub fn clear_rows(&mut self)

remove all rows (and selection).

Keep the columns and the sort function, if any.

source

pub fn row_counts(&self) -> (usize, usize)

return both the number of displayed rows and the total number

source

pub fn update_dimensions(&mut self)

recompute the widths of all columns. This should be called when the area size is modified

source

pub fn set_filter(&mut self, filter: Box<dyn Fn(&T) -> bool>)

source

pub fn remove_filter(&mut self)

source

pub fn write_on<W>(&self, w: &mut W) -> Result<(), Error>
where W: Write,

write the list view on the given writer

source

pub fn write(&self) -> Result<(), Error>

display the whole list in its area

source

pub const fn do_scroll_show_bottom(&self) -> bool

return true if the last line of the list is visible

source

pub fn scroll_to_bottom(&mut self)

ensure the last line is visible

source

pub fn try_scroll_lines(&mut self, lines_count: i32)

set the scroll amount. lines_count can be negative

source

pub fn try_scroll_pages(&mut self, pages_count: i32)

set the scroll amount. pages_count can be negative

source

pub fn try_select_next(&mut self, up: bool)

try to select the next visible line

source

pub fn select_first_line(&mut self)

select the first visible line (unless there’s nothing).

source

pub fn select_last_line(&mut self)

select the last visible line (unless there’s nothing).

source

pub fn make_selection_visible(&mut self)

scroll to ensure the selected line (if any) is visible.

This is automatically called by try_scroll and try select functions

source

pub fn get_selection(&self) -> Option<&T>

source

pub const fn has_selection(&self) -> bool

source

pub fn unselect(&mut self)

Auto Trait Implementations§

§

impl<'t, T> Freeze for ListView<'t, T>

§

impl<'t, T> !RefUnwindSafe for ListView<'t, T>

§

impl<'t, T> !Send for ListView<'t, T>

§

impl<'t, T> !Sync for ListView<'t, T>

§

impl<'t, T> Unpin for ListView<'t, T>
where T: Unpin,

§

impl<'t, T> !UnwindSafe for ListView<'t, T>

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> 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.