mod interaction;
mod render;
mod types;
pub use types::{
ListActivity, ListDataSource, ListDelegate, ListEvent, ListItem, ListRow, ListRowState,
ListSelection,
};
use crate::{ScrollView, ScrollViewState};
pub struct ListView<DataSource, Delegate> {
pub(super) scroll_view: ScrollView,
pub(super) data_source: DataSource,
pub(super) delegate: Delegate,
pub(super) touch_started_inside: bool,
pub(super) tap_candidate: bool,
pub(super) highlighted_index: Option<usize>,
pub(super) selected_index: Option<usize>,
pub(super) allows_selection: bool,
}
impl<DataSource, Delegate> ListView<DataSource, Delegate> {
pub fn new(data_source: DataSource, delegate: Delegate) -> Self {
Self {
scroll_view: ScrollView::new(),
data_source,
delegate,
touch_started_inside: false,
tap_candidate: false,
highlighted_index: None,
selected_index: None,
allows_selection: true,
}
}
pub const fn scroll_view(&self) -> &ScrollView {
&self.scroll_view
}
pub fn scroll_view_mut(&mut self) -> &mut ScrollView {
&mut self.scroll_view
}
pub const fn state(&self) -> &ScrollViewState {
self.scroll_view.state()
}
pub fn state_mut(&mut self) -> &mut ScrollViewState {
self.scroll_view.state_mut()
}
pub const fn data_source(&self) -> &DataSource {
&self.data_source
}
pub fn data_source_mut(&mut self) -> &mut DataSource {
&mut self.data_source
}
pub const fn delegate(&self) -> &Delegate {
&self.delegate
}
pub fn delegate_mut(&mut self) -> &mut Delegate {
&mut self.delegate
}
pub const fn allows_selection(&self) -> bool {
self.allows_selection
}
pub fn set_allows_selection(&mut self, allows_selection: bool) {
self.allows_selection = allows_selection;
if !allows_selection {
self.selected_index = None;
}
}
}