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 /include/cru | |
parent | bde7bdeec01574587565f782c48a18338ed66705 (diff) | |
download | cru-4fcf336d15fe246259ee18ccc99808d80e69c455.tar.gz cru-4fcf336d15fe246259ee18ccc99808d80e69c455.tar.bz2 cru-4fcf336d15fe246259ee18ccc99808d80e69c455.zip |
...
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/ui/helper/BorderStyle.hpp | 23 | ||||
-rw-r--r-- | include/cru/ui/helper/Styler.hpp | 47 |
2 files changed, 70 insertions, 0 deletions
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 <optional> + +namespace cru::ui::helper { +struct BorderStyleOfClickState { + BorderStyleOfClickState(std::optional<BorderStyle> focus = std::nullopt, + std::optional<BorderStyle> not_focus = std::nullopt) + : focus(std::move(focus)), not_focus(std::move(not_focus)) {} + + std::optional<BorderStyle> focus; + std::optional<BorderStyle> not_focus; +}; + +struct BorderStyleList { + BorderStyle default_one; + std::optional<BorderStyleOfClickState> normal; + std::optional<BorderStyleOfClickState> hover; + std::optional<BorderStyleOfClickState> press; + std::optional<BorderStyleOfClickState> 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 <memory> + +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<controls::Control*> control, + ClickDetector* click_detector = nullptr); + + CRU_DELETE_COPY(Styler) + CRU_DELETE_MOVE(Styler) + + ~Styler(); + + public: + gsl::not_null<controls::Control*> GetControl() const { return control_; } + gsl::not_null<ClickDetector*> GetClickDetector() const { + return click_detector_; + } + + IEvent<ControlStyleState>* StateChangeEvent() { return &state_change_event_; } + + private: + void RaiseStateChangeEvent(); + + private: + gsl::not_null<controls::Control*> control_; + std::unique_ptr<ClickDetector> managed_click_detector_; + gsl::not_null<ClickDetector*> click_detector_; + + Event<ControlStyleState> state_change_event_; + + EventRevokerListGuard event_guard_; +}; +} // namespace cru::ui::helper |