1use crate::{
2 geometry::{rect::RectF, vector::Vector2F},
3 sum_tree::{self, SumTree},
4 Element,
5};
6use parking_lot::Mutex;
7use std::sync::Arc;
8
9use crate::ElementBox;
10
11pub struct List {
12 state: ListState,
13}
14
15pub struct ListState(Arc<Mutex<StateInner>>);
16
17struct StateInner {
18 elements: Vec<ElementBox>,
19 heights: SumTree<ElementHeight>,
20}
21
22#[derive(Clone, Debug)]
23enum ElementHeight {
24 Pending,
25 Ready(f32),
26}
27
28#[derive(Clone, Debug, Default)]
29struct ElementHeightSummary {
30 pending_count: usize,
31 height: f32,
32}
33
34impl Element for List {
35 type LayoutState = ();
36
37 type PaintState = ();
38
39 fn layout(
40 &mut self,
41 constraint: crate::SizeConstraint,
42 cx: &mut crate::LayoutContext,
43 ) -> (Vector2F, Self::LayoutState) {
44 todo!()
45 }
46
47 fn after_layout(
48 &mut self,
49 size: Vector2F,
50 layout: &mut Self::LayoutState,
51 cx: &mut crate::AfterLayoutContext,
52 ) {
53 todo!()
54 }
55
56 fn paint(
57 &mut self,
58 bounds: RectF,
59 layout: &mut Self::LayoutState,
60 cx: &mut crate::PaintContext,
61 ) -> Self::PaintState {
62 todo!()
63 }
64
65 fn dispatch_event(
66 &mut self,
67 event: &crate::Event,
68 bounds: RectF,
69 layout: &mut Self::LayoutState,
70 paint: &mut Self::PaintState,
71 cx: &mut crate::EventContext,
72 ) -> bool {
73 todo!()
74 }
75
76 fn debug(
77 &self,
78 bounds: RectF,
79 layout: &Self::LayoutState,
80 paint: &Self::PaintState,
81 cx: &crate::DebugContext,
82 ) -> serde_json::Value {
83 todo!()
84 }
85}
86
87impl ListState {
88 pub fn new(elements: Vec<ElementBox>) -> Self {
89 let mut heights = SumTree::new();
90 heights.extend(elements.iter().map(|_| ElementHeight::Pending), &());
91 Self(Arc::new(Mutex::new(StateInner { elements, heights })))
92 }
93}
94
95impl sum_tree::Item for ElementHeight {
96 type Summary = ElementHeightSummary;
97
98 fn summary(&self) -> Self::Summary {
99 todo!()
100 }
101}
102
103impl sum_tree::Summary for ElementHeightSummary {
104 type Context = ();
105
106 fn add_summary(&mut self, summary: &Self, cx: &Self::Context) {
107 self.pending_count += summary.pending_count;
108 self.height += summary.height;
109 }
110}