gpui: Rework overlay element (#9911)
There was a problem using deferred draws with `overlay` and tooltips at the same time. The `overlay` element was removed and was split up into two separate elements - `deferred` - `anchored` - Mimics the `overlay` behavior but does not render its children as deferred `tooltip_container` does not defer its drawing anymore and only uses `anchored`. /cc @as-cii Release Notes: - Fixed tooltip for the recent projects popover not showing anymore --------- Co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
parent
49144d94bf
commit
77f1cc95b8
12 changed files with 144 additions and 136 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use gpui::{
|
||||
div, overlay, point, prelude::FluentBuilder, px, AnchorCorner, AnyElement, Bounds,
|
||||
anchored, deferred, div, point, prelude::FluentBuilder, px, AnchorCorner, AnyElement, Bounds,
|
||||
DismissEvent, DispatchPhase, Element, ElementContext, ElementId, HitboxId, InteractiveElement,
|
||||
IntoElement, LayoutId, ManagedView, MouseDownEvent, ParentElement, Pixels, Point, View,
|
||||
VisualContext, WindowContext,
|
||||
|
@ -176,17 +176,15 @@ impl<M: ManagedView> Element for PopoverMenu<M> {
|
|||
let mut menu_layout_id = None;
|
||||
|
||||
let menu_element = element_state.menu.borrow_mut().as_mut().map(|menu| {
|
||||
let mut overlay = overlay().snap_to_window().anchor(this.anchor);
|
||||
|
||||
let mut anchored = anchored().snap_to_window().anchor(this.anchor);
|
||||
if let Some(child_bounds) = element_state.child_bounds {
|
||||
overlay = overlay.position(
|
||||
anchored = anchored.position(
|
||||
this.resolved_attach().corner(child_bounds) + this.resolved_offset(cx),
|
||||
);
|
||||
}
|
||||
let mut element =
|
||||
deferred(anchored.child(div().occlude().child(menu.clone()))).into_any();
|
||||
|
||||
let mut element = overlay
|
||||
.child(div().occlude().child(menu.clone()))
|
||||
.into_any();
|
||||
menu_layout_id = Some(element.before_layout(cx));
|
||||
element
|
||||
});
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use gpui::{
|
||||
div, overlay, AnchorCorner, AnyElement, Bounds, DismissEvent, DispatchPhase, Element,
|
||||
ElementContext, ElementId, Hitbox, InteractiveElement, IntoElement, LayoutId, ManagedView,
|
||||
MouseButton, MouseDownEvent, ParentElement, Pixels, Point, View, VisualContext, WindowContext,
|
||||
anchored, deferred, div, AnchorCorner, AnyElement, Bounds, DismissEvent, DispatchPhase,
|
||||
Element, ElementContext, ElementId, Hitbox, InteractiveElement, IntoElement, LayoutId,
|
||||
ManagedView, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, View, VisualContext,
|
||||
WindowContext,
|
||||
};
|
||||
|
||||
pub struct RightClickMenu<M: ManagedView> {
|
||||
|
@ -103,15 +104,15 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
|
|||
let mut menu_layout_id = None;
|
||||
|
||||
let menu_element = element_state.menu.borrow_mut().as_mut().map(|menu| {
|
||||
let mut overlay = overlay().snap_to_window();
|
||||
let mut anchored = anchored().snap_to_window();
|
||||
if let Some(anchor) = this.anchor {
|
||||
overlay = overlay.anchor(anchor);
|
||||
anchored = anchored.anchor(anchor);
|
||||
}
|
||||
overlay = overlay.position(*element_state.position.borrow());
|
||||
anchored = anchored.position(*element_state.position.borrow());
|
||||
|
||||
let mut element =
|
||||
deferred(anchored.child(div().occlude().child(menu.clone()))).into_any();
|
||||
|
||||
let mut element = overlay
|
||||
.child(div().occlude().child(menu.clone()))
|
||||
.into_any();
|
||||
menu_layout_id = Some(element.before_layout(cx));
|
||||
element
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use gpui::{overlay, Action, AnyView, IntoElement, Render, VisualContext};
|
||||
use gpui::{anchored, Action, AnyView, IntoElement, Render, VisualContext};
|
||||
use settings::Settings;
|
||||
use theme::ThemeSettings;
|
||||
|
||||
|
@ -90,8 +90,8 @@ pub fn tooltip_container<V>(
|
|||
f: impl FnOnce(Div, &mut ViewContext<V>) -> Div,
|
||||
) -> impl IntoElement {
|
||||
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||
overlay().child(
|
||||
// padding to avoid mouse cursor
|
||||
// padding to avoid mouse cursor
|
||||
anchored().child(
|
||||
div().pl_2().pt_2p5().child(
|
||||
v_flex()
|
||||
.elevation_2(cx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue