From da6f0bcfc6ec786cf14f67f100b4c50cf2325db4 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 16 Feb 2022 17:30:49 +0800 Subject: ... --- .../properties/CheckBoxPropertyEditor.cpp | 26 ++++++++++++++++ .../components/properties/CheckBoxPropertyEditor.h | 35 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp create mode 100644 src/theme_builder/components/properties/CheckBoxPropertyEditor.h (limited to 'src/theme_builder/components/properties') diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp new file mode 100644 index 00000000..2e921f96 --- /dev/null +++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp @@ -0,0 +1,26 @@ +#include "CheckBoxPropertyEditor.h" + +namespace cru::theme_builder::components::properties { +CheckBoxPropertyEditor::CheckBoxPropertyEditor() { + container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); + container_.AddChild(&label_); + container_.AddChild(&check_box_); + + check_box_.CheckedChangeEvent()->AddSpyOnlyHandler([this] { + if (!suppress_next_change_event_) { + change_event_.Raise(nullptr); + } else { + suppress_next_change_event_ = false; + } + }); +} + +CheckBoxPropertyEditor::~CheckBoxPropertyEditor() { + container_.RemoveFromParent(); +} + +void CheckBoxPropertyEditor::SetValue(bool value, bool trigger_change) { + if (!trigger_change) suppress_next_change_event_ = true; + check_box_.SetChecked(value); +} +} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.h b/src/theme_builder/components/properties/CheckBoxPropertyEditor.h new file mode 100644 index 00000000..07ac4fe0 --- /dev/null +++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.h @@ -0,0 +1,35 @@ +#pragma once +#include "cru/ui/components/Component.h" +#include "cru/ui/controls/CheckBox.h" +#include "cru/ui/controls/Control.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" + +namespace cru::theme_builder::components::properties { +class CheckBoxPropertyEditor : public ui::components::Component { + public: + using PropertyType = bool; + + CheckBoxPropertyEditor(); + ~CheckBoxPropertyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + bool GetValue() const { return check_box_.IsChecked(); } + void SetValue(bool value, bool trigger_change = true); + + IEvent* ChangeEvent() { return &change_event_; } + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::CheckBox check_box_; + + bool suppress_next_change_event_ = false; + Event change_event_; +}; +} // namespace cru::theme_builder::components::properties -- cgit v1.2.3