From db01c12ee391310966b167670040889ab23b3379 Mon Sep 17 00:00:00 2001 From: inc0der Date: Fri, 22 Mar 2024 21:49:18 -0300 Subject: [PATCH 1/2] add mouse button option for drag scrolling --- haxe/ui/constants/MouseButton.hx | 7 ++++ haxe/ui/containers/ScrollView.hx | 56 +++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 haxe/ui/constants/MouseButton.hx diff --git a/haxe/ui/constants/MouseButton.hx b/haxe/ui/constants/MouseButton.hx new file mode 100644 index 000000000..011b6e5b0 --- /dev/null +++ b/haxe/ui/constants/MouseButton.hx @@ -0,0 +1,7 @@ +package haxe.ui.constants; + +enum abstract MouseButton(String) from String to String { + var LEFT = 'left'; + var MIDDLE = 'middle'; + var RIGHT = 'right'; +} diff --git a/haxe/ui/containers/ScrollView.hx b/haxe/ui/containers/ScrollView.hx index 1510fa915..dae3bf89a 100644 --- a/haxe/ui/containers/ScrollView.hx +++ b/haxe/ui/containers/ScrollView.hx @@ -1,5 +1,6 @@ package haxe.ui.containers; +import haxe.ui.constants.MouseButton; import haxe.ui.actions.ActionType; import haxe.ui.behaviours.Behaviour; import haxe.ui.behaviours.DataBehaviour; @@ -49,6 +50,7 @@ class ScrollView extends InteractiveComponent implements IScroller { @:clonable @:behaviour(VScrollPageSize) public var vscrollPageSize:Float; @:clonable @:behaviour(VScrollThumbSize) public var vscrollThumbSize:Null; @:clonable @:behaviour(ThumbSize) public var thumbSize:Null; + @:clonable @:behaviour(ScrollMouseButton) public var scrollMouseButton:MouseButton; @:clonable @:behaviour(ScrollModeBehaviour, ScrollMode.DRAG) public var scrollMode:ScrollMode; @:clonable @:behaviour(ScrollPolicyBehaviour) public var scrollPolicy:ScrollPolicy; @:clonable @:behaviour(HScrollPolicyBehaviour) public var horizontalScrollPolicy:ScrollPolicy; @@ -544,6 +546,21 @@ private class ThumbSize extends DataBehaviour { } } +@:dox(hide) @:noCompletion +@:access(haxe.ui.core.Component) +private class ScrollMouseButton extends DataBehaviour { + private var _scrollview:ScrollView; + + public function new(scrollview:ScrollView) { + super(scrollview); + _scrollview = scrollview; + } + + public override function validateData() { + _scrollview.scrollMouseButton = _value; + } +} + @:dox(hide) @:noCompletion @:access(haxe.ui.core.Component) private class ScrollModeBehaviour extends DataBehaviour { @@ -689,9 +706,13 @@ class ScrollViewEvents extends haxe.ui.events.Events { } if (_scrollview.scrollMode == ScrollMode.DRAG || _scrollview.scrollMode == ScrollMode.INERTIAL) { - registerEvent(MouseEvent.MOUSE_DOWN, onMouseDown); - } else if (hasEvent(MouseEvent.MOUSE_DOWN, onMouseDown)) { - unregisterEvent(MouseEvent.MOUSE_DOWN, onMouseDown); + registerEvent(MouseEvent.MIDDLE_MOUSE_DOWN, onMiddleMouseDown); + registerEvent(MouseEvent.MOUSE_DOWN, onLeftMouseDown); + registerEvent(MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown); + } else if (hasEvent(MouseEvent.MOUSE_DOWN, onLeftMouseDown)) { + unregisterEvent(MouseEvent.MIDDLE_MOUSE_DOWN, onMiddleMouseDown); + unregisterEvent(MouseEvent.MOUSE_DOWN, onLeftMouseDown); + unregisterEvent(MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown); } if (_scrollview.hasEvent(UIEvent.SHOWN) == false) { @@ -736,7 +757,9 @@ class ScrollViewEvents extends haxe.ui.events.Events { vscroll.unregisterEvent(ScrollEvent.SCROLL, onVScrollScroll); } - unregisterEvent(MouseEvent.MOUSE_DOWN, onMouseDown); + unregisterEvent(MouseEvent.MIDDLE_MOUSE_DOWN, onMiddleMouseDown); + unregisterEvent(MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown); + unregisterEvent(MouseEvent.MOUSE_DOWN, onLeftMouseDown); unregisterEvent(MouseEvent.MOUSE_WHEEL, onMouseWheel); unregisterEvent(UIEvent.SHOWN, onShown); unregisterEvent(UIEvent.COMPONENT_ADDED, onComponentAdded); @@ -807,6 +830,27 @@ class ScrollViewEvents extends haxe.ui.events.Events { private function onVScrollScroll(event:UIEvent) { _target.dispatch(new ScrollEvent(ScrollEvent.SCROLL)); } + + @:access(haxe.ui.core.Component) + private function onLeftMouseDown(event:MouseEvent) { + if (_scrollview.scrollMouseButton == MouseButton.LEFT) { + onMouseDown(event); + } + } + + @:access(haxe.ui.core.Component) + private function onMiddleMouseDown(event:MouseEvent) { + if (_scrollview.scrollMouseButton == MouseButton.MIDDLE) { + onMouseDown(event); + } + } + + @:access(haxe.ui.core.Component) + private function onRightMouseDown(event:MouseEvent) { + if (_scrollview.scrollMouseButton == MouseButton.RIGHT) { + onMouseDown(event); + } + } private var _offset:Point; private static inline var INERTIAL_TIME_CONSTANT:Int = 325; @@ -867,6 +911,8 @@ class ScrollViewEvents extends haxe.ui.events.Events { } Screen.instance.registerEvent(MouseEvent.MOUSE_MOVE, onMouseMove); + Screen.instance.registerEvent(MouseEvent.MIDDLE_MOUSE_UP, onMouseUp); + Screen.instance.registerEvent(MouseEvent.RIGHT_MOUSE_UP, onMouseUp); Screen.instance.registerEvent(MouseEvent.MOUSE_UP, onMouseUp); } @@ -967,6 +1013,8 @@ class ScrollViewEvents extends haxe.ui.events.Events { private function onMouseUp(event:MouseEvent) { Screen.instance.unregisterEvent(MouseEvent.MOUSE_MOVE, onMouseMove); + Screen.instance.unregisterEvent(MouseEvent.MIDDLE_MOUSE_UP, onMouseUp); + Screen.instance.unregisterEvent(MouseEvent.RIGHT_MOUSE_UP, onMouseUp); Screen.instance.unregisterEvent(MouseEvent.MOUSE_UP, onMouseUp); if (_scrollview.scrollMode == ScrollMode.INERTIAL) { From 090f90b54f8433a41e8eddd25c9e148f93f96c3c Mon Sep 17 00:00:00 2001 From: inc0der Date: Sat, 6 Apr 2024 11:27:51 -0300 Subject: [PATCH 2/2] update to make scrollMouseButton a DefaultBehaviour --- haxe/ui/containers/ScrollView.hx | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/haxe/ui/containers/ScrollView.hx b/haxe/ui/containers/ScrollView.hx index dae3bf89a..fa30fcb27 100644 --- a/haxe/ui/containers/ScrollView.hx +++ b/haxe/ui/containers/ScrollView.hx @@ -50,7 +50,7 @@ class ScrollView extends InteractiveComponent implements IScroller { @:clonable @:behaviour(VScrollPageSize) public var vscrollPageSize:Float; @:clonable @:behaviour(VScrollThumbSize) public var vscrollThumbSize:Null; @:clonable @:behaviour(ThumbSize) public var thumbSize:Null; - @:clonable @:behaviour(ScrollMouseButton) public var scrollMouseButton:MouseButton; + @:clonable @:behaviour(DefaultBehaviour, MouseButton.LEFT) public var scrollMouseButton:MouseButton; @:clonable @:behaviour(ScrollModeBehaviour, ScrollMode.DRAG) public var scrollMode:ScrollMode; @:clonable @:behaviour(ScrollPolicyBehaviour) public var scrollPolicy:ScrollPolicy; @:clonable @:behaviour(HScrollPolicyBehaviour) public var horizontalScrollPolicy:ScrollPolicy; @@ -546,21 +546,6 @@ private class ThumbSize extends DataBehaviour { } } -@:dox(hide) @:noCompletion -@:access(haxe.ui.core.Component) -private class ScrollMouseButton extends DataBehaviour { - private var _scrollview:ScrollView; - - public function new(scrollview:ScrollView) { - super(scrollview); - _scrollview = scrollview; - } - - public override function validateData() { - _scrollview.scrollMouseButton = _value; - } -} - @:dox(hide) @:noCompletion @:access(haxe.ui.core.Component) private class ScrollModeBehaviour extends DataBehaviour {