From de686acd6983c0edb76370ae7b8b8e1ed4ef6e14 Mon Sep 17 00:00:00 2001 From: Clement Roblot Date: Tue, 24 Oct 2023 14:47:39 +0700 Subject: [PATCH] Added anti drag feature to checkboxes --- src/ftxui/component/checkbox.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ftxui/component/checkbox.cpp b/src/ftxui/component/checkbox.cpp index ebfa46d8..3d95edb3 100644 --- a/src/ftxui/component/checkbox.cpp +++ b/src/ftxui/component/checkbox.cpp @@ -70,17 +70,25 @@ class CheckboxBase : public ComponentBase, public CheckboxOption { } if (event.mouse().button == Mouse::Left && - event.mouse().motion == Mouse::Pressed) { + event.mouse().motion == Mouse::Pressed && + isMousePressed == false) { *checked = !*checked; + isMousePressed = true; on_change(); return true; } + if (event.mouse().button == Mouse::Left && + event.mouse().motion == Mouse::Released) { + isMousePressed = false; + } + return false; } bool Focusable() const final { return true; } + bool isMousePressed = false; bool hovered_ = false; Box box_; };