Skip to main content

ListView

Struct ListView 

Source
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: bool

When 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: usize

Horizontal 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: bool

When 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

Source

pub fn layout<F>( &self, viewport_width: f32, viewport_height: f32, title_height: f32, measure_item: F, ) -> ListViewLayout
where F: Fn(usize) -> ListItemMeasure,

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. Pass 0.0 when self.title is None or when the caller has chosen to collapse it. The title is not subject to scroll_offset — it stays pinned to the top.
  • measure_item(i) — height for item i (index into self.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).

Source

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.0 on TUI, line_height on pixel backends. The scrollbar occupies the bottom row of the area (one row above the bottom border in bordered mode), and row_height also serves as the minimum thumb length.
Source

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.0 on TUI, line_height on pixel backends. The scrollbar occupies the rightmost column of the area (one column inside the right border in bordered mode), and row_height also serves as both the column width and the minimum thumb length (i.e. 1.0 on TUI — one cell wide, one cell tall minimum thumb).

Trait Implementations§

Source§

impl A11yPrimitive for ListView

Source§

fn a11y_info(&self) -> A11yInfo

This primitive’s own role, accessible name and state.
Source§

fn a11y_children(&self) -> Vec<A11yChild>

The sub-nodes this primitive contains, in reading order. Defaults to none.
Source§

fn a11y_focus_key(&self) -> Option<String>

The key of the child that should hold accessibility focus while this primitive is the focused widget — a listbox points at its active row, a toolbar at its focused button. None keeps focus on the primitive itself.
Source§

impl Clone for ListView

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ListView

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ListView

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ListView

Source§

impl PartialEq for ListView

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ListView

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ListView

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more