From 05d727f2f306bd6379fa48fcf07c575f77d3e96f Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 7 Aug 2024 11:27:50 -0400 Subject: [PATCH] add hover gesture support to iOS app --- src/ios/main.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ios/main.mm b/src/ios/main.mm index c794c802..50a03c09 100644 --- a/src/ios/main.mm +++ b/src/ios/main.mm @@ -196,6 +196,17 @@ } } io.AddMouseButtonEvent(0, hasActiveTouch); + + UIHoverGestureRecognizer *hoverGestureRecognizer = [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverGesture:)]; + [self.view addGestureRecognizer:hoverGestureRecognizer]; +- (void)hoverGesture:(UIHoverGestureRecognizer *)gesture { + ImGuiIO &io = ImGui::GetIO(); + io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen); + // Cast to UIGestureRecognizer to UIGestureRecognizer to get locationInView + UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)gesture; + if (gesture.zOffset < 0.50) { + io.AddMousePosEvent([gestureRecognizer locationInView:self.view].x, [gestureRecognizer locationInView:self.view].y); + } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {