From 73f2fd6b09fac05a7c20f0e30b8b03a92041648d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 7 Apr 2022 15:10:09 +0200 Subject: [PATCH] Pass visible bounds to `Element::dispatch_event` --- crates/editor/src/element.rs | 1 + crates/gpui/examples/text.rs | 1 + crates/gpui/src/elements.rs | 10 +++++++++- crates/gpui/src/elements/align.rs | 3 ++- crates/gpui/src/elements/canvas.rs | 1 + crates/gpui/src/elements/constrained_box.rs | 1 + crates/gpui/src/elements/container.rs | 1 + crates/gpui/src/elements/empty.rs | 1 + crates/gpui/src/elements/event_handler.rs | 2 ++ crates/gpui/src/elements/expanded.rs | 1 + crates/gpui/src/elements/flex.rs | 2 ++ crates/gpui/src/elements/hook.rs | 1 + crates/gpui/src/elements/image.rs | 1 + crates/gpui/src/elements/label.rs | 1 + crates/gpui/src/elements/list.rs | 2 ++ crates/gpui/src/elements/mouse_event_handler.rs | 1 + crates/gpui/src/elements/overlay.rs | 1 + crates/gpui/src/elements/stack.rs | 1 + crates/gpui/src/elements/svg.rs | 1 + crates/gpui/src/elements/text.rs | 1 + crates/gpui/src/elements/uniform_list.rs | 1 + crates/gpui/src/presenter.rs | 1 + crates/workspace/src/workspace.rs | 5 +++-- 23 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 0ffe3feb6d43c..640ba80ac226c 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1147,6 +1147,7 @@ impl Element for EditorElement { &mut self, event: &Event, _: RectF, + _: RectF, layout: &mut LayoutState, paint: &mut PaintState, cx: &mut EventContext, diff --git a/crates/gpui/examples/text.rs b/crates/gpui/examples/text.rs index cc849a5e62fc9..74e2c2c2eaa94 100644 --- a/crates/gpui/examples/text.rs +++ b/crates/gpui/examples/text.rs @@ -104,6 +104,7 @@ impl gpui::Element for TextElement { &mut self, _: &gpui::Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut gpui::EventContext, diff --git a/crates/gpui/src/elements.rs b/crates/gpui/src/elements.rs index 79112863b5148..55c7bf22fe460 100644 --- a/crates/gpui/src/elements.rs +++ b/crates/gpui/src/elements.rs @@ -74,6 +74,7 @@ pub trait Element { &mut self, event: &Event, bounds: RectF, + visible_bounds: RectF, layout: &mut Self::LayoutState, paint: &mut Self::PaintState, cx: &mut EventContext, @@ -169,6 +170,7 @@ pub enum Lifecycle { element: T, constraint: SizeConstraint, bounds: RectF, + visible_bounds: RectF, layout: T::LayoutState, paint: T::PaintState, }, @@ -222,6 +224,7 @@ impl AnyElement for Lifecycle { element, constraint, bounds, + visible_bounds, layout, paint, } @@ -242,6 +245,7 @@ impl AnyElement for Lifecycle { element, constraint, bounds, + visible_bounds, layout, paint, } @@ -254,12 +258,13 @@ impl AnyElement for Lifecycle { if let Lifecycle::PostPaint { element, bounds, + visible_bounds, layout, paint, .. } = self { - element.dispatch_event(event, *bounds, layout, paint, cx) + element.dispatch_event(event, *bounds, *visible_bounds, layout, paint, cx) } else { panic!("invalid element lifecycle state"); } @@ -288,6 +293,7 @@ impl AnyElement for Lifecycle { element, constraint, bounds, + visible_bounds, layout, paint, } => { @@ -299,6 +305,8 @@ impl AnyElement for Lifecycle { new_map.insert("type".into(), typ); } new_map.insert("constraint".into(), constraint.to_json()); + new_map.insert("bounds".into(), bounds.to_json()); + new_map.insert("visible_bounds".into(), visible_bounds.to_json()); new_map.append(map); json::Value::Object(new_map) } else { diff --git a/crates/gpui/src/elements/align.rs b/crates/gpui/src/elements/align.rs index ce99437f3ba51..5388f7647e503 100644 --- a/crates/gpui/src/elements/align.rs +++ b/crates/gpui/src/elements/align.rs @@ -85,7 +85,8 @@ impl Element for Align { fn dispatch_event( &mut self, event: &Event, - _: pathfinder_geometry::rect::RectF, + _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/canvas.rs b/crates/gpui/src/elements/canvas.rs index d6220fd45f481..2e10c59049f6c 100644 --- a/crates/gpui/src/elements/canvas.rs +++ b/crates/gpui/src/elements/canvas.rs @@ -59,6 +59,7 @@ where &mut self, _: &crate::Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut crate::EventContext, diff --git a/crates/gpui/src/elements/constrained_box.rs b/crates/gpui/src/elements/constrained_box.rs index c712d71a9b7ba..f12ed6900abc0 100644 --- a/crates/gpui/src/elements/constrained_box.rs +++ b/crates/gpui/src/elements/constrained_box.rs @@ -81,6 +81,7 @@ impl Element for ConstrainedBox { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/container.rs b/crates/gpui/src/elements/container.rs index 73a4349ba0256..711ab1f6a6265 100644 --- a/crates/gpui/src/elements/container.rs +++ b/crates/gpui/src/elements/container.rs @@ -247,6 +247,7 @@ impl Element for Container { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/empty.rs b/crates/gpui/src/elements/empty.rs index d6041bd9587f0..90b2123163966 100644 --- a/crates/gpui/src/elements/empty.rs +++ b/crates/gpui/src/elements/empty.rs @@ -52,6 +52,7 @@ impl Element for Empty { &mut self, _: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut EventContext, diff --git a/crates/gpui/src/elements/event_handler.rs b/crates/gpui/src/elements/event_handler.rs index 469bebee1a43f..572edf38864bf 100644 --- a/crates/gpui/src/elements/event_handler.rs +++ b/crates/gpui/src/elements/event_handler.rs @@ -85,6 +85,8 @@ impl Element for EventHandler { &mut self, event: &Event, bounds: RectF, + _: RectF, + visible_bounds: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/expanded.rs b/crates/gpui/src/elements/expanded.rs index cbeef598da649..6f69d8a92a8bf 100644 --- a/crates/gpui/src/elements/expanded.rs +++ b/crates/gpui/src/elements/expanded.rs @@ -66,6 +66,7 @@ impl Element for Expanded { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/flex.rs b/crates/gpui/src/elements/flex.rs index 1ae9c591c89c1..8c451ea8f707a 100644 --- a/crates/gpui/src/elements/flex.rs +++ b/crates/gpui/src/elements/flex.rs @@ -266,6 +266,7 @@ impl Element for Flex { &mut self, event: &Event, bounds: RectF, + _: RectF, remaining_space: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, @@ -391,6 +392,7 @@ impl Element for FlexItem { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/hook.rs b/crates/gpui/src/elements/hook.rs index 994d5fe281ca1..e947c3bac7da2 100644 --- a/crates/gpui/src/elements/hook.rs +++ b/crates/gpui/src/elements/hook.rs @@ -57,6 +57,7 @@ impl Element for Hook { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/image.rs b/crates/gpui/src/elements/image.rs index 5d36828d0cd57..6b55b567b4b43 100644 --- a/crates/gpui/src/elements/image.rs +++ b/crates/gpui/src/elements/image.rs @@ -81,6 +81,7 @@ impl Element for Image { &mut self, _: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut EventContext, diff --git a/crates/gpui/src/elements/label.rs b/crates/gpui/src/elements/label.rs index 7aa46f1199910..e6ae9cbd51330 100644 --- a/crates/gpui/src/elements/label.rs +++ b/crates/gpui/src/elements/label.rs @@ -166,6 +166,7 @@ impl Element for Label { &mut self, _: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut EventContext, diff --git a/crates/gpui/src/elements/list.rs b/crates/gpui/src/elements/list.rs index 624ec4ba7177e..77d37bc3bf3b2 100644 --- a/crates/gpui/src/elements/list.rs +++ b/crates/gpui/src/elements/list.rs @@ -253,6 +253,7 @@ impl Element for List { &mut self, event: &Event, bounds: RectF, + _: RectF, scroll_top: &mut ListOffset, _: &mut (), cx: &mut EventContext, @@ -872,6 +873,7 @@ mod tests { &mut self, _: &Event, _: RectF, + _: RectF, _: &mut (), _: &mut (), _: &mut EventContext, diff --git a/crates/gpui/src/elements/mouse_event_handler.rs b/crates/gpui/src/elements/mouse_event_handler.rs index a9cfd3334e87e..d7fb9f01131b8 100644 --- a/crates/gpui/src/elements/mouse_event_handler.rs +++ b/crates/gpui/src/elements/mouse_event_handler.rs @@ -100,6 +100,7 @@ impl Element for MouseEventHandler { &mut self, event: &Event, bounds: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/overlay.rs b/crates/gpui/src/elements/overlay.rs index 79ab71c07d7cd..0cac2ed86302c 100644 --- a/crates/gpui/src/elements/overlay.rs +++ b/crates/gpui/src/elements/overlay.rs @@ -44,6 +44,7 @@ impl Element for Overlay { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/stack.rs b/crates/gpui/src/elements/stack.rs index dd36b9c4b5aeb..4531734085487 100644 --- a/crates/gpui/src/elements/stack.rs +++ b/crates/gpui/src/elements/stack.rs @@ -51,6 +51,7 @@ impl Element for Stack { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/elements/svg.rs b/crates/gpui/src/elements/svg.rs index 3e93d3adae3cd..d473e1f0fb01f 100644 --- a/crates/gpui/src/elements/svg.rs +++ b/crates/gpui/src/elements/svg.rs @@ -76,6 +76,7 @@ impl Element for Svg { &mut self, _: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut EventContext, diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs index 5caa60c0d7b56..a0c3f6ba9fdf0 100644 --- a/crates/gpui/src/elements/text.rs +++ b/crates/gpui/src/elements/text.rs @@ -172,6 +172,7 @@ impl Element for Text { &mut self, _: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut EventContext, diff --git a/crates/gpui/src/elements/uniform_list.rs b/crates/gpui/src/elements/uniform_list.rs index 7bd3e28a2e384..526a9aea404ff 100644 --- a/crates/gpui/src/elements/uniform_list.rs +++ b/crates/gpui/src/elements/uniform_list.rs @@ -281,6 +281,7 @@ where &mut self, event: &Event, bounds: RectF, + _: RectF, layout: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index b4e419107a32d..8546bed00f2c2 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -535,6 +535,7 @@ impl Element for ChildView { &mut self, event: &Event, _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, cx: &mut EventContext, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 7ee7d5cf44ae7..b49b6f601f3a9 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -16,7 +16,7 @@ use gpui::{ action, color::Color, elements::*, - geometry::{vector::vec2f, PathBuilder}, + geometry::{rect::RectF, vector::vec2f, PathBuilder}, json::{self, to_string_pretty, ToJson}, keymap::Binding, platform::{CursorStyle, WindowOptions}, @@ -2068,7 +2068,8 @@ impl Element for AvatarRibbon { fn dispatch_event( &mut self, _: &gpui::Event, - _: gpui::geometry::rect::RectF, + _: RectF, + _: RectF, _: &mut Self::LayoutState, _: &mut Self::PaintState, _: &mut gpui::EventContext,