picker: Reintroduce headers and footers (#3786)

Update VCS menu to match Zed1.
<img width="444" alt="image"
src="https://github.com/zed-industries/zed/assets/24362066/6cb27510-f501-46bc-862f-1fb78006b77c">

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2023-12-22 18:10:59 +01:00 committed by GitHub
parent 87ff5f04cb
commit 25a5eda76f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 92 deletions

View file

@ -1,8 +1,8 @@
use editor::Editor;
use gpui::{
div, prelude::*, uniform_list, AppContext, DismissEvent, Div, EventEmitter, FocusHandle,
FocusableView, Length, MouseButton, MouseDownEvent, Render, Task, UniformListScrollHandle,
View, ViewContext, WindowContext,
div, prelude::*, uniform_list, AnyElement, AppContext, DismissEvent, Div, EventEmitter,
FocusHandle, FocusableView, Length, MouseButton, MouseDownEvent, Render, Task,
UniformListScrollHandle, View, ViewContext, WindowContext,
};
use std::{cmp, sync::Arc};
use ui::{prelude::*, v_stack, Color, Divider, Label, ListItem, ListItemSpacing};
@ -40,6 +40,12 @@ pub trait PickerDelegate: Sized + 'static {
selected: bool,
cx: &mut ViewContext<Picker<Self>>,
) -> Option<Self::ListItem>;
fn render_header(&self, _: &mut ViewContext<Picker<Self>>) -> Option<AnyElement> {
None
}
fn render_footer(&self, _: &mut ViewContext<Picker<Self>>) -> Option<AnyElement> {
None
}
}
impl<D: PickerDelegate> FocusableView for Picker<D> {
@ -253,6 +259,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
v_stack()
.flex_grow()
.py_2()
.children(self.delegate.render_header(cx))
.child(
uniform_list(
cx.view().clone(),
@ -286,6 +293,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
)
.track_scroll(self.scroll_handle.clone())
)
.max_h_72()
.overflow_hidden(),
)
@ -301,5 +309,6 @@ impl<D: PickerDelegate> Render for Picker<D> {
),
)
})
.children(self.delegate.render_footer(cx))
}
}