Introduce autoscroll support for elements (#10889)
This pull request introduces the new `ElementContext::request_autoscroll(bounds)` and `ElementContext::take_autoscroll()` methods in GPUI. These new APIs enable container elements such as `List` to change their scroll position if one of their children requested an autoscroll. We plan to use this in the revamped assistant. As a drive-by, we also: - Renamed `Element::before_layout` to `Element::request_layout` - Renamed `Element::after_layout` to `Element::prepaint` - Introduced a new `List::splice_focusable` method to splice focusable elements into the list, which enables rendering offscreen elements that are focused. Release Notes: - N/A --------- Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
efcd31c254
commit
bcbf2f2fd3
31 changed files with 780 additions and 513 deletions
|
@ -85,14 +85,14 @@ struct AnimationState {
|
|||
}
|
||||
|
||||
impl<E: IntoElement + 'static> Element for AnimationElement<E> {
|
||||
type BeforeLayout = AnyElement;
|
||||
type RequestLayoutState = AnyElement;
|
||||
|
||||
type AfterLayout = ();
|
||||
type PrepaintState = ();
|
||||
|
||||
fn before_layout(
|
||||
fn request_layout(
|
||||
&mut self,
|
||||
cx: &mut crate::ElementContext,
|
||||
) -> (crate::LayoutId, Self::BeforeLayout) {
|
||||
) -> (crate::LayoutId, Self::RequestLayoutState) {
|
||||
cx.with_element_state(Some(self.id.clone()), |state, cx| {
|
||||
let state = state.unwrap().unwrap_or_else(|| AnimationState {
|
||||
start: Instant::now(),
|
||||
|
@ -130,24 +130,24 @@ impl<E: IntoElement + 'static> Element for AnimationElement<E> {
|
|||
})
|
||||
}
|
||||
|
||||
((element.before_layout(cx), element), Some(state))
|
||||
((element.request_layout(cx), element), Some(state))
|
||||
})
|
||||
}
|
||||
|
||||
fn after_layout(
|
||||
fn prepaint(
|
||||
&mut self,
|
||||
_bounds: crate::Bounds<crate::Pixels>,
|
||||
element: &mut Self::BeforeLayout,
|
||||
element: &mut Self::RequestLayoutState,
|
||||
cx: &mut crate::ElementContext,
|
||||
) -> Self::AfterLayout {
|
||||
element.after_layout(cx);
|
||||
) -> Self::PrepaintState {
|
||||
element.prepaint(cx);
|
||||
}
|
||||
|
||||
fn paint(
|
||||
&mut self,
|
||||
_bounds: crate::Bounds<crate::Pixels>,
|
||||
element: &mut Self::BeforeLayout,
|
||||
_: &mut Self::AfterLayout,
|
||||
element: &mut Self::RequestLayoutState,
|
||||
_: &mut Self::PrepaintState,
|
||||
cx: &mut crate::ElementContext,
|
||||
) {
|
||||
element.paint(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue