diff options
-rw-r--r-- | src/theme_builder/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/theme_builder/components/Common.cpp | 22 | ||||
-rw-r--r-- | src/theme_builder/components/Common.h | 7 | ||||
-rw-r--r-- | src/theme_builder/components/MainWindow.cpp | 4 | ||||
-rw-r--r-- | src/theme_builder/components/MainWindow.h | 4 | ||||
-rw-r--r-- | src/theme_builder/components/StyleRuleEditor.cpp | 8 | ||||
-rw-r--r-- | src/theme_builder/components/StyleRuleEditor.h | 7 | ||||
-rw-r--r-- | src/theme_builder/components/StyleRuleSetEditor.cpp | 4 | ||||
-rw-r--r-- | src/theme_builder/components/StyleRuleSetEditor.h | 4 | ||||
-rw-r--r-- | src/theme_builder/components/stylers/StylerEditor.cpp | 4 | ||||
-rw-r--r-- | src/theme_builder/components/stylers/StylerEditor.h | 4 | ||||
-rw-r--r-- | src/theme_builder/main.cpp | 6 |
12 files changed, 58 insertions, 17 deletions
diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt index 87669da9..94de566e 100644 --- a/src/theme_builder/CMakeLists.txt +++ b/src/theme_builder/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(cru_theme_builder main.cpp + components/Common.cpp components/Editor.cpp components/MainWindow.cpp components/StyleRuleEditor.cpp diff --git a/src/theme_builder/components/Common.cpp b/src/theme_builder/components/Common.cpp new file mode 100644 index 00000000..75d5deb0 --- /dev/null +++ b/src/theme_builder/components/Common.cpp @@ -0,0 +1,22 @@ +#include "Common.h" +#include "cru/platform/Color.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/gui/UiApplication.h" + +#include <random> + +namespace cru::theme_builder::components { +std::unique_ptr<platform::graphics::ISolidColorBrush> +CreateRandomEditorBackgroundBrush() { + static float current_hue = 0.0f; + current_hue += 23.f; + if (current_hue > 360.f) { + current_hue -= 360.f; + } + + return platform::gui::IUiApplication::GetInstance() + ->GetGraphicsFactory() + ->CreateSolidColorBrush(platform::HslColor(current_hue, 0.5f, 0.8f)); +} + +} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/Common.h b/src/theme_builder/components/Common.h new file mode 100644 index 00000000..b91fcf88 --- /dev/null +++ b/src/theme_builder/components/Common.h @@ -0,0 +1,7 @@ +#pragma once +#include "cru/platform/graphics/Brush.h" + +namespace cru::theme_builder::components { +std::unique_ptr<platform::graphics::ISolidColorBrush> +CreateRandomEditorBackgroundBrush(); +} diff --git a/src/theme_builder/components/MainWindow.cpp b/src/theme_builder/components/MainWindow.cpp index fa8b04bc..0c78ef25 100644 --- a/src/theme_builder/components/MainWindow.cpp +++ b/src/theme_builder/components/MainWindow.cpp @@ -3,7 +3,7 @@ #include "cru/ui/controls/StackLayout.h" #include "cru/ui/controls/TextBlock.h" -namespace cru::theme_builder { +namespace cru::theme_builder::components { using namespace cru::ui; using namespace cru::ui::controls; using namespace cru::platform::gui; @@ -34,4 +34,4 @@ void MainWindow::Show() { window_.GetNativeWindow()->SetVisibility(WindowVisibilityType::Show); window_.GetNativeWindow()->SetToForeground(); } -} // namespace cru::theme_builder +} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/MainWindow.h b/src/theme_builder/components/MainWindow.h index 8d1675f3..ede1c38f 100644 --- a/src/theme_builder/components/MainWindow.h +++ b/src/theme_builder/components/MainWindow.h @@ -7,7 +7,7 @@ #include "cru/ui/controls/TextBlock.h" #include "cru/ui/controls/Window.h" -namespace cru::theme_builder { +namespace cru::theme_builder::components { class MainWindow : public ui::components::Component { public: MainWindow(); @@ -29,4 +29,4 @@ class MainWindow : public ui::components::Component { ui::controls::TextBlock preview_button_text_; StyleRuleSetEditor style_rule_set_editor_; }; -} // namespace cru::theme_builder +} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleEditor.cpp b/src/theme_builder/components/StyleRuleEditor.cpp index eefe9451..6aef6455 100644 --- a/src/theme_builder/components/StyleRuleEditor.cpp +++ b/src/theme_builder/components/StyleRuleEditor.cpp @@ -1,10 +1,14 @@ #include "StyleRuleEditor.h" +#include "Common.h" #include "conditions/ConditionEditor.h" #include "cru/ui/ThemeManager.h" #include "cru/ui/style/StyleRule.h" -namespace cru::theme_builder { +namespace cru::theme_builder::components { StyleRuleEditor::StyleRuleEditor() { + container_.SetChild(&main_layout_); + container_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush()); + main_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); main_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); @@ -55,4 +59,4 @@ void StyleRuleEditor::SetValue(const ui::style::StyleRule& style_rule, change_event_.Raise(nullptr); } } -} // namespace cru::theme_builder +} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleEditor.h b/src/theme_builder/components/StyleRuleEditor.h index 8cee966f..e819fc98 100644 --- a/src/theme_builder/components/StyleRuleEditor.h +++ b/src/theme_builder/components/StyleRuleEditor.h @@ -8,7 +8,7 @@ #include "cru/ui/style/StyleRule.h" #include "stylers/StylerEditor.h" -namespace cru::theme_builder { +namespace cru::theme_builder::components { class StyleRuleEditor : public ui::components::Component { public: StyleRuleEditor(); @@ -19,7 +19,7 @@ class StyleRuleEditor : public ui::components::Component { ~StyleRuleEditor() override; public: - ui::controls::Control* GetRootControl() override { return &main_layout_; } + ui::controls::Control* GetRootControl() override { return &container_; } ui::style::StyleRule GetValue() const; void SetValue(const ui::style::StyleRule& style_rule, @@ -29,6 +29,7 @@ class StyleRuleEditor : public ui::components::Component { IEvent<std::nullptr_t>* RemoveEvent() { return &remove_event_; } private: + ui::controls::Container container_; ui::controls::FlexLayout main_layout_; ui::controls::TextBlock label_; ui::controls::FlexLayout head_layout_; @@ -41,4 +42,4 @@ class StyleRuleEditor : public ui::components::Component { Event<std::nullptr_t> change_event_; Event<std::nullptr_t> remove_event_; }; -} // namespace cru::theme_builder +} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleSetEditor.cpp b/src/theme_builder/components/StyleRuleSetEditor.cpp index dde7f3b8..dc09125f 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.cpp +++ b/src/theme_builder/components/StyleRuleSetEditor.cpp @@ -3,7 +3,7 @@ #include "cru/ui/style/Condition.h" #include "cru/ui/style/Styler.h" -namespace cru::theme_builder { +namespace cru::theme_builder::components { using namespace cru::ui::controls; StyleRuleSetEditor::StyleRuleSetEditor() { scroll_view_.SetChild(&container_); @@ -50,4 +50,4 @@ void StyleRuleSetEditor::BindStyleRuleSet( rules_layout_.AddChild(style_rule_editors_.back()->GetRootControl()); } } -} // namespace cru::theme_builder +} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleSetEditor.h b/src/theme_builder/components/StyleRuleSetEditor.h index c58a7a3d..3ffad77f 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.h +++ b/src/theme_builder/components/StyleRuleSetEditor.h @@ -7,7 +7,7 @@ #include "cru/ui/controls/ScrollView.h" #include "cru/ui/style/StyleRuleSet.h" -namespace cru::theme_builder { +namespace cru::theme_builder::components { class StyleRuleSetEditor : public ui::components::Component { public: StyleRuleSetEditor(); @@ -32,4 +32,4 @@ class StyleRuleSetEditor : public ui::components::Component { ui::controls::Button add_button_; ui::controls::TextBlock add_button_text_; }; -} // namespace cru::theme_builder +} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/stylers/StylerEditor.cpp b/src/theme_builder/components/stylers/StylerEditor.cpp index 8b18969c..662e5a08 100644 --- a/src/theme_builder/components/stylers/StylerEditor.cpp +++ b/src/theme_builder/components/stylers/StylerEditor.cpp @@ -1,4 +1,5 @@ #include "StylerEditor.h" +#include "../Common.h" #include "BorderStylerEditor.h" #include "CompoundStylerEditor.h" #include "ContentBrushStylerEditor.h" @@ -13,6 +14,9 @@ namespace cru::theme_builder::components::stylers { StylerEditor::StylerEditor() { + border_.SetChild(&container_); + border_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush()); + container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); container_.AddChild(&head_container_); container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); diff --git a/src/theme_builder/components/stylers/StylerEditor.h b/src/theme_builder/components/stylers/StylerEditor.h index 482cce7d..3cbcb5a5 100644 --- a/src/theme_builder/components/stylers/StylerEditor.h +++ b/src/theme_builder/components/stylers/StylerEditor.h @@ -1,5 +1,6 @@ #pragma once #include "../Editor.h" +#include "cru/ui/controls/Container.h" #include "cru/ui/controls/FlexLayout.h" #include "cru/ui/controls/TextBlock.h" #include "cru/ui/style/Styler.h" @@ -11,7 +12,7 @@ class StylerEditor : public Editor { ~StylerEditor() override; public: - ui::controls::Control* GetRootControl() override { return &container_; } + ui::controls::Control* GetRootControl() override { return &border_; } ui::controls::FlexLayout* GetContainer() { return &container_; } @@ -23,6 +24,7 @@ class StylerEditor : public Editor { virtual ClonablePtr<ui::style::Styler> GetStyler() = 0; private: + ui::controls::Container border_; ui::controls::FlexLayout container_; ui::controls::FlexLayout head_container_; ui::controls::TextBlock label_; diff --git a/src/theme_builder/main.cpp b/src/theme_builder/main.cpp index df03b379..0c5b2159 100644 --- a/src/theme_builder/main.cpp +++ b/src/theme_builder/main.cpp @@ -5,14 +5,14 @@ #include "cru/ui/ThemeResourceDictionary.h" int main() { - using namespace cru::theme_builder; + using namespace cru::theme_builder::components; using namespace cru::ui; auto resource_dir = cru::io::GetResourceDir(); ThemeManager::GetInstance()->PrependThemeResourceDictionary( - ThemeResourceDictionary::FromFile(resource_dir / - "cru/theme_builder/ThemeResources.xml")); + ThemeResourceDictionary::FromFile( + resource_dir / "cru/theme_builder/ThemeResources.xml")); std::unique_ptr<cru::platform::gui::IUiApplication> application( cru::platform::bootstrap::CreateUiApplication()); |