pub struct ListView {
pub id: WidgetId,
pub title: Option<StyledText>,
pub items: Vec<ListItem>,
pub selected_idx: usize,
pub scroll_offset: usize,
pub has_focus: bool,
pub bordered: bool,
pub h_scroll: usize,
pub max_content_width: Option<usize>,
pub show_v_scrollbar: bool,
}Expand description
Declarative description of a ListView widget.
§Examples
use quadraui::{ListItem, ListItemMeasure, ListView, ListViewHit, StyledText, WidgetId};
let list = ListView {
id: WidgetId::new("list:quickfix"),
title: None,
items: vec![ListItem {
text: StyledText::plain("src/main.rs:10: unused import"),
icon: None,
detail: None,
decoration: Default::default(),
}],
selected_idx: 0,
scroll_offset: 0,
has_focus: true,
bordered: false,
h_scroll: 0,
max_content_width: None,
show_v_scrollbar: false,
};
let layout = list.layout(80.0, 10.0, 0.0, |_| ListItemMeasure::new(1.0));
assert_eq!(layout.hit_test(0.0, 0.0), ListViewHit::Item(0));Fields§
§id: WidgetId§title: Option<StyledText>Optional header row shown above the items. None = no header.
items: Vec<ListItem>§selected_idx: usize§scroll_offset: usize§has_focus: bool§bordered: boolWhen true, backends draw a ╭─╮ │ │ ╰─╯ frame around the list
and inset items by 1 cell on each side. Title (if present)
renders as an overlay on the top border (╭─ Title ─╮) instead
of as a separate header strip. Used by modal-style overlays
(tab switcher, file picker). Default false matches the flat
header+rows layout used by quickfix and other inline panels.
h_scroll: usizeHorizontal scroll offset in chars (number of content columns to skip
from the left before rendering). Default 0 = no scroll.
The caller increments / decrements this in response
to Left / Right key events.
max_content_width: Option<usize>Total width (in chars) of the widest item row, including the 2-char
selection prefix, any icon, and the main text. When
max_content_width > visible_area_width the TUI rasteriser reserves
the bottom row of the list area for a horizontal scrollbar.
None = caller hasn’t measured content; no scrollbar shown.
show_v_scrollbar: boolWhen true, backends reserve the rightmost column of the list area
for a vertical scrollbar and paint a track/thumb there. The thumb
position is derived from scroll_offset and items.len().
false (default) = no vertical scrollbar regardless of list length.
The vertical scrollbar is independent of h_scroll / max_content_width:
both scrollbars can be active simultaneously.
Implementations§
Source§impl ListView
impl ListView
Sourcepub fn layout<F>(
&self,
viewport_width: f32,
viewport_height: f32,
title_height: f32,
measure_item: F,
) -> ListViewLayout
pub fn layout<F>( &self, viewport_width: f32, viewport_height: f32, title_height: f32, measure_item: F, ) -> ListViewLayout
Compute the full rendering + hit-test layout for this list.
Per D6: layout decisions live here; backends iterate
visible_items for painting and call hit_test for clicks.
§Arguments
viewport_width,viewport_height— available area in the measurer’s unit.title_height— height reserved for the title row at the top. Pass0.0whenself.titleisNoneor when the caller has chosen to collapse it. The title is not subject toscroll_offset— it stays pinned to the top.measure_item(i)— height for itemi(index intoself.items). Receives the row index so backends can vary height by decoration or other row state.
§Row clipping
The last visible item’s bounds.height is clipped to what fits
inside the viewport (same semantics as TreeView::layout).
Sourcepub fn hscrollbar(&self, area: Rect, row_height: f32) -> Option<Scrollbar>
pub fn hscrollbar(&self, area: Rect, row_height: f32) -> Option<Scrollbar>
Horizontal scrollbar geometry for this list rendered into area.
This is the single source of truth shared by the rasteriser —
which paints the returned Scrollbar — and consumers, which
hit-test the resolved track / thumb_start / thumb_len to
implement thumb dragging. Keeping it here (rather than inline in
each backend’s draw_*) means a consumer never re-derives the
track rect and so can never drift out of sync with the paint.
Reach it backend-agnostically via crate::Backend::list_hscrollbar.
Returns None when no horizontal scrollbar is needed:
max_content_width is None, or the content fits within the
visible width.
§Arguments
area— the list surface rect, in surface-native units (TUI cells, GTK / macOS pixels).row_height— height of one row:1.0on TUI,line_heighton pixel backends. The scrollbar occupies the bottom row of the area (one row above the bottom border inborderedmode), androw_heightalso serves as the minimum thumb length.
Sourcepub fn vscrollbar(&self, area: Rect, row_height: f32) -> Option<Scrollbar>
pub fn vscrollbar(&self, area: Rect, row_height: f32) -> Option<Scrollbar>
Vertical scrollbar geometry for this list rendered into area.
This is the single source of truth shared by the rasteriser — which
paints the returned Scrollbar — and consumers, which hit-test the
resolved track / thumb_start / thumb_len to implement thumb
dragging. Keeping it here (rather than inline in each backend’s
draw_*) means a consumer never re-derives the track rect and so can
never drift out of sync with the paint. Reach it backend-agnostically
via crate::Backend::list_vscrollbar.
Returns None when no vertical scrollbar is needed: show_v_scrollbar
is false, the list is empty, or all items fit in the visible viewport.
§Arguments
area— the list surface rect, in surface-native units (TUI cells, GTK / macOS pixels).row_height— height of one row:1.0on TUI,line_heighton pixel backends. The scrollbar occupies the rightmost column of the area (one column inside the right border inborderedmode), androw_heightalso serves as both the column width and the minimum thumb length (i.e.1.0on TUI — one cell wide, one cell tall minimum thumb).
Trait Implementations§
Source§impl A11yPrimitive for ListView
impl A11yPrimitive for ListView
Source§fn a11y_children(&self) -> Vec<A11yChild>
fn a11y_children(&self) -> Vec<A11yChild>
Source§fn a11y_focus_key(&self) -> Option<String>
fn a11y_focus_key(&self) -> Option<String>
None keeps focus
on the primitive itself.Source§impl<'de> Deserialize<'de> for ListView
impl<'de> Deserialize<'de> for ListView
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ListView
impl StructuralPartialEq for ListView
Auto Trait Implementations§
impl Freeze for ListView
impl RefUnwindSafe for ListView
impl Send for ListView
impl Sync for ListView
impl Unpin for ListView
impl UnsafeUnpin for ListView
impl UnwindSafe for ListView
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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