aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/ui/controls/CheckBox.h6
-rw-r--r--include/cru/ui/style/Styler.h2
-rw-r--r--src/theme_builder/components/properties/ColorPropertyEditor.h2
-rw-r--r--src/theme_builder/components/properties/CornerRadiusPropertyEditor.h2
-rw-r--r--src/theme_builder/components/properties/OptionalPropertyEditor.h28
-rw-r--r--src/theme_builder/components/styler/BorderStylerEditor.cpp100
-rw-r--r--src/theme_builder/components/styler/BorderStylerEditor.h43
7 files changed, 182 insertions, 1 deletions
diff --git a/include/cru/ui/controls/CheckBox.h b/include/cru/ui/controls/CheckBox.h
index 1c81b284..19908389 100644
--- a/include/cru/ui/controls/CheckBox.h
+++ b/include/cru/ui/controls/CheckBox.h
@@ -12,9 +12,13 @@ class CRU_UI_API CheckBox : public NoChildControl,
public virtual ICheckableControl,
public virtual IClickableControl {
public:
+ static constexpr StringView kControlType = u"CheckBox";
+
CheckBox();
~CheckBox() override;
+ String GetControlType() const override { return kControlType.ToString(); }
+
render::RenderObject* GetRenderObject() const override {
return container_render_object_.get();
}
@@ -27,7 +31,7 @@ class CRU_UI_API CheckBox : public NoChildControl,
void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override;
- helper::ClickState GetClickState() const {
+ helper::ClickState GetClickState() override {
return click_detector_.GetState();
}
diff --git a/include/cru/ui/style/Styler.h b/include/cru/ui/style/Styler.h
index 4d812643..d6cbc760 100644
--- a/include/cru/ui/style/Styler.h
+++ b/include/cru/ui/style/Styler.h
@@ -60,6 +60,8 @@ class CRU_UI_API BorderStyler : public Styler {
void Apply(controls::Control* control) const override;
+ ApplyBorderStyleInfo GetBorderStyle() const { return style_; }
+
BorderStyler* Clone() const override { return new BorderStyler(style_); }
private:
diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.h b/src/theme_builder/components/properties/ColorPropertyEditor.h
index 7c7155ab..3ee0933b 100644
--- a/src/theme_builder/components/properties/ColorPropertyEditor.h
+++ b/src/theme_builder/components/properties/ColorPropertyEditor.h
@@ -13,6 +13,8 @@ class ColorPropertyEditor : public ui::components::Component {
~ColorPropertyEditor() override;
public:
+ ui::controls::Control* GetRootControl() override { return &container_; }
+
String GetLabel() const { return label_.GetText(); }
void SetLabel(String label) { label_.SetText(std::move(label)); }
diff --git a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h
index de55cdd4..04de2adf 100644
--- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h
+++ b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h
@@ -9,6 +9,8 @@ class CornerRadiusPropertyEditor : public ui::components::Component {
CornerRadiusPropertyEditor();
~CornerRadiusPropertyEditor() override;
+ ui::controls::Control* GetRootControl() override { return &container_; }
+
ui::CornerRadius GetCornerRadius() const { return corner_radius_; }
void SetCornerRadius(const ui::CornerRadius& corner_radius);
diff --git a/src/theme_builder/components/properties/OptionalPropertyEditor.h b/src/theme_builder/components/properties/OptionalPropertyEditor.h
new file mode 100644
index 00000000..e343727f
--- /dev/null
+++ b/src/theme_builder/components/properties/OptionalPropertyEditor.h
@@ -0,0 +1,28 @@
+#pragma once
+#include "cru/ui/components/Component.h"
+#include "cru/ui/controls/CheckBox.h"
+#include "cru/ui/controls/FlexLayout.h"
+
+namespace cru::theme_builder::components::properties {
+template <typename TEditor>
+class OptionalPropertyEditor : public ui::components::Component {
+ public:
+ OptionalPropertyEditor() {
+ container_.AddChild(&check_box_);
+ container_.AddChild(editor_->GetRootControl());
+ }
+ ~OptionalPropertyEditor() override { container_.RemoveFromParent(); }
+
+ ui::controls::Control* GetRootControl() override { return &container_; }
+
+ bool IsEnabled() const { return check_box_.IsChecked(); }
+ void SetEnabled(bool enabled) { check_box_.SetChecked(enabled); }
+
+ TEditor* GetEditor() { return &editor_; }
+
+ private:
+ ui::controls::FlexLayout container_;
+ ui::controls::CheckBox check_box_;
+ TEditor editor_;
+};
+} // namespace cru::theme_builder::components::properties
diff --git a/src/theme_builder/components/styler/BorderStylerEditor.cpp b/src/theme_builder/components/styler/BorderStylerEditor.cpp
new file mode 100644
index 00000000..6c87ad32
--- /dev/null
+++ b/src/theme_builder/components/styler/BorderStylerEditor.cpp
@@ -0,0 +1,100 @@
+#include "BorderStylerEditor.h"
+#include <memory>
+#include "cru/common/ClonablePtr.h"
+#include "cru/platform/graphics/Brush.h"
+#include "cru/platform/graphics/Factory.h"
+#include "cru/platform/gui/UiApplication.h"
+#include "cru/ui/style/ApplyBorderStyleInfo.h"
+#include "cru/ui/style/Styler.h"
+
+namespace cru::theme_builder::components::styler {
+BorderStylerEditor::BorderStylerEditor() {
+ container_.AddChild(corner_radius_editor_.GetRootControl());
+ container_.AddChild(thickness_editor_.GetRootControl());
+ container_.AddChild(brush_editor_.GetRootControl());
+ container_.AddChild(foreground_brush_editor_.GetRootControl());
+ container_.AddChild(background_brush_editor_.GetRootControl());
+
+ // TODO: Add change listener.
+}
+
+BorderStylerEditor::~BorderStylerEditor() { container_.RemoveFromParent(); }
+
+ClonablePtr<ui::style::BorderStyler> BorderStylerEditor::GetStyler() {
+ auto graphics_factory =
+ platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory();
+
+ ui::style::ApplyBorderStyleInfo border_style;
+ if (corner_radius_editor_.IsEnabled()) {
+ border_style.border_radius =
+ corner_radius_editor_.GetEditor()->GetCornerRadius();
+ }
+
+ if (thickness_editor_.IsEnabled()) {
+ border_style.border_thickness =
+ thickness_editor_.GetEditor()->GetThickness();
+ }
+
+ if (brush_editor_.IsEnabled()) {
+ border_style.border_brush = graphics_factory->CreateSolidColorBrush(
+ brush_editor_.GetEditor()->GetColor());
+ }
+
+ if (foreground_brush_editor_.IsEnabled()) {
+ border_style.foreground_brush = graphics_factory->CreateSolidColorBrush(
+ foreground_brush_editor_.GetEditor()->GetColor());
+ }
+
+ if (background_brush_editor_.IsEnabled()) {
+ border_style.background_brush = graphics_factory->CreateSolidColorBrush(
+ background_brush_editor_.GetEditor()->GetColor());
+ }
+
+ return ui::style::BorderStyler::Create(border_style);
+}
+
+void BorderStylerEditor::SetStyler(
+ const ClonablePtr<ui::style::BorderStyler> &styler) {
+ Expects(styler);
+
+ auto border_style = styler->GetBorderStyle();
+ corner_radius_editor_.SetEnabled(border_style.border_radius.has_value());
+ if (border_style.border_radius.has_value()) {
+ corner_radius_editor_.GetEditor()->SetCornerRadius(
+ *border_style.border_radius);
+ }
+
+ thickness_editor_.SetEnabled(border_style.border_thickness.has_value());
+ if (border_style.border_thickness.has_value()) {
+ thickness_editor_.GetEditor()->SetThickness(*border_style.border_thickness);
+ }
+
+ brush_editor_.SetEnabled(border_style.border_brush.has_value());
+ if (border_style.border_brush.has_value()) {
+ brush_editor_.GetEditor()->SetColor(
+ std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
+ border_style.border_brush.value())
+ ->GetColor());
+ }
+
+ foreground_brush_editor_.SetEnabled(
+ border_style.foreground_brush.has_value());
+ if (border_style.foreground_brush.has_value()) {
+ foreground_brush_editor_.GetEditor()->SetColor(
+ std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
+ border_style.foreground_brush.value())
+ ->GetColor());
+ }
+
+ background_brush_editor_.SetEnabled(
+ border_style.background_brush.has_value());
+
+ if (border_style.background_brush.has_value()) {
+ background_brush_editor_.GetEditor()->SetColor(
+ std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
+ border_style.background_brush.value())
+ ->GetColor());
+ }
+}
+
+} // namespace cru::theme_builder::components::styler
diff --git a/src/theme_builder/components/styler/BorderStylerEditor.h b/src/theme_builder/components/styler/BorderStylerEditor.h
new file mode 100644
index 00000000..16ae64fb
--- /dev/null
+++ b/src/theme_builder/components/styler/BorderStylerEditor.h
@@ -0,0 +1,43 @@
+#pragma once
+#include "../properties/ColorPropertyEditor.h"
+#include "../properties/CornerRadiusPropertyEditor.h"
+#include "../properties/OptionalPropertyEditor.h"
+#include "../properties/ThicknessPropertyEditor.h"
+#include "cru/common/ClonablePtr.h"
+#include "cru/common/Event.h"
+#include "cru/ui/components/Component.h"
+#include "cru/ui/controls/CheckBox.h"
+#include "cru/ui/controls/FlexLayout.h"
+#include "cru/ui/style/Styler.h"
+
+namespace cru::theme_builder::components::styler {
+class BorderStylerEditor : public ui::components::Component {
+ public:
+ BorderStylerEditor();
+ ~BorderStylerEditor() override;
+
+ ui::controls::Control* GetRootControl() override { return nullptr; }
+
+ ClonablePtr<ui::style::BorderStyler> GetStyler();
+ void SetStyler(const ClonablePtr<ui::style::BorderStyler>& styler);
+
+ IEvent<ClonablePtr<ui::style::BorderStyler>>* ChangeEvent() {
+ return &change_event_;
+ }
+
+ private:
+ ui::controls::FlexLayout container_;
+ properties::OptionalPropertyEditor<properties::CornerRadiusPropertyEditor>
+ corner_radius_editor_;
+ properties::OptionalPropertyEditor<properties::ThicknessPropertyEditor>
+ thickness_editor_;
+ properties::OptionalPropertyEditor<properties::ColorPropertyEditor>
+ brush_editor_;
+ properties::OptionalPropertyEditor<properties::ColorPropertyEditor>
+ foreground_brush_editor_;
+ properties::OptionalPropertyEditor<properties::ColorPropertyEditor>
+ background_brush_editor_;
+
+ Event<ClonablePtr<ui::style::BorderStyler>> change_event_;
+};
+} // namespace cru::theme_builder::components::styler