This commit is contained in:
Nathan Sobo 2021-08-20 16:34:46 -06:00
parent c3dda14490
commit d0a5bc694c

View file

@ -1,4 +1,8 @@
use crate::sum_tree::{self, SumTree};
use crate::{
geometry::{rect::RectF, vector::Vector2F},
sum_tree::{self, SumTree},
Element,
};
use parking_lot::Mutex;
use std::sync::Arc;
@ -12,7 +16,7 @@ pub struct ListState(Arc<Mutex<StateInner>>);
struct StateInner {
elements: Vec<ElementBox>,
element_heights: SumTree<ElementHeight>,
heights: SumTree<ElementHeight>,
}
#[derive(Clone, Debug)]
@ -27,6 +31,67 @@ struct ElementHeightSummary {
height: f32,
}
impl Element for List {
type LayoutState = ();
type PaintState = ();
fn layout(
&mut self,
constraint: crate::SizeConstraint,
cx: &mut crate::LayoutContext,
) -> (Vector2F, Self::LayoutState) {
todo!()
}
fn after_layout(
&mut self,
size: Vector2F,
layout: &mut Self::LayoutState,
cx: &mut crate::AfterLayoutContext,
) {
todo!()
}
fn paint(
&mut self,
bounds: RectF,
layout: &mut Self::LayoutState,
cx: &mut crate::PaintContext,
) -> Self::PaintState {
todo!()
}
fn dispatch_event(
&mut self,
event: &crate::Event,
bounds: RectF,
layout: &mut Self::LayoutState,
paint: &mut Self::PaintState,
cx: &mut crate::EventContext,
) -> bool {
todo!()
}
fn debug(
&self,
bounds: RectF,
layout: &Self::LayoutState,
paint: &Self::PaintState,
cx: &crate::DebugContext,
) -> serde_json::Value {
todo!()
}
}
impl ListState {
pub fn new(elements: Vec<ElementBox>) -> Self {
let mut heights = SumTree::new();
heights.extend(elements.iter().map(|_| ElementHeight::Pending), &());
Self(Arc::new(Mutex::new(StateInner { elements, heights })))
}
}
impl sum_tree::Item for ElementHeight {
type Summary = ElementHeightSummary;