virtual-list only.Expand description
A long list of equally tall rows that only builds the rows in view, so a hundred thousand items scroll as smoothly as ten.
State holds the items, the selection in the chosen Mode and the
keyboard highlight. Its update handles presses,
keyboard navigation and items arriving from the channel that
subscription owns. The app draws each row with a closure that gets
the item’s index and the item.
A list made with_follow sticks to its end as
items arrive, like a feed or a log. Scrolling up stops following, and
scrolling back to the end, or pressing End, starts again. A list made
with_limit drops its oldest items once it holds
that many, so a stream never grows without bound.
The list resolves its keys through a Keymap of Actions while it
has focus, which it takes when pressed; see default_keymap.
use iced::widget::text;
use iced::{Element, Subscription};
use iced_cube::data::virtual_list::{self, Event, Output, State, virtual_list};
#[derive(Debug, Clone)]
enum Message {
Feed(Event<String>),
}
struct App {
feed: State<String>,
sender: Option<virtual_list::Sender<String>>,
}
impl App {
fn update(&mut self, message: Message) {
let Message::Feed(event) = message;
if let Some(Output::Ready(sender)) = self.feed.update(event) {
// Hand clones of the sender to producers.
self.sender = Some(sender);
}
}
fn view(&self) -> Element<'_, Message> {
virtual_list(&self.feed, |_, line: &String| text(line.as_str()).into())
.height(320)
.on_event(Message::Feed)
.into()
}
fn subscription(&self) -> Subscription<Message> {
virtual_list::subscription().map(Message::Feed)
}
}Structs§
- RowStyle
- The colours of a row.
- State
- The items, the selection, the highlight and whether the list follows its end.
- Status
- How a row is shown.
- Virtual
List - A virtual list builder. Convert it into an
Elementto render.
Enums§
- Action
- What a list keyboard shortcut does.
- Event
- Everything that changes a list.
- Mode
- How items are selected.
- Output
- What the app may need to act on after an
Event.
Constants§
- BATCH_
SIZE - The most items delivered in one
Event::Received. - CHANNEL_
CAPACITY - How many items a producer can send before it has to wait.
- DEFAULT_
PAGE - Rows a page key moves until the list reports how many fit.
- ROW_
HEIGHT - The default height of every row.
Functions§
- default_
keymap - The default list shortcuts:
- frame_
style - The frame around the rows: a subtle border with rounded corners.
- row_
style - Resolves a row’s colours as a tree’s rows do: the accent behind a selected row, a lighter tint under the pointer and a ring around the keyboard highlight. Disabled rows are plain.
- stream
- The stream behind
subscription, for driving it without a runtime. - subscription
- Owns the channel items arrive on. Emits
Event::Readyfirst, then batches of up toBATCH_SIZEitems. - virtual_
list - Renders
state, drawing each row withrow, which gets the item’s index and the item. Withouton_eventthe rows render disabled.