mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-07 02:57:34 +00:00
Fix drawing uniform list elements when scrolling
This commit is contained in:
parent
8aaa46a1b6
commit
eaf90a4fbd
1 changed files with 21 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
point, px, size, AnyElement, AvailableSpace, Bounds, Element, ElementId, InteractiveElement,
|
point, px, size, AnyElement, AvailableSpace, BorrowWindow, Bounds, ContentMask, Element,
|
||||||
InteractiveElementState, Interactivity, LayoutId, Pixels, Point, Render, RenderOnce, Size,
|
ElementId, InteractiveElement, InteractiveElementState, Interactivity, LayoutId, Pixels, Point,
|
||||||
StyleRefinement, Styled, View, ViewContext, WindowContext,
|
Render, RenderOnce, Size, StyleRefinement, Styled, View, ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
|
use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
|
||||||
|
@ -210,31 +210,31 @@ impl Element for UniformList {
|
||||||
scroll_offset: shared_scroll_offset,
|
scroll_offset: shared_scroll_offset,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let visible_item_count = if item_height > px(0.) {
|
|
||||||
(padded_bounds.size.height / item_height).ceil() as usize + 1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
let first_visible_element_ix =
|
let first_visible_element_ix =
|
||||||
(-scroll_offset.y / item_height).floor() as usize;
|
(-scroll_offset.y / item_height).floor() as usize;
|
||||||
|
let last_visible_element_ix =
|
||||||
|
((-scroll_offset.y + padded_bounds.size.height) / item_height).ceil()
|
||||||
|
as usize;
|
||||||
let visible_range = first_visible_element_ix
|
let visible_range = first_visible_element_ix
|
||||||
..cmp::min(
|
..cmp::min(last_visible_element_ix, self.item_count);
|
||||||
first_visible_element_ix + visible_item_count,
|
|
||||||
self.item_count,
|
|
||||||
);
|
|
||||||
|
|
||||||
let items = (self.render_items)(visible_range.clone(), cx);
|
let items = (self.render_items)(visible_range.clone(), cx);
|
||||||
cx.with_z_index(1, |cx| {
|
cx.with_z_index(1, |cx| {
|
||||||
for (item, ix) in items.into_iter().zip(visible_range) {
|
let content_mask = ContentMask {
|
||||||
let item_origin = padded_bounds.origin
|
bounds: padded_bounds,
|
||||||
+ point(px(0.), item_height * ix + scroll_offset.y);
|
};
|
||||||
let available_space = size(
|
cx.with_content_mask(Some(content_mask), |cx| {
|
||||||
AvailableSpace::Definite(padded_bounds.size.width),
|
for (item, ix) in items.into_iter().zip(visible_range) {
|
||||||
AvailableSpace::Definite(item_height),
|
let item_origin = padded_bounds.origin
|
||||||
);
|
+ point(px(0.), item_height * ix + scroll_offset.y);
|
||||||
item.draw(item_origin, available_space, cx);
|
let available_space = size(
|
||||||
}
|
AvailableSpace::Definite(padded_bounds.size.width),
|
||||||
|
AvailableSpace::Definite(item_height),
|
||||||
|
);
|
||||||
|
item.draw(item_origin, available_space, cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue