Fix more z-index and rendering issues

Co-Authored-By: Antonio Scandurra <antonio@zed.dev>
This commit is contained in:
Kirill Bulatov 2023-12-19 12:30:57 +02:00
parent 825a8f0927
commit 8f1c5375ef
4 changed files with 31 additions and 12 deletions

View file

@ -68,6 +68,7 @@ impl Render for CollabTitlebarItem {
h_stack() h_stack()
.id("titlebar") .id("titlebar")
.z_index(160)
.justify_between() .justify_between()
.w_full() .w_full()
.h(rems(1.75)) .h(rems(1.75))

View file

@ -3,8 +3,8 @@ use crate::{
ListSeparator, ListSubHeader, ListSeparator, ListSubHeader,
}; };
use gpui::{ use gpui::{
px, Action, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView, px, Action, AnyElement, AppContext, DismissEvent, Div, EventEmitter, FocusHandle,
IntoElement, Render, Subscription, View, VisualContext, FocusableView, IntoElement, Render, Subscription, View, VisualContext,
}; };
use menu::{SelectFirst, SelectLast, SelectNext, SelectPrev}; use menu::{SelectFirst, SelectLast, SelectNext, SelectPrev};
use std::{rc::Rc, time::Duration}; use std::{rc::Rc, time::Duration};
@ -18,6 +18,9 @@ pub enum ContextMenuItem {
handler: Rc<dyn Fn(&mut WindowContext)>, handler: Rc<dyn Fn(&mut WindowContext)>,
action: Option<Box<dyn Action>>, action: Option<Box<dyn Action>>,
}, },
CustomEntry {
entry_render: Box<dyn Fn(&mut WindowContext) -> AnyElement>,
},
} }
pub struct ContextMenu { pub struct ContextMenu {
@ -83,6 +86,16 @@ impl ContextMenu {
self self
} }
pub fn custom_entry(
mut self,
entry_render: impl Fn(&mut WindowContext) -> AnyElement + 'static,
) -> Self {
self.items.push(ContextMenuItem::CustomEntry {
entry_render: Box::new(entry_render),
});
self
}
pub fn action(mut self, label: impl Into<SharedString>, action: Box<dyn Action>) -> Self { pub fn action(mut self, label: impl Into<SharedString>, action: Box<dyn Action>) -> Self {
self.items.push(ContextMenuItem::Entry { self.items.push(ContextMenuItem::Entry {
label: label.into(), label: label.into(),
@ -230,9 +243,9 @@ impl Render for ContextMenu {
el el
}) })
.flex_none() .flex_none()
.child( .child(List::new().children(self.items.iter_mut().enumerate().map(
List::new().children(self.items.iter().enumerate().map( |(ix, item)| {
|(ix, item)| match item { match item {
ContextMenuItem::Separator => ListSeparator.into_any_element(), ContextMenuItem::Separator => ListSeparator.into_any_element(),
ContextMenuItem::Header(header) => { ContextMenuItem::Header(header) => {
ListSubHeader::new(header.clone()).into_any_element() ListSubHeader::new(header.clone()).into_any_element()
@ -255,7 +268,7 @@ impl Render for ContextMenu {
Label::new(label.clone()).into_any_element() Label::new(label.clone()).into_any_element()
}; };
ListItem::new(label.clone()) ListItem::new(ix)
.inset(true) .inset(true)
.selected(Some(ix) == self.selected_index) .selected(Some(ix) == self.selected_index)
.on_click(move |_, cx| handler(cx)) .on_click(move |_, cx| handler(cx))
@ -271,9 +284,14 @@ impl Render for ContextMenu {
) )
.into_any_element() .into_any_element()
} }
ContextMenuItem::CustomEntry { entry_render } => ListItem::new(ix)
.inset(true)
.selected(Some(ix) == self.selected_index)
.child(entry_render(cx))
.into_any_element(),
}
}, },
)), ))),
),
) )
} }
} }

View file

@ -129,7 +129,6 @@ impl RenderOnce for ListItem {
fn render(self, cx: &mut WindowContext) -> Self::Rendered { fn render(self, cx: &mut WindowContext) -> Self::Rendered {
h_stack() h_stack()
.id(self.id) .id(self.id)
.bg(gpui::green())
.w_full() .w_full()
.relative() .relative()
// When an item is inset draw the indent spacing outside of the item // When an item is inset draw the indent spacing outside of the item
@ -172,8 +171,8 @@ impl RenderOnce for ListItem {
}) })
}) })
.when_some(self.on_click, |this, on_click| { .when_some(self.on_click, |this, on_click| {
this.cursor_copy() this.cursor_pointer()
.on_click(move |event, cx| on_click(dbg!(event), cx)) .on_click(move |event, cx| on_click(event, cx))
}) })
.when_some(self.on_secondary_mouse_down, |this, on_mouse_down| { .when_some(self.on_secondary_mouse_down, |this, on_mouse_down| {
this.on_mouse_down(MouseButton::Right, move |event, cx| { this.on_mouse_down(MouseButton::Right, move |event, cx| {

View file

@ -96,6 +96,7 @@ impl RenderOnce for TabBar {
div() div()
.id(self.id) .id(self.id)
.z_index(120)
.group("tab_bar") .group("tab_bar")
.flex() .flex()
.flex_none() .flex_none()