diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 39091ecad1..771bc1049c 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1619,7 +1619,7 @@ mod tests { // Don't panic. let bounds = RectF::new(Default::default(), size); - let mut paint_cx = presenter.build_paint_context(&mut scene, cx); + let mut paint_cx = presenter.build_paint_context(&mut scene, bounds.size(), cx); element.paint(bounds, bounds, &mut state, &mut paint_cx); } } diff --git a/crates/gpui/src/elements/tooltip.rs b/crates/gpui/src/elements/tooltip.rs index b56f269667..4c255e139e 100644 --- a/crates/gpui/src/elements/tooltip.rs +++ b/crates/gpui/src/elements/tooltip.rs @@ -101,9 +101,16 @@ impl Element for Tooltip { self.child.paint(bounds.origin(), visible_bounds, cx); if let Some(tooltip) = self.tooltip.as_mut() { let origin = self.state.read(cx).position.get(); - let size = tooltip.size(); + let mut bounds = RectF::new(origin, tooltip.size()); + if bounds.lower_right().x() > cx.window_size.x() { + bounds.set_origin_x(bounds.origin_x() - bounds.width()); + } + if bounds.lower_right().y() > cx.window_size.y() { + bounds.set_origin_y(bounds.origin_y() - bounds.height()); + } + cx.scene.push_stacking_context(None); - tooltip.paint(origin, RectF::new(origin, size), cx); + tooltip.paint(bounds.origin(), bounds, cx); cx.scene.pop_stacking_context(); } } diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 6e29242b84..720e9e90b5 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -148,7 +148,7 @@ impl Presenter { if let Some(root_view_id) = cx.root_view_id(self.window_id) { self.layout(window_size, refreshing, cx); - let mut paint_cx = self.build_paint_context(&mut scene, cx); + let mut paint_cx = self.build_paint_context(&mut scene, window_size, cx); paint_cx.paint( root_view_id, Vector2F::zero(), @@ -205,10 +205,12 @@ impl Presenter { pub fn build_paint_context<'a>( &'a mut self, scene: &'a mut Scene, + window_size: Vector2F, cx: &'a mut MutableAppContext, ) -> PaintContext { PaintContext { scene, + window_size, font_cache: &self.font_cache, text_layout_cache: &self.text_layout_cache, rendered_views: &mut self.rendered_views, @@ -592,6 +594,7 @@ impl<'a> UpgradeViewHandle for LayoutContext<'a> { pub struct PaintContext<'a> { rendered_views: &'a mut HashMap, view_stack: Vec, + pub window_size: Vector2F, pub scene: &'a mut Scene, pub font_cache: &'a FontCache, pub text_layout_cache: &'a TextLayoutCache,