use smallvec::SmallVec;
use super::lazy_list_state::LazyListItemInfo;
pub type SmallNodeVec = SmallVec<[u64; 4]>;
pub type SmallOffsetVec = SmallVec<[f32; 4]>;
#[derive(Clone, Debug)]
pub struct LazyListMeasuredItem {
pub index: usize,
pub key: u64,
pub content_type: Option<u64>,
pub main_axis_size: f32,
pub cross_axis_size: f32,
pub offset: f32,
pub node_ids: SmallNodeVec,
pub child_offsets: SmallOffsetVec,
}
impl LazyListMeasuredItem {
pub fn new(
index: usize,
key: u64,
content_type: Option<u64>,
main_axis_size: f32,
cross_axis_size: f32,
) -> Self {
Self {
index,
key,
content_type,
main_axis_size,
cross_axis_size,
offset: 0.0,
node_ids: SmallVec::new(),
child_offsets: SmallVec::new(),
}
}
pub fn to_item_info(&self) -> LazyListItemInfo {
LazyListItemInfo {
index: self.index,
key: self.key,
offset: self.offset,
size: self.main_axis_size,
}
}
}
#[derive(Clone, Debug)]
pub struct LazyListMeasureResult {
pub visible_items: Vec<LazyListMeasuredItem>,
pub first_visible_item_index: usize,
pub first_visible_item_scroll_offset: f32,
pub viewport_size: f32,
pub total_content_size: f32,
pub can_scroll_forward: bool,
pub can_scroll_backward: bool,
}
impl Default for LazyListMeasureResult {
fn default() -> Self {
Self {
visible_items: Vec::new(),
first_visible_item_index: 0,
first_visible_item_scroll_offset: 0.0,
viewport_size: 0.0,
total_content_size: 0.0,
can_scroll_forward: false,
can_scroll_backward: false,
}
}
}