Replace Default trait bound with a zero function on Summary/Dimension (#17975)
This lets us provide a context when constructing the zero value. We need it so we can require anchors to be associated with a buffer id, which we're doing as part of simplifying the multibuffer API. Release Notes: - N/A Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
4d074fc737
commit
2e72fd210a
28 changed files with 706 additions and 349 deletions
|
@ -181,7 +181,7 @@ impl ListState {
|
|||
last_layout_bounds: None,
|
||||
last_padding: None,
|
||||
render_item: Box::new(render_item),
|
||||
items: SumTree::new(),
|
||||
items: SumTree::default(),
|
||||
logical_scroll_top: None,
|
||||
alignment,
|
||||
overdraw,
|
||||
|
@ -228,7 +228,7 @@ impl ListState {
|
|||
) {
|
||||
let state = &mut *self.0.borrow_mut();
|
||||
|
||||
let mut old_items = state.items.cursor::<Count>();
|
||||
let mut old_items = state.items.cursor::<Count>(&());
|
||||
let mut new_items = old_items.slice(&Count(old_range.start), Bias::Right, &());
|
||||
old_items.seek_forward(&Count(old_range.end), Bias::Right, &());
|
||||
|
||||
|
@ -297,7 +297,7 @@ impl ListState {
|
|||
scroll_top.item_ix = ix;
|
||||
scroll_top.offset_in_item = px(0.);
|
||||
} else {
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>();
|
||||
let mut cursor = state.items.cursor::<ListItemSummary>(&());
|
||||
cursor.seek(&Count(ix + 1), Bias::Right, &());
|
||||
let bottom = cursor.start().height + padding.top;
|
||||
let goal_top = px(0.).max(bottom - height + padding.bottom);
|
||||
|
@ -326,7 +326,7 @@ impl ListState {
|
|||
return None;
|
||||
}
|
||||
|
||||
let mut cursor = state.items.cursor::<(Count, Height)>();
|
||||
let mut cursor = state.items.cursor::<(Count, Height)>(&());
|
||||
cursor.seek(&Count(scroll_top.item_ix), Bias::Right, &());
|
||||
|
||||
let scroll_top = cursor.start().1 .0 + scroll_top.offset_in_item;
|
||||
|
@ -348,7 +348,7 @@ impl ListState {
|
|||
|
||||
impl StateInner {
|
||||
fn visible_range(&self, height: Pixels, scroll_top: &ListOffset) -> Range<usize> {
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>();
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(&());
|
||||
cursor.seek(&Count(scroll_top.item_ix), Bias::Right, &());
|
||||
let start_y = cursor.start().height + scroll_top.offset_in_item;
|
||||
cursor.seek_forward(&Height(start_y + height), Bias::Left, &());
|
||||
|
@ -378,7 +378,7 @@ impl StateInner {
|
|||
if self.alignment == ListAlignment::Bottom && new_scroll_top == scroll_max {
|
||||
self.logical_scroll_top = None;
|
||||
} else {
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>();
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(&());
|
||||
cursor.seek(&Height(new_scroll_top), Bias::Right, &());
|
||||
let item_ix = cursor.start().count;
|
||||
let offset_in_item = new_scroll_top - cursor.start().height;
|
||||
|
@ -418,7 +418,7 @@ impl StateInner {
|
|||
}
|
||||
|
||||
fn scroll_top(&self, logical_scroll_top: &ListOffset) -> Pixels {
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>();
|
||||
let mut cursor = self.items.cursor::<ListItemSummary>(&());
|
||||
cursor.seek(&Count(logical_scroll_top.item_ix), Bias::Right, &());
|
||||
cursor.start().height + logical_scroll_top.offset_in_item
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ impl StateInner {
|
|||
AvailableSpace::MinContent,
|
||||
);
|
||||
|
||||
let mut cursor = old_items.cursor::<Count>();
|
||||
let mut cursor = old_items.cursor::<Count>(&());
|
||||
|
||||
// Render items after the scroll top, including those in the trailing overdraw
|
||||
cursor.seek(&Count(scroll_top.item_ix), Bias::Right, &());
|
||||
|
@ -560,7 +560,7 @@ impl StateInner {
|
|||
}
|
||||
|
||||
let measured_range = cursor.start().0..(cursor.start().0 + measured_items.len());
|
||||
let mut cursor = old_items.cursor::<Count>();
|
||||
let mut cursor = old_items.cursor::<Count>(&());
|
||||
let mut new_items = cursor.slice(&Count(measured_range.start), Bias::Right, &());
|
||||
new_items.extend(measured_items, &());
|
||||
cursor.seek(&Count(measured_range.end), Bias::Right, &());
|
||||
|
@ -573,7 +573,7 @@ impl StateInner {
|
|||
if !rendered_focused_item {
|
||||
let mut cursor = self
|
||||
.items
|
||||
.filter::<_, Count>(|summary| summary.has_focus_handles);
|
||||
.filter::<_, Count>(&(), |summary| summary.has_focus_handles);
|
||||
cursor.next(&());
|
||||
while let Some(item) = cursor.item() {
|
||||
if item.contains_focused(cx) {
|
||||
|
@ -629,7 +629,7 @@ impl StateInner {
|
|||
offset_in_item: autoscroll_bounds.top() - item_origin.y,
|
||||
});
|
||||
} else if autoscroll_bounds.bottom() > bounds.bottom() {
|
||||
let mut cursor = self.items.cursor::<Count>();
|
||||
let mut cursor = self.items.cursor::<Count>(&());
|
||||
cursor.seek(&Count(item.index), Bias::Right, &());
|
||||
let mut height = bounds.size.height - padding.top - padding.bottom;
|
||||
|
||||
|
@ -883,6 +883,10 @@ impl sum_tree::Item for ListItem {
|
|||
impl sum_tree::Summary for ListItemSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &Self, _: &()) {
|
||||
self.count += summary.count;
|
||||
self.rendered_count += summary.rendered_count;
|
||||
|
@ -893,12 +897,20 @@ impl sum_tree::Summary for ListItemSummary {
|
|||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ListItemSummary> for Count {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ListItemSummary, _: &()) {
|
||||
self.0 += summary.count;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ListItemSummary> for Height {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ListItemSummary, _: &()) {
|
||||
self.0 += summary.height;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue