From 65e288c40a593965b41378755f7111c56e123295 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 26 Feb 2022 19:46:37 +0800 Subject: ... --- assets/cru/theme_builder/ThemeResources.xml | 16 ++++++++++++++++ include/cru/ui/ThemeResourceDictionary.h | 11 +++++++++-- include/cru/ui/controls/Container.h | 15 ++++++++++++++- src/theme_builder/CMakeLists.txt | 1 + .../components/properties/ColorPropertyEditor.cpp | 7 +++++++ src/theme_builder/main.cpp | 10 ++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 assets/cru/theme_builder/ThemeResources.xml diff --git a/assets/cru/theme_builder/ThemeResources.xml b/assets/cru/theme_builder/ThemeResources.xml new file mode 100644 index 00000000..544f6908 --- /dev/null +++ b/assets/cru/theme_builder/ThemeResources.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h index 26f7ec8d..a303b466 100644 --- a/include/cru/ui/ThemeResourceDictionary.h +++ b/include/cru/ui/ThemeResourceDictionary.h @@ -7,6 +7,7 @@ #include "style/StyleRuleSet.h" #include +#include #include #include @@ -25,9 +26,15 @@ class CRU_UI_API ThemeResourceDictionary : public Object { CRU_DEFINE_CLASS_LOG_TAG(u"ThemeResources"); public: - static std::unique_ptr FromFile(const String& file_path); + static std::unique_ptr FromFile( + const String& file_path); + static std::unique_ptr FromFile( + std::filesystem::path file_path) { + return FromFile(String::FromStdPath(file_path)); + } - explicit ThemeResourceDictionary(xml::XmlElementNode* xml_root, bool clone = true); + explicit ThemeResourceDictionary(xml::XmlElementNode* xml_root, + bool clone = true); CRU_DELETE_COPY(ThemeResourceDictionary) CRU_DELETE_MOVE(ThemeResourceDictionary) diff --git a/include/cru/ui/controls/Container.h b/include/cru/ui/controls/Container.h index 98958b3b..c8bf3f32 100644 --- a/include/cru/ui/controls/Container.h +++ b/include/cru/ui/controls/Container.h @@ -2,10 +2,12 @@ #include "SingleChildControl.h" #include "../render/BorderRenderObject.h" +#include "IBorderControl.h" namespace cru::ui::controls { class CRU_UI_API Container - : public SingleChildControl { + : public SingleChildControl, + public virtual IBorderControl { static constexpr StringView kControlType = u"Container"; public: @@ -16,6 +18,13 @@ class CRU_UI_API Container ~Container() override; public: + bool IsBorderEnabled() const { + return GetContainerRenderObject()->IsBorderEnabled(); + } + void SetBorderEnabled(bool enabled) { + GetContainerRenderObject()->SetBorderEnabled(enabled); + } + std::shared_ptr GetForegroundBrush() const { return GetContainerRenderObject()->GetForegroundBrush(); } @@ -32,6 +41,10 @@ class CRU_UI_API Container GetContainerRenderObject()->SetBackgroundBrush(brush); } + void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override { + GetContainerRenderObject()->ApplyBorderStyle(style); + } + public: String GetControlType() const final { return kControlType.ToString(); } }; diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt index dff58874..709c4d76 100644 --- a/src/theme_builder/CMakeLists.txt +++ b/src/theme_builder/CMakeLists.txt @@ -34,4 +34,5 @@ if(APPLE) endif() target_add_resources(cru_theme_builder cru/ui) +target_add_resources(cru_theme_builder cru/theme_builder) target_link_libraries(cru_theme_builder PRIVATE cru_platform_bootstrap cru_ui) diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.cpp b/src/theme_builder/components/properties/ColorPropertyEditor.cpp index 49911f77..89b145a7 100644 --- a/src/theme_builder/components/properties/ColorPropertyEditor.cpp +++ b/src/theme_builder/components/properties/ColorPropertyEditor.cpp @@ -1,6 +1,7 @@ #include "ColorPropertyEditor.h" #include "cru/platform/graphics/Factory.h" #include "cru/ui/Base.h" +#include "cru/ui/ThemeManager.h" namespace cru::theme_builder::components::properties { ColorPropertyEditor::ColorPropertyEditor() { @@ -8,9 +9,15 @@ ColorPropertyEditor::ColorPropertyEditor() { container_.AddChild(&color_cube_); container_.AddChild(&color_text_); + color_cube_.SetBorderEnabled(true); + color_cube_.GetStyleRuleSet()->SetParent( + ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( + u"cru.theme_builder.color_cube.style")); + color_cube_brush_ = platform::gui::IUiApplication::GetInstance() ->GetGraphicsFactory() ->CreateSolidColorBrush(color_); + color_cube_.SetForegroundBrush(color_cube_brush_); color_text_.SetText(color_.ToString()); diff --git a/src/theme_builder/main.cpp b/src/theme_builder/main.cpp index 7e7faa3d..df03b379 100644 --- a/src/theme_builder/main.cpp +++ b/src/theme_builder/main.cpp @@ -1,8 +1,18 @@ #include "components/MainWindow.h" +#include "cru/common/io/Resource.h" #include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/ui/ThemeManager.h" +#include "cru/ui/ThemeResourceDictionary.h" int main() { using namespace cru::theme_builder; + using namespace cru::ui; + + auto resource_dir = cru::io::GetResourceDir(); + + ThemeManager::GetInstance()->PrependThemeResourceDictionary( + ThemeResourceDictionary::FromFile(resource_dir / + "cru/theme_builder/ThemeResources.xml")); std::unique_ptr application( cru::platform::bootstrap::CreateUiApplication()); -- cgit v1.2.3