From 7a8aba329bca459a73ec9cb42949198d06d59834 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 27 Nov 2023 11:43:14 -0700 Subject: [PATCH] Break content mask for hoverables --- crates/editor2/src/element.rs | 8 ++++++-- crates/gpui2/src/elements/overlay.rs | 8 +++++--- crates/gpui2/src/window.rs | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 1a888e21f7f79265a5551d1b1fe9e6fe062ff8db..5b510095ff116745d020e5ecb8604d06e9af0a02 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -1055,7 +1055,9 @@ impl EditorElement { list_origin.y -= layout.position_map.line_height + list_height; } - context_menu.draw(list_origin, available_space, cx); + cx.break_content_mask(|cx| { + context_menu.draw(list_origin, available_space, cx) + }); } if let Some((position, mut hover_popovers)) = layout.hover_popovers.take() { @@ -1095,7 +1097,9 @@ impl EditorElement { popover_origin.x = popover_origin.x + x_out_of_bounds; } - hover_popover.draw(popover_origin, available_space, cx); + cx.break_content_mask(|cx| { + hover_popover.draw(popover_origin, available_space, cx) + }); current_y = popover_origin.y - HOVER_POPOVER_GAP; } diff --git a/crates/gpui2/src/elements/overlay.rs b/crates/gpui2/src/elements/overlay.rs index d8aad4a42f9413f60e05d59bfab5d0606d4dd5d2..764bdfabcd6695d3ee0b4dd71cc51e472567c09e 100644 --- a/crates/gpui2/src/elements/overlay.rs +++ b/crates/gpui2/src/elements/overlay.rs @@ -144,9 +144,11 @@ impl Element for Overlay { } cx.with_element_offset(desired.origin - bounds.origin, |cx| { - for child in self.children { - child.paint(cx); - } + cx.break_content_mask(|cx| { + for child in self.children { + child.paint(cx); + } + }) }) } } diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index de86e427571624fa2014827a51064eaa955fc73f..5d33f0161c687325d77db16d6dc5ec316236ff2c 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -1752,6 +1752,24 @@ pub trait BorrowWindow: BorrowMut + BorrowMut { } } + /// Invoke the given function with the content mask reset to that + /// of the window. + fn break_content_mask(&mut self, f: impl FnOnce(&mut Self) -> R) -> R { + let mask = ContentMask { + bounds: Bounds { + origin: Point::default(), + size: self.window().viewport_size, + }, + }; + self.window_mut() + .current_frame + .content_mask_stack + .push(mask); + let result = f(self); + self.window_mut().current_frame.content_mask_stack.pop(); + result + } + /// Update the global element offset relative to the current offset. This is used to implement /// scrolling. fn with_element_offset(