Calculate hitbox based on visible bounds in {Mouse}EventHandler

This is in contrast to not dispatching the event altogether in `Flex` when
the event is not contained in the flex element bounds. That approach was
problematic because it didn't give an opportunity to `MouseEventHandler`s
to handle mouse move events when they didn't intersect with the element bounds,
causing elements to never clear their hover state, cursor style, etc.
This commit is contained in:
Antonio Scandurra 2022-04-07 15:11:10 +02:00
parent 73f2fd6b09
commit b396909035
3 changed files with 7 additions and 14 deletions

View file

@ -99,8 +99,8 @@ impl Element for MouseEventHandler {
fn dispatch_event(
&mut self,
event: &Event,
bounds: RectF,
_: RectF,
visible_bounds: RectF,
_: &mut Self::LayoutState,
_: &mut Self::PaintState,
cx: &mut EventContext,
@ -113,8 +113,8 @@ impl Element for MouseEventHandler {
let handled_in_child = self.child.dispatch_event(event, cx);
let hit_bounds = RectF::from_points(
bounds.origin() - vec2f(self.padding.left, self.padding.top),
bounds.lower_right() + vec2f(self.padding.right, self.padding.bottom),
visible_bounds.origin() - vec2f(self.padding.left, self.padding.top),
visible_bounds.lower_right() + vec2f(self.padding.right, self.padding.bottom),
)
.round_out();