diff options
-rw-r--r-- | include/cru/ui/controls/CheckBox.h | 18 | ||||
-rw-r--r-- | src/ui/controls/CheckBox.cpp | 7 |
2 files changed, 22 insertions, 3 deletions
diff --git a/include/cru/ui/controls/CheckBox.h b/include/cru/ui/controls/CheckBox.h index a892389b..1c81b284 100644 --- a/include/cru/ui/controls/CheckBox.h +++ b/include/cru/ui/controls/CheckBox.h @@ -1,13 +1,16 @@ #pragma once +#include "../helper/ClickDetector.h" +#include "../render/BorderRenderObject.h" #include "IBorderControl.h" #include "ICheckableControl.h" +#include "IClickableControl.h" #include "NoChildControl.h" -#include "cru/ui/render/BorderRenderObject.h" namespace cru::ui::controls { class CRU_UI_API CheckBox : public NoChildControl, public virtual IBorderControl, - public virtual ICheckableControl { + public virtual ICheckableControl, + public virtual IClickableControl { public: CheckBox(); ~CheckBox() override; @@ -18,15 +21,26 @@ class CRU_UI_API CheckBox : public NoChildControl, bool IsChecked() const override { return checked_; } void SetChecked(bool checked) override; + void Toggle() { SetChecked(!checked_); } IEvent<bool>* CheckedChangeEvent() override { return &checked_change_event_; } void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override; + helper::ClickState GetClickState() const { + return click_detector_.GetState(); + } + + IEvent<helper::ClickState>* ClickStateChangeEvent() override { + return click_detector_.StateChangeEvent(); + } + private: bool checked_ = false; Event<bool> checked_change_event_; std::unique_ptr<render::BorderRenderObject> container_render_object_; + + helper::ClickDetector click_detector_; }; } // namespace cru::ui::controls diff --git a/src/ui/controls/CheckBox.cpp b/src/ui/controls/CheckBox.cpp index ab8af2e8..d41d1cb6 100644 --- a/src/ui/controls/CheckBox.cpp +++ b/src/ui/controls/CheckBox.cpp @@ -1,10 +1,15 @@ #include "cru/ui/controls/CheckBox.h" +#include "cru/ui/helper/ClickDetector.h" #include "cru/ui/render/BorderRenderObject.h" namespace cru::ui::controls { CheckBox::CheckBox() - : container_render_object_(new render::BorderRenderObject()) { + : container_render_object_(new render::BorderRenderObject()), + click_detector_(this) { container_render_object_->SetAttachedControl(this); + + click_detector_.ClickEvent()->AddHandler( + [this](const helper::ClickEventArgs&) { Toggle(); }); } CheckBox::~CheckBox() {} |