diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/ui/helper/BorderStyle.cpp | 0 | ||||
-rw-r--r-- | src/ui/helper/Styler.cpp | 27 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index d9edf49e..974a3959 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -21,8 +21,10 @@ add_library(cru_ui STATIC controls/TextControlService.hpp controls/Window.cpp events/UiEvent.cpp + helper/BorderStyle.cpp helper/ClickDetector.cpp helper/ShortcutHub.cpp + helper/Styler.cpp host/LayoutPaintCycler.cpp host/WindowHost.cpp render/BorderRenderObject.cpp @@ -53,8 +55,10 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/controls/TextBlock.hpp ${CRU_UI_INCLUDE_DIR}/controls/Window.hpp ${CRU_UI_INCLUDE_DIR}/events/UiEvent.hpp + ${CRU_UI_INCLUDE_DIR}/helper/BorderStyle.hpp ${CRU_UI_INCLUDE_DIR}/helper/ClickDetector.hpp ${CRU_UI_INCLUDE_DIR}/helper/ShortcutHub.hpp + ${CRU_UI_INCLUDE_DIR}/helper/Styler.hpp ${CRU_UI_INCLUDE_DIR}/host/LayoutPaintCycler.hpp ${CRU_UI_INCLUDE_DIR}/host/WindowHost.hpp ${CRU_UI_INCLUDE_DIR}/render/Base.hpp diff --git a/src/ui/helper/BorderStyle.cpp b/src/ui/helper/BorderStyle.cpp new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/ui/helper/BorderStyle.cpp 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 |