pub struct List<'a> { /* private fields */ }Expand description
A scrollable, single-column list of plain-text items with a ListState-driven highlighted
item – Table’s single-column sibling, sharing its windowing and selection story.
One item renders per line, top-aligned in the area it’s rendered into and clipped to
area.width(). state.offset() is the index of the first item drawn – rendering draws
whatever window offset names and does not clamp or auto-scroll it, matching
Table’s and ListState’s existing “only the caller knows the viewport
height” design. Call state.ensure_visible(visible_item_count)
before rendering to keep state.selected() on-screen. If selected() is Some and its item
falls within the visible window, that item is drawn with an inverted highlight background; if
it has scrolled out of view, nothing is highlighted.
item_style and selected_style each default to the same fixed palette as
Table’s row_style/selected_style (a dim gray-blue for unselected items,
a bright-white-on-dark-blue highlight for the selected one); set them with
List::item_style/List::selected_style.
§Examples
use retroglyph_core::{Headless, Rect, Terminal};
use retroglyph_widgets::{List, ListState, StatefulWidget};
let items = ["Alpha", "Bravo", "Charlie"];
let mut state = ListState::new();
state.select(Some(1));
let mut term = Terminal::new(Headless::new(20, 3));
List::new(&items).render(Rect::new(0, 0, 20, 3), &mut term, &mut state);Implementations§
Source§impl<'a> List<'a>
impl<'a> List<'a>
Sourcepub const fn item_style(self, style: Style) -> Self
pub const fn item_style(self, style: Style) -> Self
Set the style of unselected items.
Sourcepub const fn selected_style(self, style: Style) -> Self
pub const fn selected_style(self, style: Style) -> Self
Set the style of the selected item, including its background fill.
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
Applies theme’s named roles to this list: item_style becomes theme.fg on
theme.panel_bg, and selected_style becomes theme.bg on theme.accent.
item_style sets an explicit background rather than leaving it at Style::new()’s
default: an unset background isn’t “transparent” once a real backend draws it (a bare
Color::Default cell paints as solid black behind the glyph – see
retroglyph-software’s DEFAULT_BG), so this widget assumes it’s drawn on
theme.panel_bg, true when composed with a themed super::Panel/super::Modal.
Drawing this list directly on the raw screen background instead needs a manual
.item_style(...) override afterwards.
Call before any manual List::item_style/List::selected_style override you want to
keep.
Sourcepub fn theme_on(self, theme: Theme, bg: Color) -> Self
pub fn theme_on(self, theme: Theme, bg: Color) -> Self
Same as List::theme, but item_style is drawn on bg instead of theme.panel_bg –
for a list drawn directly on a backdrop other than a themed super::Panel/
super::Modal’s fill. List::theme is exactly theme_on(theme, theme.panel_bg).