diff options
Diffstat (limited to 'src/theme_builder/components/properties')
13 files changed, 56 insertions, 119 deletions
diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp index 3b96b716..fb6f4705 100644 --- a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp +++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp @@ -6,19 +6,14 @@ CheckBoxPropertyEditor::CheckBoxPropertyEditor() { 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; - } - }); + check_box_.CheckedChangeEvent()->AddSpyOnlyHandler( + [this] { RaiseChangeEvent(); }); } CheckBoxPropertyEditor::~CheckBoxPropertyEditor() {} void CheckBoxPropertyEditor::SetValue(bool value, bool trigger_change) { - if (!trigger_change) suppress_next_change_event_ = true; + if (!trigger_change) SuppressNextChangeEvent(); 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 index 07ac4fe0..f78ed6c9 100644 --- a/src/theme_builder/components/properties/CheckBoxPropertyEditor.h +++ b/src/theme_builder/components/properties/CheckBoxPropertyEditor.h @@ -1,12 +1,11 @@ #pragma once -#include "cru/ui/components/Component.h" +#include "../Editor.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 { +class CheckBoxPropertyEditor : public Editor { public: using PropertyType = bool; @@ -22,14 +21,9 @@ class CheckBoxPropertyEditor : public ui::components::Component { bool GetValue() const { return check_box_.IsChecked(); } void SetValue(bool value, bool trigger_change = true); - IEvent<std::nullptr_t>* 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<std::nullptr_t> change_event_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.cpp b/src/theme_builder/components/properties/ColorPropertyEditor.cpp index d6577abb..49911f77 100644 --- a/src/theme_builder/components/properties/ColorPropertyEditor.cpp +++ b/src/theme_builder/components/properties/ColorPropertyEditor.cpp @@ -21,7 +21,7 @@ ColorPropertyEditor::ColorPropertyEditor() { color_ = *color; color_cube_brush_->SetColor(*color); is_color_text_valid_ = true; - change_event_.Raise(nullptr); + RaiseChangeEvent(); } else { is_color_text_valid_ = false; // TODO: Show error! @@ -33,9 +33,7 @@ ColorPropertyEditor::~ColorPropertyEditor() {} void ColorPropertyEditor::SetValue(const ui::Color &color, bool trigger_change) { - color_cube_brush_->SetColor(color); + if (!trigger_change) SuppressNextChangeEvent(); color_text_.SetText(color.ToString()); - is_color_text_valid_ = true; - if (trigger_change) change_event_.Raise(nullptr); } } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.h b/src/theme_builder/components/properties/ColorPropertyEditor.h index 3265e8e9..aa6cfcfa 100644 --- a/src/theme_builder/components/properties/ColorPropertyEditor.h +++ b/src/theme_builder/components/properties/ColorPropertyEditor.h @@ -1,13 +1,13 @@ #pragma once +#include "../Editor.h" #include "cru/platform/graphics/Base.h" -#include "cru/ui/components/Component.h" #include "cru/ui/controls/Container.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class ColorPropertyEditor : public ui::components::Component { +class ColorPropertyEditor : public Editor { public: using PropertyType = ui::Color; @@ -23,8 +23,6 @@ class ColorPropertyEditor : public ui::components::Component { ui::Color GetValue() const { return color_; } void SetValue(const ui::Color& color, bool trigger_change = true); - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } - private: ui::Color color_ = ui::colors::transparent; @@ -34,7 +32,5 @@ class ColorPropertyEditor : public ui::components::Component { std::shared_ptr<platform::graphics::ISolidColorBrush> color_cube_brush_; ui::controls::TextBox color_text_; bool is_color_text_valid_; - - Event<std::nullptr_t> change_event_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp index d124b8fe..91e2c614 100644 --- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp +++ b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp @@ -1,4 +1,5 @@ #include "CornerRadiusPropertyEditor.h" +#include "cru/ui/Base.h" namespace cru::theme_builder::components::properties { CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() { @@ -13,35 +14,26 @@ CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() { container_.AddChild(left_bottom_editor_.GetRootControl()); container_.AddChild(right_bottom_editor_.GetRootControl()); - left_top_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) { - corner_radius_.left_top = left_top_editor_.GetValue(); - change_event_.Raise(nullptr); - }); - - right_top_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) { - corner_radius_.right_top = left_top_editor_.GetValue(); - change_event_.Raise(nullptr); - }); - - left_bottom_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) { - corner_radius_.left_bottom = left_bottom_editor_.GetValue(); - change_event_.Raise(nullptr); - }); - - right_bottom_editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) { - corner_radius_.right_bottom = right_bottom_editor_.GetValue(); - change_event_.Raise(nullptr); - }); + ConnectChangeEvent(left_top_editor_); + ConnectChangeEvent(right_top_editor_); + ConnectChangeEvent(left_bottom_editor_); + ConnectChangeEvent(right_bottom_editor_); } CornerRadiusPropertyEditor::~CornerRadiusPropertyEditor() {} +ui::CornerRadius CornerRadiusPropertyEditor::GetValue() const { + return ui::CornerRadius( + left_top_editor_.GetValue(), right_top_editor_.GetValue(), + left_bottom_editor_.GetValue(), right_bottom_editor_.GetValue()); +} + void CornerRadiusPropertyEditor::SetValue(const ui::CornerRadius& corner_radius, bool trigger_change) { left_top_editor_.SetValue(corner_radius.left_top, false); right_top_editor_.SetValue(corner_radius.right_top, false); left_bottom_editor_.SetValue(corner_radius.left_bottom, false); right_bottom_editor_.SetValue(corner_radius.right_bottom, false); - if (trigger_change) change_event_.Raise(nullptr); + if (trigger_change) RaiseChangeEvent(); } } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h index 06e1f024..6b6833d1 100644 --- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h +++ b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once +#include "../Editor.h" #include "PointPropertyEditor.h" #include "cru/ui/Base.h" -#include "cru/ui/components/Component.h" #include "cru/ui/controls/FlexLayout.h" namespace cru::theme_builder::components::properties { -class CornerRadiusPropertyEditor : public ui::components::Component { +class CornerRadiusPropertyEditor : public Editor { public: using PropertyType = ui::CornerRadius; @@ -14,21 +14,15 @@ class CornerRadiusPropertyEditor : public ui::components::Component { ui::controls::Control* GetRootControl() override { return &container_; } - ui::CornerRadius GetValue() const { return corner_radius_; } + ui::CornerRadius GetValue() const; void SetValue(const ui::CornerRadius& corner_radius, bool trigger_change = true); - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } - private: - ui::CornerRadius corner_radius_; - ui::controls::FlexLayout container_; PointPropertyEditor left_top_editor_; PointPropertyEditor right_top_editor_; PointPropertyEditor left_bottom_editor_; PointPropertyEditor right_bottom_editor_; - - Event<std::nullptr_t> change_event_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/OptionalPropertyEditor.h b/src/theme_builder/components/properties/OptionalPropertyEditor.h index 4467d4de..d7362d50 100644 --- a/src/theme_builder/components/properties/OptionalPropertyEditor.h +++ b/src/theme_builder/components/properties/OptionalPropertyEditor.h @@ -1,5 +1,5 @@ #pragma once -#include "cru/ui/components/Component.h" +#include "../Editor.h" #include "cru/ui/controls/CheckBox.h" #include "cru/ui/controls/FlexLayout.h" @@ -7,7 +7,7 @@ namespace cru::theme_builder::components::properties { template <typename TEditor> -class OptionalPropertyEditor : public ui::components::Component { +class OptionalPropertyEditor : public Editor { public: using PropertyType = typename TEditor::PropertyType; @@ -17,7 +17,7 @@ class OptionalPropertyEditor : public ui::components::Component { editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) { if (IsEnabled()) { - change_event_.Raise(nullptr); + RaiseChangeEvent(); } }); } @@ -29,7 +29,7 @@ class OptionalPropertyEditor : public ui::components::Component { void SetEnabled(bool enabled, bool trigger_change = true) { check_box_.SetChecked(enabled); if (trigger_change) { - change_event_.Raise(nullptr); + RaiseChangeEvent(); } } @@ -42,7 +42,7 @@ class OptionalPropertyEditor : public ui::components::Component { if (value) { SetEnabled(true, false); editor_.SetValue(*value, false); - if (trigger_change) change_event_.Raise(nullptr); + if (trigger_change) RaiseChangeEvent(); } else { SetEnabled(false, trigger_change); } @@ -50,13 +50,9 @@ class OptionalPropertyEditor : public ui::components::Component { TEditor* GetEditor() { return &editor_; } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } - private: ui::controls::FlexLayout container_; ui::controls::CheckBox check_box_; TEditor editor_; - - Event<std::nullptr_t> change_event_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/PointPropertyEditor.cpp b/src/theme_builder/components/properties/PointPropertyEditor.cpp index 60f3c06c..6d4277aa 100644 --- a/src/theme_builder/components/properties/PointPropertyEditor.cpp +++ b/src/theme_builder/components/properties/PointPropertyEditor.cpp @@ -9,21 +9,17 @@ PointPropertyEditor::PointPropertyEditor() { container_.AddChild(&text_); text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { - if (!suppress_next_change_event_) { - auto text = text_.GetTextView(); - auto point_mapper = - ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Point>(); - try { - auto point = point_mapper->MapFromString(text.ToString()); - point_ = point; - is_text_valid_ = true; - change_event_.Raise(nullptr); - } catch (const Exception&) { - is_text_valid_ = false; - // TODO: Show error! - } - } else { - suppress_next_change_event_ = false; + auto text = text_.GetTextView(); + auto point_mapper = + ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Point>(); + try { + auto point = point_mapper->MapFromString(text.ToString()); + point_ = point; + is_text_valid_ = true; + RaiseChangeEvent(); + } catch (const Exception&) { + is_text_valid_ = false; + // TODO: Show error! } }); } @@ -32,9 +28,7 @@ PointPropertyEditor::~PointPropertyEditor() {} void PointPropertyEditor::SetValue(const ui::Point& point, bool trigger_change) { - point_ = point; - is_text_valid_ = true; - if (!trigger_change) suppress_next_change_event_ = true; + if (!trigger_change) SuppressNextChangeEvent(); text_.SetText(ConvertPointToString(point)); } diff --git a/src/theme_builder/components/properties/PointPropertyEditor.h b/src/theme_builder/components/properties/PointPropertyEditor.h index e4604c84..bd852e3a 100644 --- a/src/theme_builder/components/properties/PointPropertyEditor.h +++ b/src/theme_builder/components/properties/PointPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once -#include "cru/ui/components/Component.h" +#include "../Editor.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class PointPropertyEditor : public ui::components::Component { +class PointPropertyEditor : public Editor { public: using PropertyType = ui::Point; @@ -21,8 +21,6 @@ class PointPropertyEditor : public ui::components::Component { ui::Point GetValue() const { return point_; } void SetValue(const ui::Point& point, bool trigger_change = true); - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } - private: static String ConvertPointToString(const ui::Point& point); @@ -33,8 +31,5 @@ class PointPropertyEditor : public ui::components::Component { ui::controls::TextBlock label_; ui::controls::TextBox text_; bool is_text_valid_; - - bool suppress_next_change_event_ = false; - Event<std::nullptr_t> change_event_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.cpp b/src/theme_builder/components/properties/SelectPropertyEditor.cpp index 243f6035..835b2d12 100644 --- a/src/theme_builder/components/properties/SelectPropertyEditor.cpp +++ b/src/theme_builder/components/properties/SelectPropertyEditor.cpp @@ -7,15 +7,9 @@ SelectPropertyEditor::SelectPropertyEditor() { container_.AddChild(&label_); container_.AddChild(select_.GetRootControl()); - select_.ItemSelectedEvent()->AddHandler([this](Index index) { - if (!suppress_next_change_event_) { - change_event_.Raise(nullptr); - } else { - suppress_next_change_event_ = false; - } - }); + select_.ItemSelectedEvent()->AddHandler( + [this](Index index) { RaiseChangeEvent(); }); } SelectPropertyEditor::~SelectPropertyEditor() {} - } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.h b/src/theme_builder/components/properties/SelectPropertyEditor.h index a67cb80f..475d2d0a 100644 --- a/src/theme_builder/components/properties/SelectPropertyEditor.h +++ b/src/theme_builder/components/properties/SelectPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once -#include "cru/ui/components/Component.h" +#include "../Editor.h" #include "cru/ui/components/Select.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/controls/TextBlock.h" namespace cru::theme_builder::components::properties { -class SelectPropertyEditor : public ui::components::Component { +class SelectPropertyEditor : public Editor { public: using PropertyType = Index; @@ -20,7 +20,7 @@ class SelectPropertyEditor : public ui::components::Component { Index GetSelectedIndex() const { return select_.GetSelectedIndex(); } void SetSelectedIndex(Index index, bool trigger_change = true) { - if (trigger_change == false) suppress_next_change_event_ = true; + if (trigger_change == false) SuppressNextChangeEvent(); select_.SetSelectedIndex(index); } @@ -34,14 +34,9 @@ class SelectPropertyEditor : public ui::components::Component { SetSelectedIndex(value, trigger_change); } - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } - private: ui::controls::FlexLayout container_; ui::controls::TextBlock label_; ui::components::Select select_; - - bool suppress_next_change_event_ = false; - Event<std::nullptr_t> change_event_; }; } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp index c5e5f658..3e022bb1 100644 --- a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp +++ b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp @@ -8,14 +8,14 @@ ThicknessPropertyEditor::ThicknessPropertyEditor() { container_.AddChild(&text_); text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { - auto text = text_.GetTextView(); + auto text = text_.GetText(); auto thickness_mapper = ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Thickness>(); try { - auto thickness = thickness_mapper->MapFromString(text.ToString()); + auto thickness = thickness_mapper->MapFromString(text); thickness_ = thickness; is_text_valid_ = true; - change_event_.Raise(nullptr); + RaiseChangeEvent(); } catch (const Exception &) { is_text_valid_ = false; // TODO: Show error! @@ -27,10 +27,8 @@ ThicknessPropertyEditor::~ThicknessPropertyEditor() {} void ThicknessPropertyEditor::SetValue(const ui::Thickness &thickness, bool trigger_change) { - thickness_ = thickness; - text_.SetText(Format(u"{} {} {} {}", thickness_.left, thickness_.top, - thickness_.right, thickness_.bottom)); - is_text_valid_ = true; - if (trigger_change) change_event_.Raise(nullptr); + if (!trigger_change) SuppressNextChangeEvent(); + text_.SetText(Format(u"{} {} {} {}", thickness.left, thickness.top, + thickness.right, thickness.bottom)); } } // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/ThicknessPropertyEditor.h b/src/theme_builder/components/properties/ThicknessPropertyEditor.h index 87b160c6..cea9ae9d 100644 --- a/src/theme_builder/components/properties/ThicknessPropertyEditor.h +++ b/src/theme_builder/components/properties/ThicknessPropertyEditor.h @@ -1,11 +1,11 @@ #pragma once -#include "cru/ui/components/Component.h" +#include "../Editor.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/TextBox.h" namespace cru::theme_builder::components::properties { -class ThicknessPropertyEditor : public ui::components::Component { +class ThicknessPropertyEditor : public Editor { public: using PropertyType = ui::Thickness; @@ -20,8 +20,6 @@ class ThicknessPropertyEditor : public ui::components::Component { ui::Thickness GetValue() const { return thickness_; } void SetValue(const ui::Thickness& thickness, bool trigger_change = true); - IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } - private: ui::Thickness thickness_; @@ -29,7 +27,5 @@ class ThicknessPropertyEditor : public ui::components::Component { ui::controls::TextBlock label_; ui::controls::TextBox text_; bool is_text_valid_; - - Event<std::nullptr_t> change_event_; }; } // namespace cru::theme_builder::components::properties |