diff options
author | crupest <crupest@outlook.com> | 2020-11-10 20:29:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-11-10 20:29:28 +0800 |
commit | 4fcf336d15fe246259ee18ccc99808d80e69c455 (patch) | |
tree | abd1867004b804cce3e6b72ae8c40a43f630d048 /src/ui/helper/Styler.cpp | |
parent | bde7bdeec01574587565f782c48a18338ed66705 (diff) | |
download | cru-4fcf336d15fe246259ee18ccc99808d80e69c455.tar.gz cru-4fcf336d15fe246259ee18ccc99808d80e69c455.tar.bz2 cru-4fcf336d15fe246259ee18ccc99808d80e69c455.zip |
...
Diffstat (limited to 'src/ui/helper/Styler.cpp')
-rw-r--r-- | src/ui/helper/Styler.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/ui/helper/Styler.cpp b/src/ui/helper/Styler.cpp new file mode 100644 index 00000000..6500a3f7 --- /dev/null +++ b/src/ui/helper/Styler.cpp @@ -0,0 +1,27 @@ +#include "cru/ui/helper/Styler.hpp" +#include "cru/ui/helper/ClickDetector.hpp" +#include "gsl/pointers" + +namespace cru::ui::helper { +Styler::Styler(gsl::not_null<controls::Control*> control, + ClickDetector* click_detector) + : control_(control), + managed_click_detector_(click_detector ? nullptr + : new ClickDetector(control)), + click_detector_(click_detector ? click_detector + : managed_click_detector_.get()) { + event_guard_ += control_->GainFocusEvent()->Direct()->AddHandler( + [this](auto) { this->RaiseStateChangeEvent(); }); + event_guard_ += control_->LoseFocusEvent()->Direct()->AddHandler( + [this](auto) { this->RaiseStateChangeEvent(); }); + event_guard_ += click_detector_->StateChangeEvent()->AddHandler( + [this](auto) { this->RaiseStateChangeEvent(); }); +} + +Styler::~Styler() = default; + +void Styler::RaiseStateChangeEvent() { + this->state_change_event_.Raise(ControlStyleState{ + this->click_detector_->GetState(), this->control_->HasFocus()}); +} +} // namespace cru::ui::helper |