WIP: Move sum_tree module into gpui so we can use it in List

This commit is contained in:
Nathan Sobo
2021-08-20 16:18:39 -06:00
parent 2507f9b4d4
commit c3dda14490
16 changed files with 190 additions and 138 deletions
+45
View File
@@ -0,0 +1,45 @@
use crate::sum_tree::{self, SumTree};
use parking_lot::Mutex;
use std::sync::Arc;
use crate::ElementBox;
pub struct List {
state: ListState,
}
pub struct ListState(Arc<Mutex<StateInner>>);
struct StateInner {
elements: Vec<ElementBox>,
element_heights: SumTree<ElementHeight>,
}
#[derive(Clone, Debug)]
enum ElementHeight {
Pending,
Ready(f32),
}
#[derive(Clone, Debug, Default)]
struct ElementHeightSummary {
pending_count: usize,
height: f32,
}
impl sum_tree::Item for ElementHeight {
type Summary = ElementHeightSummary;
fn summary(&self) -> Self::Summary {
todo!()
}
}
impl sum_tree::Summary for ElementHeightSummary {
type Context = ();
fn add_summary(&mut self, summary: &Self, cx: &Self::Context) {
self.pending_count += summary.pending_count;
self.height += summary.height;
}
}