Combine platform mouse events to use common MouseEvent struct and remove MouseDragged event in favor of MouseMoved

This commit is contained in:
Keith Simmons 2022-07-06 16:37:56 -07:00
parent 686e57373b
commit bcb553f233
8 changed files with 172 additions and 163 deletions

View file

@ -1,7 +1,7 @@
use crate::{
geometry::vector::Vector2F, CursorRegion, DebugContext, Element, ElementBox, Event,
EventContext, LayoutContext, LeftMouseDownEvent, MouseRegion, NavigateMouseDownEvent,
NavigationDirection, PaintContext, RightMouseDownEvent, SizeConstraint,
EventContext, LayoutContext, MouseButton, MouseEvent, MouseRegion, NavigationDirection,
PaintContext, SizeConstraint,
};
use pathfinder_geometry::rect::RectF;
use serde_json::json;
@ -117,7 +117,11 @@ impl Element for EventHandler {
true
} else {
match event {
Event::LeftMouseDown(LeftMouseDownEvent { position, .. }) => {
Event::MouseDown(MouseEvent {
button: MouseButton::Left,
position,
..
}) => {
if let Some(callback) = self.mouse_down.as_mut() {
if visible_bounds.contains_point(*position) {
return callback(cx);
@ -125,7 +129,11 @@ impl Element for EventHandler {
}
false
}
Event::RightMouseDown(RightMouseDownEvent { position, .. }) => {
Event::MouseDown(MouseEvent {
button: MouseButton::Right,
position,
..
}) => {
if let Some(callback) = self.right_mouse_down.as_mut() {
if visible_bounds.contains_point(*position) {
return callback(cx);
@ -133,9 +141,9 @@ impl Element for EventHandler {
}
false
}
Event::NavigateMouseDown(NavigateMouseDownEvent {
Event::MouseDown(MouseEvent {
button: MouseButton::Navigate(direction),
position,
direction,
..
}) => {
if let Some(callback) = self.navigate_mouse_down.as_mut() {