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:
Bennet Bo Fenner 2024-03-29 16:26:16 +01:00 committed by GitHub
parent 49144d94bf
commit 77f1cc95b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 144 additions and 136 deletions

View File

@ -14,12 +14,12 @@ use db::kvp::KEY_VALUE_STORE;
use editor::{Editor, EditorElement, EditorStyle}; use editor::{Editor, EditorElement, EditorStyle};
use fuzzy::{match_strings, StringMatchCandidate}; use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{ use gpui::{
actions, canvas, div, fill, list, overlay, point, prelude::*, px, AnyElement, AppContext, actions, anchored, canvas, deferred, div, fill, list, point, prelude::*, px, AnyElement,
AsyncWindowContext, Bounds, ClickEvent, ClipboardItem, DismissEvent, Div, EventEmitter, AppContext, AsyncWindowContext, Bounds, ClickEvent, ClipboardItem, DismissEvent, Div,
FocusHandle, FocusableView, FontStyle, FontWeight, InteractiveElement, IntoElement, ListOffset, EventEmitter, FocusHandle, FocusableView, FontStyle, FontWeight, InteractiveElement,
ListState, Model, MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, Render, IntoElement, ListOffset, ListState, Model, MouseDownEvent, ParentElement, Pixels, Point,
SharedString, Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext, PromptLevel, Render, SharedString, Styled, Subscription, Task, TextStyle, View, ViewContext,
WeakView, WhiteSpace, VisualContext, WeakView, WhiteSpace,
}; };
use menu::{Cancel, Confirm, SecondaryConfirm, SelectNext, SelectPrev}; use menu::{Cancel, Confirm, SecondaryConfirm, SelectNext, SelectPrev};
use project::{Fs, Project}; use project::{Fs, Project};
@ -2767,10 +2767,12 @@ impl Render for CollabPanel {
self.render_signed_in(cx) self.render_signed_in(cx)
}) })
.children(self.context_menu.as_ref().map(|(menu, position, _)| { .children(self.context_menu.as_ref().map(|(menu, position, _)| {
overlay() deferred(
.position(*position) anchored()
.anchor(gpui::AnchorCorner::TopLeft) .position(*position)
.child(menu.clone()) .anchor(gpui::AnchorCorner::TopLeft)
.child(menu.clone()),
)
})) }))
} }
} }

View File

