From 3195cc703f29adddd76822114d359c2d69655f3d Mon Sep 17 00:00:00 2001 From: Grim Maple Date: Fri, 18 Nov 2022 20:38:51 +0300 Subject: [PATCH] Add double click action --- src/dlangui/widgets/widget.d | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 83283538..da40a4b8 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -82,6 +82,12 @@ interface OnClickHandler { bool onClick(Widget source); } +/// Interface slot for OnDoubleClick +interface OnDoubleClickHandler +{ + bool onDoubleClick(Widget source); +} + /// interface - slot for onCheckChanged interface OnCheckHandler { bool onCheckChanged(Widget source, bool checked); @@ -1172,6 +1178,14 @@ public: return res; } + // called to process double click and notify listeners + protected bool handleDoubleClick() + { + if (doubleClick.assigned) + return doubleClick(this); + return false; + } + void cancelLayout() { _needLayout = false; @@ -1278,11 +1292,16 @@ public: setState(State.Pressed); if (canFocus) setFocus(); + nextClickIsDouble = event.doubleClick; return true; } if (event.action == MouseAction.ButtonUp && event.button == MouseButton.Left && state & State.Pressed) { resetState(State.Pressed); - handleClick(); + if(nextClickIsDouble) + handleDoubleClick(); + else + handleClick(); + nextClickIsDouble = false; return true; } if (event.action == MouseAction.FocusOut || event.action == MouseAction.Cancel) { @@ -1339,6 +1358,9 @@ public: /// on click event listener (bool delegate(Widget)) Signal!OnClickHandler click; + /// On double click event listener (bool delegate(Widget)) + Signal!OnDoubleClickHandler doubleClick; + /// checked state change event listener (bool delegate(Widget, bool)) Signal!OnCheckHandler checkChange; @@ -1764,6 +1786,9 @@ public: mixin(generatePropertySetters("margins", "padding")); return false; } + +private: + bool nextClickIsDouble = false; } /** Widget list holder. */