Guide API
Skip to main content

ListViewerState

Struct ListViewerState 

Source
pub struct ListViewerState {
    pub state: ViewState,
    pub num_cols: i32,
    pub top_item: i32,
    pub focused: i32,
    pub range: i32,
    pub indent: i32,
    pub h_scroll_bar: Option<ViewId>,
    pub v_scroll_bar: Option<ViewId>,
    pub find_mode: FindMode,
    pub query: String,
    /* private fields */
}
Expand description

The shared state of every list-viewer. A concrete list widget embeds one and exposes it via ListViewer::lv/ListViewer::lv_mut.

§Turbo Vision heritage

The data half of TListViewer (tlstview.cpp) — its instance fields.

Fields§

§state: ViewState

View state (geometry, flags, …) — the View composition target.

§num_cols: i32

The number of columns (>= 1) the items are laid out in.

Controls the column-major item layout: relative to the first visible row top_item, column j holds items top_item + j * size.y .. top_item + (j + 1) * size.y. Must be >= 1; the constructor clamps smaller values to 1 and fires a debug_assert.

§top_item: i32

The item index drawn at the top-left cell (the scroll offset).

Adjusted by focus_item to keep focused visible. Read it to find out which item is at the top of the current view; set it directly only when constructing a pre-scrolled list before insertion.

§focused: i32

The index of the item that holds the keyboard cursor.

Changed by keyboard nav, mouse clicks, and the scrollbar read-sync. Read it to find the current selection; move it by calling focus_item or focus_item_num (both keep top_item in sync).

§range: i32

The total number of items in the list.

Set this by calling set_range, which also resets focused if it now falls past the end and (re)publishes the vertical bar’s range. Reading it directly is fine; writing it directly is not (the bar and focused would be left inconsistent).

§indent: i32

Cached horizontal-bar value — draw cannot reach the sibling bar, so the value is cached here and refreshed by the read-sync (apply_scroll).

§h_scroll_bar: Option<ViewId>

The horizontal scrollbar, identified by ViewId (None if absent).

Pass the bar’s id when constructing via ListViewerState::new. After insertion call update_steps to publish the initial step sizes. The pump then brokers all subsequent reads and writes through the apply_scroll / Deferred::SyncListViewer seam — do NOT read or write the bar directly from event handlers.

§v_scroll_bar: Option<ViewId>

The vertical scrollbar, identified by ViewId (None if absent).

Same wiring rules as h_scroll_bar: pass the id at construction, call update_steps after insertion, and let the pump broker all bar ↔ list synchronization.

§find_mode: FindMode

Find mode (opt-in). Off keeps the classic prefix lookup; the other variants enable the accumulated-query find-and-highlight.

§query: String

The accumulated find query (find mode only; always empty when Off).

Implementations§

Source§

impl ListViewerState

Source

pub fn new( bounds: Rect, num_cols: i32, h_scroll_bar: Option<ViewId>, v_scroll_bar: Option<ViewId>, ) -> Self

Create list-viewer state for bounds, with num_cols columns and optional scroll bar ids.

Call this before inserting the widget into its parent group. Because there is no Context at construction time, bar step sizes cannot be published yet — call update_steps immediately after the widget is inserted (the same two-step pattern the scroller uses). The state starts at the top of an empty list (top_item = 0, focused = 0, range = 0).

Sets ofFirstClick and ofSelectable on the embedded ViewState. num_cols < 1 is clamped to 1 with a debug_assert.

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
§

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

§

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.
§

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.
§

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.
§

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.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.