From 4fcf336d15fe246259ee18ccc99808d80e69c455 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 10 Nov 2020 20:29:28 +0800 Subject: ... --- include/cru/ui/helper/BorderStyle.hpp | 23 +++++++++++++++++ include/cru/ui/helper/Styler.hpp | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 include/cru/ui/helper/BorderStyle.hpp create mode 100644 include/cru/ui/helper/Styler.hpp (limited to 'include') diff --git a/include/cru/ui/helper/BorderStyle.hpp b/include/cru/ui/helper/BorderStyle.hpp new file mode 100644 index 00000000..0ec0d9ee --- /dev/null +++ b/include/cru/ui/helper/BorderStyle.hpp @@ -0,0 +1,23 @@ +#pragma once +#include "cru/ui/Base.hpp" + +#include + +namespace cru::ui::helper { +struct BorderStyleOfClickState { + BorderStyleOfClickState(std::optional focus = std::nullopt, + std::optional not_focus = std::nullopt) + : focus(std::move(focus)), not_focus(std::move(not_focus)) {} + + std::optional focus; + std::optional not_focus; +}; + +struct BorderStyleList { + BorderStyle default_one; + std::optional normal; + std::optional hover; + std::optional press; + std::optional press_inactive; +}; +} // namespace cru::ui::helper diff --git a/include/cru/ui/helper/Styler.hpp b/include/cru/ui/helper/Styler.hpp new file mode 100644 index 00000000..ed8bfbdc --- /dev/null +++ b/include/cru/ui/helper/Styler.hpp @@ -0,0 +1,47 @@ +#pragma once +#include "cru/common/Base.hpp" +#include "cru/common/Event.hpp" +#include "cru/ui/Base.hpp" +#include "cru/ui/helper/ClickDetector.hpp" +#include "gsl/pointers" + +#include + +namespace cru::ui::helper { +struct ControlStyleState { + ClickState click_state; + bool focus; +}; + +class Styler : public Object { + public: + // You could provide your click detector. Otherwise a new one will be created. + explicit Styler(gsl::not_null control, + ClickDetector* click_detector = nullptr); + + CRU_DELETE_COPY(Styler) + CRU_DELETE_MOVE(Styler) + + ~Styler(); + + public: + gsl::not_null GetControl() const { return control_; } + gsl::not_null GetClickDetector() const { + return click_detector_; + } + + IEvent* StateChangeEvent() { return &state_change_event_; } + + private: + void RaiseStateChangeEvent(); + + private: + gsl::not_null control_; + std::unique_ptr managed_click_detector_; + gsl::not_null click_detector_; + + Event state_change_event_; + + EventRevokerListGuard event_guard_; +}; +} // namespace cru::ui::helper -- cgit v1.2.3