@ -5,9 +5,9 @@ use client::{
}; };
use fuzzy::{match_strings, StringMatchCandidate}; use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{ use gpui::{
actions, div, overlay, AppContext, ClipboardItem, DismissEvent, EventEmitter, FocusableView, actions, anchored, deferred, div, AppContext, ClipboardItem, DismissEvent, EventEmitter,
Model, ParentElement, Render, Styled, Subscription, Task, View, ViewContext, VisualContext, FocusableView, Model, ParentElement, Render, Styled, Subscription, Task, View, ViewContext,
WeakView, VisualContext, WeakView,
}; };
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use std::sync::Arc; use std::sync::Arc;
@ -408,11 +408,11 @@ impl PickerDelegate for ChannelModalDelegate {
.when(is_me, |el| el.child(Label::new("You").color(Color::Muted))) .when(is_me, |el| el.child(Label::new("You").color(Color::Muted)))
.children( .children(
if let (Some((menu, _)), true) = (&self.context_menu, selected) { if let (Some((menu, _)), true) = (&self.context_menu, selected) {
Some( Some(deferred(
overlay() anchored()
.anchor(gpui::AnchorCorner::TopRight) .anchor(gpui::AnchorCorner::TopRight)
.child(menu.clone()), .child(menu.clone()),
) ))
} else { } else {
None None
}, },

View File

@ -20,13 +20,14 @@ use anyhow::Result;
use collections::{BTreeMap, HashMap}; use collections::{BTreeMap, HashMap};
use git::{blame::BlameEntry, diff::DiffHunkStatus, Oid}; use git::{blame::BlameEntry, diff::DiffHunkStatus, Oid};
use gpui::{ use gpui::{
div, fill, outline, overlay, point, px, quad, relative, size, svg, transparent_black, Action, anchored, deferred, div, fill, outline, point, px, quad, relative, size, svg,
AnchorCorner, AnyElement, AnyView, AvailableSpace, Bounds, ClipboardItem, ContentMask, Corners, transparent_black, Action, AnchorCorner, AnyElement, AnyView, AvailableSpace, Bounds,
CursorStyle, DispatchPhase, Edges, Element, ElementContext, ElementInputHandler, Entity, ClipboardItem, ContentMask, Corners, CursorStyle, DispatchPhase, Edges, Element,
Hitbox, Hsla, InteractiveElement, IntoElement, ModifiersChangedEvent, MouseButton, ElementContext, ElementInputHandler, Entity, Hitbox, Hsla, InteractiveElement, IntoElement,
MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, ScrollDelta, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
ScrollWheelEvent, ShapedLine, SharedString, Size, Stateful, StatefulInteractiveElement, Style, ParentElement, Pixels, ScrollDelta, ScrollWheelEvent, ShapedLine, SharedString, Size, Stateful,
Styled, TextRun, TextStyle, TextStyleRefinement, View, ViewContext, WindowContext, StatefulInteractiveElement, Style, Styled, TextRun, TextStyle, TextStyleRefinement, View,
ViewContext, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
use language::language_settings::ShowWhitespaceSetting; use language::language_settings::ShowWhitespaceSetting;
@ -1804,12 +1805,15 @@ impl EditorElement {
fn layout_mouse_context_menu(&self, cx: &mut ElementContext) -> Option<AnyElement> { fn layout_mouse_context_menu(&self, cx: &mut ElementContext) -> Option<AnyElement> {
let mouse_context_menu = self.editor.read(cx).mouse_context_menu.as_ref()?; let mouse_context_menu = self.editor.read(cx).mouse_context_menu.as_ref()?;
let mut element = overlay() let mut element = deferred(
.position(mouse_context_menu.position) anchored()
.child(mouse_context_menu.context_menu.clone()) .position(mouse_context_menu.position)
.anchor(AnchorCorner::TopLeft) .child(mouse_context_menu.context_menu.clone())
.snap_to_window() .anchor(AnchorCorner::TopLeft)
.into_any(); .snap_to_window(),
)
.into_any();
element.layout(gpui::Point::default(), AvailableSpace::min_size(), cx); element.layout(gpui::Point::default(), AvailableSpace::min_size(), cx);
Some(element) Some(element)
} }

View File

@ -6,71 +6,70 @@ use crate::{
Pixels, Point, Size, Style, Pixels, Point, Size, Style,
}; };
/// The state that the overlay element uses to track its children. /// The state that the anchored element element uses to track its children.
pub struct OverlayState { pub struct AnchoredState {
child_layout_ids: SmallVec<[LayoutId; 4]>, child_layout_ids: SmallVec<[LayoutId; 4]>,
offset: Point<Pixels>,
} }
/// An overlay element that can be used to display UI that /// An anchored element that can be used to display UI that
/// floats on top of other UI elements. /// will avoid overflowing the window bounds.
pub struct Overlay { pub struct Anchored {
children: SmallVec<[AnyElement; 2]>, children: SmallVec<[AnyElement; 2]>,
anchor_corner: AnchorCorner, anchor_corner: AnchorCorner,
fit_mode: OverlayFitMode, fit_mode: AnchoredFitMode,
anchor_position: Option<Point<Pixels>>, anchor_position: Option<Point<Pixels>>,
position_mode: OverlayPositionMode, position_mode: AnchoredPositionMode,
} }
/// overlay gives you a floating element that will avoid overflowing the window bounds. /// anchored gives you an element that will avoid overflowing the window bounds.
/// Its children should have no margin to avoid measurement issues. /// Its children should have no margin to avoid measurement issues.
pub fn overlay() -> Overlay { pub fn anchored() -> Anchored {
Overlay { Anchored {
children: SmallVec::new(), children: SmallVec::new(),
anchor_corner: AnchorCorner::TopLeft, anchor_corner: AnchorCorner::TopLeft,
fit_mode: OverlayFitMode::SwitchAnchor, fit_mode: AnchoredFitMode::SwitchAnchor,
anchor_position: None, anchor_position: None,
position_mode: OverlayPositionMode::Window, position_mode: AnchoredPositionMode::Window,
} }
} }
impl Overlay { impl Anchored {
/// Sets which corner of the overlay should be anchored to the current position. /// Sets which corner of the anchored element should be anchored to the current position.
pub fn anchor(mut self, anchor: AnchorCorner) -> Self { pub fn anchor(mut self, anchor: AnchorCorner) -> Self {
self.anchor_corner = anchor; self.anchor_corner = anchor;
self self
} }
/// Sets the position in window coordinates /// Sets the position in window coordinates
/// (otherwise the location the overlay is rendered is used) /// (otherwise the location the anchored element is rendered is used)
pub fn position(mut self, anchor: Point<Pixels>) -> Self { pub fn position(mut self, anchor: Point<Pixels>) -> Self {
self.anchor_position = Some(anchor); self.anchor_position = Some(anchor);
self self
} }
/// Sets the position mode for this overlay. Local will have this /// Sets the position mode for this anchored element. Local will have this
/// interpret its [`Overlay::position`] as relative to the parent element. /// interpret its [`Anchored::position`] as relative to the parent element.
/// While Window will have it interpret the position as relative to the window. /// While Window will have it interpret the position as relative to the window.
pub fn position_mode(mut self, mode: OverlayPositionMode) -> Self { pub fn position_mode(mut self, mode: AnchoredPositionMode) -> Self {
self.position_mode = mode; self.position_mode = mode;
self self
} }
/// Snap to window edge instead of switching anchor corner when an overflow would occur. /// Snap to window edge instead of switching anchor corner when an overflow would occur.
pub fn snap_to_window(mut self) -> Self { pub fn snap_to_window(mut self) -> Self {
self.fit_mode = OverlayFitMode::SnapToWindow; self.fit_mode = AnchoredFitMode::SnapToWindow;
self self
} }
} }
impl ParentElement for Overlay { impl ParentElement for Anchored {
fn extend(&mut self, elements: impl Iterator<Item = AnyElement>) { fn extend(&mut self, elements: impl Iterator<Item = AnyElement>) {
self.children.extend(elements) self.children.extend(elements)
} }
} }
impl Element for Overlay { impl Element for Anchored {
type BeforeLayout = OverlayState; type BeforeLayout = AnchoredState;
type AfterLayout = (); type AfterLayout = ();
fn before_layout(&mut self, cx: &mut ElementContext) -> (crate::LayoutId, Self::BeforeLayout) { fn before_layout(&mut self, cx: &mut ElementContext) -> (crate::LayoutId, Self::BeforeLayout) {
@ -80,21 +79,15 @@ impl Element for Overlay {
.map(|child| child.before_layout(cx)) .map(|child| child.before_layout(cx))
.collect::<SmallVec<_>>(); .collect::<SmallVec<_>>();
let overlay_style = Style { let anchored_style = Style {
position: Position::Absolute, position: Position::Absolute,
display: Display::Flex, display: Display::Flex,
..Style::default() ..Style::default()
}; };
let layout_id = cx.request_layout(&overlay_style, child_layout_ids.iter().copied()); let layout_id = cx.request_layout(&anchored_style, child_layout_ids.iter().copied());
( (layout_id, AnchoredState { child_layout_ids })
layout_id,
OverlayState {
child_layout_ids,
offset: Point::default(),
},
)
} }
fn after_layout( fn after_layout(
@ -128,7 +121,7 @@ impl Element for Overlay {
size: cx.viewport_size(), size: cx.viewport_size(),
}; };
if self.fit_mode == OverlayFitMode::SwitchAnchor { if self.fit_mode == AnchoredFitMode::SwitchAnchor {
let mut anchor_corner = self.anchor_corner; let mut anchor_corner = self.anchor_corner;
if desired.left() < limits.left() || desired.right() > limits.right() { if desired.left() < limits.left() || desired.right() > limits.right() {
@ -151,7 +144,7 @@ impl Element for Overlay {
} }
} }
// Snap the horizontal edges of the overlay to the horizontal edges of the window if // Snap the horizontal edges of the anchored element to the horizontal edges of the window if
// its horizontal bounds overflow, aligning to the left if it is wider than the limits. // its horizontal bounds overflow, aligning to the left if it is wider than the limits.
if desired.right() > limits.right() { if desired.right() > limits.right() {
desired.origin.x -= desired.right() - limits.right(); desired.origin.x -= desired.right() - limits.right();
@ -160,7 +153,7 @@ impl Element for Overlay {
desired.origin.x = limits.origin.x; desired.origin.x = limits.origin.x;
} }
// Snap the vertical edges of the overlay to the vertical edges of the window if // Snap the vertical edges of the anchored element to the vertical edges of the window if
// its vertical bounds overflow, aligning to the top if it is taller than the limits. // its vertical bounds overflow, aligning to the top if it is taller than the limits.
if desired.bottom() > limits.bottom() { if desired.bottom() > limits.bottom() {
desired.origin.y -= desired.bottom() - limits.bottom(); desired.origin.y -= desired.bottom() - limits.bottom();
@ -169,15 +162,14 @@ impl Element for Overlay {
desired.origin.y = limits.origin.y; desired.origin.y = limits.origin.y;
} }
before_layout.offset = cx.element_offset() + desired.origin - bounds.origin; let offset = desired.origin - bounds.origin;
before_layout.offset = point( let offset = point(offset.x.round(), offset.y.round());
before_layout.offset.x.round(),
before_layout.offset.y.round(),
);
for child in self.children.drain(..) { cx.with_element_offset(offset, |cx| {
cx.defer_draw(child, before_layout.offset, 1); for child in &mut self.children {
} child.after_layout(cx);
}
})
} }
fn paint( fn paint(
@ -185,12 +177,15 @@ impl Element for Overlay {
_bounds: crate::Bounds<crate::Pixels>, _bounds: crate::Bounds<crate::Pixels>,
_before_layout: &mut Self::BeforeLayout, _before_layout: &mut Self::BeforeLayout,
_after_layout: &mut Self::AfterLayout, _after_layout: &mut Self::AfterLayout,
_cx: &mut ElementContext, cx: &mut ElementContext,
) { ) {
for child in &mut self.children {
child.paint(cx);
}
} }
} }
impl IntoElement for Overlay { impl IntoElement for Anchored {
type Element = Self; type Element = Self;
fn into_element(self) -> Self::Element { fn into_element(self) -> Self::Element {
@ -203,25 +198,25 @@ enum Axis {
Vertical, Vertical,
} }
/// Which algorithm to use when fitting the overlay to be inside the window. /// Which algorithm to use when fitting the anchored element to be inside the window.
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub enum OverlayFitMode { pub enum AnchoredFitMode {
/// Snap the overlay to the window edge /// Snap the anchored element to the window edge
SnapToWindow, SnapToWindow,
/// Switch which corner anchor this overlay is attached to /// Switch which corner anchor this anchored element is attached to
SwitchAnchor, SwitchAnchor,
} }
/// Which algorithm to use when positioning the overlay. /// Which algorithm to use when positioning the anchored element.
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub enum OverlayPositionMode { pub enum AnchoredPositionMode {
/// Position the overlay relative to the window /// Position the anchored element relative to the window
Window, Window,
/// Position the overlay relative to its parent /// Position the anchored element relative to its parent
Local, Local,
} }
impl OverlayPositionMode { impl AnchoredPositionMode {
fn get_position_and_bounds( fn get_position_and_bounds(
&self, &self,
anchor_position: Option<Point<Pixels>>, anchor_position: Option<Point<Pixels>>,
@ -230,12 +225,12 @@ impl OverlayPositionMode {
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
) -> (Point<Pixels>, Bounds<Pixels>) { ) -> (Point<Pixels>, Bounds<Pixels>) {
match self { match self {
OverlayPositionMode::Window => { AnchoredPositionMode::Window => {
let anchor_position = anchor_position.unwrap_or(bounds.origin); let anchor_position = anchor_position.unwrap_or(bounds.origin);
let bounds = anchor_corner.get_bounds(anchor_position, size); let bounds = anchor_corner.get_bounds(anchor_position, size);
(anchor_position, bounds) (anchor_position, bounds)
} }
OverlayPositionMode::Local => { AnchoredPositionMode::Local => {
let anchor_position = anchor_position.unwrap_or_default(); let anchor_position = anchor_position.unwrap_or_default();
let bounds = anchor_corner.get_bounds(bounds.origin + anchor_position, size); let bounds = anchor_corner.get_bounds(bounds.origin + anchor_position, size);
(anchor_position, bounds) (anchor_position, bounds)
@ -244,7 +239,7 @@ impl OverlayPositionMode {
} }
} }
/// Which corner of the overlay should be considered the anchor. /// Which corner of the anchored element should be considered the anchor.
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum AnchorCorner { pub enum AnchorCorner {
/// The top left corner /// The top left corner

View File

@ -1,21 +1,21 @@
mod anchored;
mod animation; mod animation;
mod canvas; mod canvas;
mod deferred; mod deferred;
mod div; mod div;
mod img; mod img;
mod list; mod list;
mod overlay;
mod svg; mod svg;
mod text; mod text;
mod uniform_list; mod uniform_list;
pub use anchored::*;
pub use animation::*; pub use animation::*;
pub use canvas::*; pub use canvas::*;
pub use deferred::*; pub use deferred::*;
pub use div::*; pub use div::*;
pub use img::*; pub use img::*;
pub use list::*; pub use list::*;
pub use overlay::*;
pub use svg::*; pub use svg::*;
pub use text::*; pub use text::*;
pub use uniform_list::*; pub use uniform_list::*;

View File

@ -356,6 +356,11 @@ impl<'a> ElementContext<'a> {
let mut root_element = self.window.root_view.as_ref().unwrap().clone().into_any(); let mut root_element = self.window.root_view.as_ref().unwrap().clone().into_any();
root_element.layout(Point::default(), self.window.viewport_size.into(), self); root_element.layout(Point::default(), self.window.viewport_size.into(), self);
let mut sorted_deferred_draws =
(0..self.window.next_frame.deferred_draws.len()).collect::<SmallVec<[_; 8]>>();
sorted_deferred_draws.sort_by_key(|ix| self.window.next_frame.deferred_draws[*ix].priority);
self.layout_deferred_draws(&sorted_deferred_draws);
let mut prompt_element = None; let mut prompt_element = None;
let mut active_drag_element = None; let mut active_drag_element = None;
let mut tooltip_element = None; let mut tooltip_element = None;
@ -380,17 +385,14 @@ impl<'a> ElementContext<'a> {
tooltip_element = Some(element); tooltip_element = Some(element);
} }
let mut sorted_deferred_draws =
(0..self.window.next_frame.deferred_draws.len()).collect::<SmallVec<[_; 8]>>();
sorted_deferred_draws.sort_by_key(|ix| self.window.next_frame.deferred_draws[*ix].priority);
self.layout_deferred_draws(&sorted_deferred_draws);
self.window.mouse_hit_test = self.window.next_frame.hit_test(self.window.mouse_position); self.window.mouse_hit_test = self.window.next_frame.hit_test(self.window.mouse_position);
// Now actually paint the elements. // Now actually paint the elements.
self.window.draw_phase = DrawPhase::Paint; self.window.draw_phase = DrawPhase::Paint;
root_element.paint(self); root_element.paint(self);
self.paint_deferred_draws(&sorted_deferred_draws);
if let Some(mut prompt_element) = prompt_element { if let Some(mut prompt_element) = prompt_element {
prompt_element.paint(self) prompt_element.paint(self)
} else if let Some(mut drag_element) = active_drag_element { } else if let Some(mut drag_element) = active_drag_element {
@ -398,8 +400,6 @@ impl<'a> ElementContext<'a> {
} else if let Some(mut tooltip_element) = tooltip_element { } else if let Some(mut tooltip_element) = tooltip_element {
tooltip_element.paint(self); tooltip_element.paint(self);
} }
self.paint_deferred_draws(&sorted_deferred_draws);
} }
fn layout_deferred_draws(&mut self, deferred_draw_indices: &[usize]) { fn layout_deferred_draws(&mut self, deferred_draw_indices: &[usize]) {

View File

@ -10,11 +10,11 @@ use file_associations::FileAssociations;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use collections::{hash_map, HashMap}; use collections::{hash_map, HashMap};
use gpui::{ use gpui::{
actions, div, impl_actions, overlay, px, uniform_list, Action, AppContext, AssetSource, actions, anchored, deferred, div, impl_actions, px, uniform_list, Action, AppContext,
AsyncWindowContext, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView, AssetSource, AsyncWindowContext, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle,
InteractiveElement, KeyContext, Model, MouseButton, MouseDownEvent, ParentElement, Pixels, FocusableView, InteractiveElement, KeyContext, Model, MouseButton, MouseDownEvent,
Point, PromptLevel, Render, Stateful, Styled, Subscription, Task, UniformListScrollHandle, ParentElement, Pixels, Point, PromptLevel, Render, Stateful, Styled, Subscription, Task,
View, ViewContext, VisualContext as _, WeakView, WindowContext, UniformListScrollHandle, View, ViewContext, VisualContext as _, WeakView, WindowContext,
}; };
use menu::{Confirm, SelectNext, SelectPrev}; use menu::{Confirm, SelectNext, SelectPrev};
use project::{ use project::{
@ -1585,10 +1585,12 @@ impl Render for ProjectPanel {
.track_scroll(self.scroll_handle.clone()), .track_scroll(self.scroll_handle.clone()),
) )
.children(self.context_menu.as_ref().map(|(menu, position, _)| { .children(self.context_menu.as_ref().map(|(menu, position, _)| {
overlay() deferred(
.position(*position) anchored()
.anchor(gpui::AnchorCorner::TopLeft) .position(*position)
.child(menu.clone()) .anchor(gpui::AnchorCorner::TopLeft)
.child(menu.clone()),
)
})) }))
} else { } else {
v_flex() v_flex()

View File

@ -6,9 +6,9 @@ use collections::HashSet;
use editor::{scroll::Autoscroll, Editor}; use editor::{scroll::Autoscroll, Editor};
use futures::{stream::FuturesUnordered, StreamExt}; use futures::{stream::FuturesUnordered, StreamExt};
use gpui::{ use gpui::{
div, impl_actions, overlay, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle, anchored, deferred, div, impl_actions, AnyElement, AppContext, DismissEvent, EventEmitter,
FocusableView, KeyContext, KeyDownEvent, Keystroke, Model, MouseButton, MouseDownEvent, Pixels, FocusHandle, FocusableView, KeyContext, KeyDownEvent, Keystroke, Model, MouseButton,
Render, Styled, Subscription, Task, View, VisualContext, WeakView, MouseDownEvent, Pixels, Render, Styled, Subscription, Task, View, VisualContext, WeakView,
}; };
use language::Bias; use language::Bias;
use persistence::TERMINAL_DB; use persistence::TERMINAL_DB;
@ -765,10 +765,12 @@ impl Render for TerminalView {
)), )),
) )
.children(self.context_menu.as_ref().map(|(menu, position, _)| { .children(self.context_menu.as_ref().map(|(menu, position, _)| {
overlay() deferred(
.position(*position) anchored()
.anchor(gpui::AnchorCorner::TopLeft) .position(*position)
.child(menu.clone()) .anchor(gpui::AnchorCorner::TopLeft)
.child(menu.clone()),
)
})) }))
} }
} }

View File

@ -1,7 +1,7 @@
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use gpui::{ 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, DismissEvent, DispatchPhase, Element, ElementContext, ElementId, HitboxId, InteractiveElement,
IntoElement, LayoutId, ManagedView, MouseDownEvent, ParentElement, Pixels, Point, View, IntoElement, LayoutId, ManagedView, MouseDownEvent, ParentElement, Pixels, Point, View,
VisualContext, WindowContext, VisualContext, WindowContext,
@ -176,17 +176,15 @@ impl<M: ManagedView> Element for PopoverMenu<M> {
let mut menu_layout_id = None; let mut menu_layout_id = None;
let menu_element = element_state.menu.borrow_mut().as_mut().map(|menu| { 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 { 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), 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)); menu_layout_id = Some(element.before_layout(cx));
element element
}); });

View File

@ -1,9 +1,10 @@
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use gpui::{ use gpui::{
div, overlay, AnchorCorner, AnyElement, Bounds, DismissEvent, DispatchPhase, Element, anchored, deferred, div, AnchorCorner, AnyElement, Bounds, DismissEvent, DispatchPhase,
ElementContext, ElementId, Hitbox, InteractiveElement, IntoElement, LayoutId, ManagedView, Element, ElementContext, ElementId, Hitbox, InteractiveElement, IntoElement, LayoutId,
MouseButton, MouseDownEvent, ParentElement, Pixels, Point, View, VisualContext, WindowContext, ManagedView, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, View, VisualContext,
WindowContext,
}; };
pub struct RightClickMenu<M: ManagedView> { pub struct RightClickMenu<M: ManagedView> {
@ -103,15 +104,15 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
let mut menu_layout_id = None; let mut menu_layout_id = None;
let menu_element = element_state.menu.borrow_mut().as_mut().map(|menu| { 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 { 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)); menu_layout_id = Some(element.before_layout(cx));
element element
}); });

View File

@ -1,4 +1,4 @@
use gpui::{overlay, Action, AnyView, IntoElement, Render, VisualContext}; use gpui::{anchored, Action, AnyView, IntoElement, Render, VisualContext};
use settings::Settings; use settings::Settings;
use theme::ThemeSettings; use theme::ThemeSettings;
@ -90,8 +90,8 @@ pub fn tooltip_container<V>(
f: impl FnOnce(Div, &mut ViewContext<V>) -> Div, f: impl FnOnce(Div, &mut ViewContext<V>) -> Div,
) -> impl IntoElement { ) -> impl IntoElement {
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone(); 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( div().pl_2().pt_2p5().child(
v_flex() v_flex()
.elevation_2(cx) .elevation_2(cx)

View File

@ -8,11 +8,11 @@ use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque}; use collections::{HashMap, HashSet, VecDeque};
use futures::{stream::FuturesUnordered, StreamExt}; use futures::{stream::FuturesUnordered, StreamExt};
use gpui::{ use gpui::{
actions, impl_actions, overlay, prelude::*, Action, AnchorCorner, AnyElement, AppContext, actions, anchored, deferred, impl_actions, prelude::*, Action, AnchorCorner, AnyElement,
AsyncWindowContext, ClickEvent, DismissEvent, Div, DragMoveEvent, EntityId, EventEmitter, AppContext, AsyncWindowContext, ClickEvent, DismissEvent, Div, DragMoveEvent, EntityId,
ExternalPaths, FocusHandle, FocusableView, Model, MouseButton, NavigationDirection, Pixels, EventEmitter, ExternalPaths, FocusHandle, FocusableView, Model, MouseButton,
Point, PromptLevel, Render, ScrollHandle, Subscription, Task, View, ViewContext, VisualContext, NavigationDirection, Pixels, Point, PromptLevel, Render, ScrollHandle, Subscription, Task,
WeakFocusHandle, WeakView, WindowContext, View, ViewContext, VisualContext, WeakFocusHandle, WeakView, WindowContext,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use project::{Project, ProjectEntryId, ProjectPath}; use project::{Project, ProjectEntryId, ProjectPath};
@ -1567,7 +1567,11 @@ impl Pane {
.bottom_0() .bottom_0()
.right_0() .right_0()
.size_0() .size_0()
.child(overlay().anchor(AnchorCorner::TopRight).child(menu.clone())) .child(deferred(
anchored()
.anchor(AnchorCorner::TopRight)
.child(menu.clone()),
))
} }
pub fn set_zoomed(&mut self, zoomed: bool, cx: &mut ViewContext<Self>) { pub fn set_zoomed(&mut self, zoomed: bool, cx: &mut ViewContext<Self>) {