From 34a64e6ffefaab007578932ddbab931a25f1d56e Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 15 May 2022 14:15:31 +0800 Subject: ... --- demos/CMakeLists.txt | 16 +-- demos/InputMethod/CMakeLists.txt | 12 ++ demos/InputMethod/main.cpp | 149 +++++++++++++++++++++ demos/ScrollView/CMakeLists.txt | 12 ++ demos/ScrollView/main.cpp | 87 ++++++++++++ demos/SvgPath/CMakeLists.txt | 12 ++ demos/SvgPath/main.cpp | 48 +++++++ demos/graphics/CMakeLists.txt | 2 +- demos/input_method/CMakeLists.txt | 12 -- demos/input_method/main.cpp | 149 --------------------- demos/main/CMakeLists.txt | 2 +- demos/scroll_view/CMakeLists.txt | 12 -- demos/scroll_view/main.cpp | 87 ------------ demos/svg_path/CMakeLists.txt | 12 -- demos/svg_path/main.cpp | 48 ------- src/CMakeLists.txt | 2 +- src/ThemeBuilder/CMakeLists.txt | 45 +++++++ src/ThemeBuilder/components/Common.cpp | 22 +++ src/ThemeBuilder/components/Common.h | 7 + src/ThemeBuilder/components/Editor.cpp | 23 ++++ src/ThemeBuilder/components/Editor.h | 25 ++++ src/ThemeBuilder/components/HeadBodyEditor.cpp | 30 +++++ src/ThemeBuilder/components/HeadBodyEditor.h | 36 +++++ src/ThemeBuilder/components/MainWindow.cpp | 37 +++++ src/ThemeBuilder/components/MainWindow.h | 32 +++++ src/ThemeBuilder/components/StyleRuleEditor.cpp | 62 +++++++++ src/ThemeBuilder/components/StyleRuleEditor.h | 45 +++++++ src/ThemeBuilder/components/StyleRuleSetEditor.cpp | 123 +++++++++++++++++ src/ThemeBuilder/components/StyleRuleSetEditor.h | 44 ++++++ .../conditions/CheckedConditionEditor.cpp | 26 ++++ .../components/conditions/CheckedConditionEditor.h | 28 ++++ .../conditions/ClickStateConditionEditor.cpp | 69 ++++++++++ .../conditions/ClickStateConditionEditor.h | 30 +++++ .../conditions/CompoundConditionEditor.cpp | 109 +++++++++++++++ .../conditions/CompoundConditionEditor.h | 72 ++++++++++ .../components/conditions/ConditionEditor.cpp | 50 +++++++ .../components/conditions/ConditionEditor.h | 17 +++ .../components/conditions/FocusConditionEditor.cpp | 25 ++++ .../components/conditions/FocusConditionEditor.h | 28 ++++ .../components/conditions/NoConditionEditor.cpp | 7 + .../components/conditions/NoConditionEditor.h | 17 +++ .../properties/CheckBoxPropertyEditor.cpp | 19 +++ .../components/properties/CheckBoxPropertyEditor.h | 29 ++++ .../components/properties/ColorPropertyEditor.cpp | 48 +++++++ .../components/properties/ColorPropertyEditor.h | 36 +++++ .../properties/CornerRadiusPropertyEditor.cpp | 42 ++++++ .../properties/CornerRadiusPropertyEditor.h | 28 ++++ .../components/properties/FontPropertyEditor.cpp | 60 +++++++++ .../components/properties/FontPropertyEditor.h | 38 ++++++ .../properties/MeasureLengthPropertyEditor.cpp | 37 +++++ .../properties/MeasureLengthPropertyEditor.h | 35 +++++ .../components/properties/OptionalPropertyEditor.h | 65 +++++++++ .../components/properties/PointPropertyEditor.cpp | 38 ++++++ .../components/properties/PointPropertyEditor.h | 35 +++++ .../components/properties/SelectPropertyEditor.cpp | 15 +++ .../components/properties/SelectPropertyEditor.h | 42 ++++++ .../components/properties/TextPropertyEditor.cpp | 22 +++ .../components/properties/TextPropertyEditor.h | 31 +++++ .../properties/ThicknessPropertyEditor.cpp | 34 +++++ .../properties/ThicknessPropertyEditor.h | 31 +++++ .../components/stylers/BorderStylerEditor.cpp | 100 ++++++++++++++ .../components/stylers/BorderStylerEditor.h | 36 +++++ .../components/stylers/CompoundStylerEditor.cpp | 105 +++++++++++++++ .../components/stylers/CompoundStylerEditor.h | 30 +++++ .../stylers/ContentBrushStylerEditor.cpp | 31 +++++ .../components/stylers/ContentBrushStylerEditor.h | 24 ++++ .../components/stylers/CursorStylerEditor.cpp | 65 +++++++++ .../components/stylers/CursorStylerEditor.h | 24 ++++ .../components/stylers/FontStylerEditor.cpp | 23 ++++ .../components/stylers/FontStylerEditor.h | 23 ++++ .../components/stylers/MarginStylerEditor.cpp | 28 ++++ .../components/stylers/MarginStylerEditor.h | 25 ++++ .../components/stylers/PaddingStylerEditor.cpp | 28 ++++ .../components/stylers/PaddingStylerEditor.h | 25 ++++ .../stylers/PreferredSizeStylerEditor.cpp | 34 +++++ .../components/stylers/PreferredSizeStylerEditor.h | 27 ++++ .../components/stylers/StylerEditor.cpp | 63 +++++++++ src/ThemeBuilder/components/stylers/StylerEditor.h | 16 +++ src/ThemeBuilder/main.cpp | 25 ++++ src/theme_builder/CMakeLists.txt | 45 ------- src/theme_builder/components/Common.cpp | 22 --- src/theme_builder/components/Common.h | 7 - src/theme_builder/components/Editor.cpp | 23 ---- src/theme_builder/components/Editor.h | 25 ---- src/theme_builder/components/HeadBodyEditor.cpp | 30 ----- src/theme_builder/components/HeadBodyEditor.h | 36 ----- src/theme_builder/components/MainWindow.cpp | 37 ----- src/theme_builder/components/MainWindow.h | 32 ----- src/theme_builder/components/StyleRuleEditor.cpp | 62 --------- src/theme_builder/components/StyleRuleEditor.h | 45 ------- .../components/StyleRuleSetEditor.cpp | 123 ----------------- src/theme_builder/components/StyleRuleSetEditor.h | 44 ------ .../conditions/CheckedConditionEditor.cpp | 26 ---- .../components/conditions/CheckedConditionEditor.h | 28 ---- .../conditions/ClickStateConditionEditor.cpp | 69 ---------- .../conditions/ClickStateConditionEditor.h | 30 ----- .../conditions/CompoundConditionEditor.cpp | 109 --------------- .../conditions/CompoundConditionEditor.h | 72 ---------- .../components/conditions/ConditionEditor.cpp | 50 ------- .../components/conditions/ConditionEditor.h | 17 --- .../components/conditions/FocusConditionEditor.cpp | 25 ---- .../components/conditions/FocusConditionEditor.h | 28 ---- .../components/conditions/NoConditionEditor.cpp | 7 - .../components/conditions/NoConditionEditor.h | 17 --- .../properties/CheckBoxPropertyEditor.cpp | 19 --- .../components/properties/CheckBoxPropertyEditor.h | 29 ---- .../components/properties/ColorPropertyEditor.cpp | 48 ------- .../components/properties/ColorPropertyEditor.h | 36 ----- .../properties/CornerRadiusPropertyEditor.cpp | 42 ------ .../properties/CornerRadiusPropertyEditor.h | 28 ---- .../components/properties/FontPropertyEditor.cpp | 60 --------- .../components/properties/FontPropertyEditor.h | 38 ------ .../properties/MeasureLengthPropertyEditor.cpp | 37 ----- .../properties/MeasureLengthPropertyEditor.h | 35 ----- .../components/properties/OptionalPropertyEditor.h | 65 --------- .../components/properties/PointPropertyEditor.cpp | 38 ------ .../components/properties/PointPropertyEditor.h | 35 ----- .../components/properties/SelectPropertyEditor.cpp | 15 --- .../components/properties/SelectPropertyEditor.h | 42 ------ .../components/properties/TextPropertyEditor.cpp | 22 --- .../components/properties/TextPropertyEditor.h | 31 ----- .../properties/ThicknessPropertyEditor.cpp | 34 ----- .../properties/ThicknessPropertyEditor.h | 31 ----- .../components/stylers/BorderStylerEditor.cpp | 100 -------------- .../components/stylers/BorderStylerEditor.h | 36 ----- .../components/stylers/CompoundStylerEditor.cpp | 105 --------------- .../components/stylers/CompoundStylerEditor.h | 30 ----- .../stylers/ContentBrushStylerEditor.cpp | 31 ----- .../components/stylers/ContentBrushStylerEditor.h | 24 ---- .../components/stylers/CursorStylerEditor.cpp | 65 --------- .../components/stylers/CursorStylerEditor.h | 24 ---- .../components/stylers/FontStylerEditor.cpp | 23 ---- .../components/stylers/FontStylerEditor.h | 23 ---- .../components/stylers/MarginStylerEditor.cpp | 28 ---- .../components/stylers/MarginStylerEditor.h | 25 ---- .../components/stylers/PaddingStylerEditor.cpp | 28 ---- .../components/stylers/PaddingStylerEditor.h | 25 ---- .../stylers/PreferredSizeStylerEditor.cpp | 34 ----- .../components/stylers/PreferredSizeStylerEditor.h | 27 ---- .../components/stylers/StylerEditor.cpp | 63 --------- .../components/stylers/StylerEditor.h | 16 --- src/theme_builder/main.cpp | 25 ---- test/CMakeLists.txt | 8 +- test/common/CMakeLists.txt | 7 +- test/platform/CMakeLists.txt | 7 +- test/platform/graphics/direct2d/CMakeLists.txt | 6 + test/platform/graphics/direct2d/ConvertTest.cpp | 31 +++++ test/toml/CMakeLists.txt | 2 +- test/win/CMakeLists.txt | 1 - test/win/graphics/CMakeLists.txt | 1 - test/win/graphics/direct/CMakeLists.txt | 13 -- test/win/graphics/direct/ConvertTest.cpp | 31 ----- test/xml/CMakeLists.txt | 2 +- 153 files changed, 2801 insertions(+), 2822 deletions(-) create mode 100644 demos/InputMethod/CMakeLists.txt create mode 100644 demos/InputMethod/main.cpp create mode 100644 demos/ScrollView/CMakeLists.txt create mode 100644 demos/ScrollView/main.cpp create mode 100644 demos/SvgPath/CMakeLists.txt create mode 100644 demos/SvgPath/main.cpp delete mode 100644 demos/input_method/CMakeLists.txt delete mode 100644 demos/input_method/main.cpp delete mode 100644 demos/scroll_view/CMakeLists.txt delete mode 100644 demos/scroll_view/main.cpp delete mode 100644 demos/svg_path/CMakeLists.txt delete mode 100644 demos/svg_path/main.cpp create mode 100644 src/ThemeBuilder/CMakeLists.txt create mode 100644 src/ThemeBuilder/components/Common.cpp create mode 100644 src/ThemeBuilder/components/Common.h create mode 100644 src/ThemeBuilder/components/Editor.cpp create mode 100644 src/ThemeBuilder/components/Editor.h create mode 100644 src/ThemeBuilder/components/HeadBodyEditor.cpp create mode 100644 src/ThemeBuilder/components/HeadBodyEditor.h create mode 100644 src/ThemeBuilder/components/MainWindow.cpp create mode 100644 src/ThemeBuilder/components/MainWindow.h create mode 100644 src/ThemeBuilder/components/StyleRuleEditor.cpp create mode 100644 src/ThemeBuilder/components/StyleRuleEditor.h create mode 100644 src/ThemeBuilder/components/StyleRuleSetEditor.cpp create mode 100644 src/ThemeBuilder/components/StyleRuleSetEditor.h create mode 100644 src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp create mode 100644 src/ThemeBuilder/components/conditions/CheckedConditionEditor.h create mode 100644 src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp create mode 100644 src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h create mode 100644 src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp create mode 100644 src/ThemeBuilder/components/conditions/CompoundConditionEditor.h create mode 100644 src/ThemeBuilder/components/conditions/ConditionEditor.cpp create mode 100644 src/ThemeBuilder/components/conditions/ConditionEditor.h create mode 100644 src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp create mode 100644 src/ThemeBuilder/components/conditions/FocusConditionEditor.h create mode 100644 src/ThemeBuilder/components/conditions/NoConditionEditor.cpp create mode 100644 src/ThemeBuilder/components/conditions/NoConditionEditor.h create mode 100644 src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/ColorPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/FontPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/FontPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/OptionalPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/PointPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/PointPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/SelectPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/SelectPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/TextPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/TextPropertyEditor.h create mode 100644 src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp create mode 100644 src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h create mode 100644 src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/BorderStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/CompoundStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/CursorStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/FontStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/FontStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/MarginStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/PaddingStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.h create mode 100644 src/ThemeBuilder/components/stylers/StylerEditor.cpp create mode 100644 src/ThemeBuilder/components/stylers/StylerEditor.h create mode 100644 src/ThemeBuilder/main.cpp delete mode 100644 src/theme_builder/CMakeLists.txt delete mode 100644 src/theme_builder/components/Common.cpp delete mode 100644 src/theme_builder/components/Common.h delete mode 100644 src/theme_builder/components/Editor.cpp delete mode 100644 src/theme_builder/components/Editor.h delete mode 100644 src/theme_builder/components/HeadBodyEditor.cpp delete mode 100644 src/theme_builder/components/HeadBodyEditor.h delete mode 100644 src/theme_builder/components/MainWindow.cpp delete mode 100644 src/theme_builder/components/MainWindow.h delete mode 100644 src/theme_builder/components/StyleRuleEditor.cpp delete mode 100644 src/theme_builder/components/StyleRuleEditor.h delete mode 100644 src/theme_builder/components/StyleRuleSetEditor.cpp delete mode 100644 src/theme_builder/components/StyleRuleSetEditor.h delete mode 100644 src/theme_builder/components/conditions/CheckedConditionEditor.cpp delete mode 100644 src/theme_builder/components/conditions/CheckedConditionEditor.h delete mode 100644 src/theme_builder/components/conditions/ClickStateConditionEditor.cpp delete mode 100644 src/theme_builder/components/conditions/ClickStateConditionEditor.h delete mode 100644 src/theme_builder/components/conditions/CompoundConditionEditor.cpp delete mode 100644 src/theme_builder/components/conditions/CompoundConditionEditor.h delete mode 100644 src/theme_builder/components/conditions/ConditionEditor.cpp delete mode 100644 src/theme_builder/components/conditions/ConditionEditor.h delete mode 100644 src/theme_builder/components/conditions/FocusConditionEditor.cpp delete mode 100644 src/theme_builder/components/conditions/FocusConditionEditor.h delete mode 100644 src/theme_builder/components/conditions/NoConditionEditor.cpp delete mode 100644 src/theme_builder/components/conditions/NoConditionEditor.h delete mode 100644 src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/CheckBoxPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/ColorPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/ColorPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/CornerRadiusPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/FontPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/FontPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/MeasureLengthPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/OptionalPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/PointPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/PointPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/SelectPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/SelectPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/TextPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/TextPropertyEditor.h delete mode 100644 src/theme_builder/components/properties/ThicknessPropertyEditor.cpp delete mode 100644 src/theme_builder/components/properties/ThicknessPropertyEditor.h delete mode 100644 src/theme_builder/components/stylers/BorderStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/BorderStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/CompoundStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/CompoundStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/ContentBrushStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/ContentBrushStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/CursorStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/CursorStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/FontStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/FontStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/MarginStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/MarginStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/PaddingStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/PaddingStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/PreferredSizeStylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/PreferredSizeStylerEditor.h delete mode 100644 src/theme_builder/components/stylers/StylerEditor.cpp delete mode 100644 src/theme_builder/components/stylers/StylerEditor.h delete mode 100644 src/theme_builder/main.cpp create mode 100644 test/platform/graphics/direct2d/CMakeLists.txt create mode 100644 test/platform/graphics/direct2d/ConvertTest.cpp delete mode 100644 test/win/CMakeLists.txt delete mode 100644 test/win/graphics/CMakeLists.txt delete mode 100644 test/win/graphics/direct/CMakeLists.txt delete mode 100644 test/win/graphics/direct/ConvertTest.cpp diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 220fbeae..9b8f0fec 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -1,23 +1,23 @@ -add_library(cru_demo_base INTERFACE) +add_library(CruDemoBase INTERFACE) -target_link_libraries(cru_demo_base INTERFACE CruPlatformBootstrap) +target_link_libraries(CruDemoBase INTERFACE CruPlatformBootstrap) if(WIN32) add_subdirectory(graphics) add_subdirectory(main) - add_subdirectory(scroll_view) + add_subdirectory(ScrollView) - add_subdirectory(input_method) - add_subdirectory(svg_path) + add_subdirectory(InputMethod) + add_subdirectory(SvgPath) elseif(APPLE) add_subdirectory(graphics) add_subdirectory(main) - add_subdirectory(scroll_view) + add_subdirectory(ScrollView) - add_subdirectory(input_method) - add_subdirectory(svg_path) + add_subdirectory(InputMethod) + add_subdirectory(SvgPath) elseif(UNIX) add_subdirectory(xcb) endif() diff --git a/demos/InputMethod/CMakeLists.txt b/demos/InputMethod/CMakeLists.txt new file mode 100644 index 00000000..8ceeaec9 --- /dev/null +++ b/demos/InputMethod/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(CruDemoInputMethod main.cpp) + +if(APPLE) + set_target_properties(CruDemoInputMethod PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_BUNDLE_NAME demo-input-method + MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-input-method + ) +endif() + +target_link_libraries(CruDemoInputMethod PRIVATE CruDemoBase) + diff --git a/demos/InputMethod/main.cpp b/demos/InputMethod/main.cpp new file mode 100644 index 00000000..abbbed2c --- /dev/null +++ b/demos/InputMethod/main.cpp @@ -0,0 +1,149 @@ +#include "cru/platform/Color.h" +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/Font.h" +#include "cru/platform/graphics/Painter.h" +#include "cru/platform/gui/InputMethod.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/platform/gui/Window.h" + +int main() { + using namespace cru; + using namespace cru::platform; + using namespace cru::platform::graphics; + using namespace cru::platform::gui; + + IUiApplication* application = bootstrap::CreateUiApplication(); + + auto graphics_factory = application->GetGraphicsFactory(); + + auto window = application->CreateWindow(); + + auto input_method_context = window->GetInputMethodContext(); + + auto brush = graphics_factory->CreateSolidColorBrush(); + brush->SetColor(colors::black); + + auto odd_clause_brush = graphics_factory->CreateSolidColorBrush(); + odd_clause_brush->SetColor(colors::yellow); + auto even_clause_brush = graphics_factory->CreateSolidColorBrush(); + even_clause_brush->SetColor(colors::green); + auto target_clause_brush = graphics_factory->CreateSolidColorBrush(); + target_clause_brush->SetColor(colors::blue); + + std::shared_ptr font = graphics_factory->CreateFont(String{}, 30); + + float window_width = 10000; + + auto prompt_text_layout = + graphics_factory->CreateTextLayout(font, + u"Ctrl+1: Enable IME\n" + u"Ctrl+2: Disable IME\n" + u"Ctrl+3: Complete composition.\n" + u"Ctrl+4: Cancel composition."); + + std::optional optional_composition_text; + String committed_text; + + window->ResizeEvent()->AddHandler( + [&prompt_text_layout, &window_width](const Size& size) { + prompt_text_layout->SetMaxWidth(size.width); + window_width = size.width; + }); + + window->PaintEvent()->AddHandler([&](auto) { + auto painter = window->BeginPaint(); + painter->Clear(colors::white); + + painter->DrawText(Point{}, prompt_text_layout.get(), brush.get()); + + const auto anchor_y = prompt_text_layout->GetTextBounds().height; + + auto text_layout = graphics_factory->CreateTextLayout( + font, committed_text + (optional_composition_text + ? optional_composition_text->text + : u"")); + text_layout->SetMaxWidth(window_width); + + if (optional_composition_text) { + const auto& composition_text = *optional_composition_text; + + for (int i = 0; i < static_cast(composition_text.clauses.size()); + i++) { + const auto& clause = composition_text.clauses[i]; + auto rects = text_layout->TextRangeRect(TextRange::FromTwoSides( + clause.start, clause.end, committed_text.size())); + const auto& b = clause.target + ? target_clause_brush + : (i % 2 ? odd_clause_brush : even_clause_brush); + for (auto& rect : rects) { + rect.top += anchor_y; + painter->FillRectangle(rect, b.get()); + } + } + } + + painter->DrawText(Point{0, anchor_y}, text_layout.get(), brush.get()); + + if (optional_composition_text) { + const auto& composition_text = *optional_composition_text; + + const auto cursor_pos = composition_text.selection.position + + gsl::narrow_cast(committed_text.size()); + + const auto cursor_lefttop = + text_layout->TextSinglePoint(cursor_pos, false); + + painter->FillRectangle( + Rect{cursor_lefttop.left, cursor_lefttop.top + anchor_y, 3, + cursor_lefttop.height}, + brush.get()); + } + + painter->EndDraw(); + }); + + window->KeyDownEvent()->AddHandler( + [&input_method_context](const NativeKeyEventArgs& args) { + if (args.modifier & KeyModifiers::ctrl) { + switch (args.key) { + case KeyCode::N1: + input_method_context->EnableIME(); + break; + case KeyCode::N2: + input_method_context->DisableIME(); + break; + case KeyCode::N3: + input_method_context->CompleteComposition(); + break; + case KeyCode::N4: + input_method_context->CancelComposition(); + break; + default: + break; + } + } + }); + + input_method_context->TextEvent()->AddHandler( + [window, &committed_text](const StringView& c) { + committed_text += c; + window->RequestRepaint(); + }); + + input_method_context->CompositionEvent()->AddHandler( + [window, &input_method_context, &optional_composition_text](auto) { + optional_composition_text = input_method_context->GetCompositionText(); + window->RequestRepaint(); + }); + + input_method_context->CompositionEndEvent()->AddHandler( + [window, &optional_composition_text](auto) { + optional_composition_text = std::nullopt; + window->RequestRepaint(); + }); + + window->SetVisibility(WindowVisibilityType::Show); + + return application->Run(); +} diff --git a/demos/ScrollView/CMakeLists.txt b/demos/ScrollView/CMakeLists.txt new file mode 100644 index 00000000..8b34f5d8 --- /dev/null +++ b/demos/ScrollView/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(CruDemoScrollView main.cpp) + +if(APPLE) + set_target_properties(CruDemoScrollView PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-scroll-view + MACOSX_BUNDLE_BUNDLE_NAME demo-scroll-view + ) +endif() + +target_add_resources(CruDemoScrollView cru/ui) +target_link_libraries(CruDemoScrollView PRIVATE CruDemoBase CruUi) diff --git a/demos/ScrollView/main.cpp b/demos/ScrollView/main.cpp new file mode 100644 index 00000000..b049a408 --- /dev/null +++ b/demos/ScrollView/main.cpp @@ -0,0 +1,87 @@ +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/platform/gui/Window.h" +#include "cru/ui/controls/ScrollView.h" +#include "cru/ui/controls/TextBlock.h" +#include "cru/ui/controls/Window.h" + +using cru::platform::gui::IUiApplication; +using cru::ui::controls::ScrollView; +using cru::ui::controls::TextBlock; +using cru::ui::controls::Window; + +int main() { + std::unique_ptr application( + cru::platform::bootstrap::CreateUiApplication()); + + Window window; + ScrollView scroll_view; + window.AddChild(&scroll_view); + + TextBlock text_block( + uR"([Verse 1] +The snow glows white on the mountain tonight +Not a footprint to be seen +A kingdom of isolation +And it looks like I'm the queen +The wind is howling like this swirling storm inside +Couldn't keep it in, Heaven knows I tried + +[Pre-Chorus] +Don't let them in, don't let them see +Be the good girl you always have to be +Conceal, don't feel, don't let them know +Well, now they know + +[Chorus] +Let it go, let it go +Can't hold it back anymore +Let it go, let it go +Turn away and slam the door +I don't care what they're going to say +Let the storm rage on +The cold never bothered me anyway + +[Verse 2] +It's funny how some distance +Makes everything seem small +And the fears that once controlled me +Can't get to me at all + +[Pre-Chorus] +It's time to see what I can do +To test the limits and break through +No right, no wrong, no rules for me +I'm free + +[Chorus] +Let it go, let it go +I'm one with the wind and sky +Let it go, let it go +You'll never see me cry +Here I stand, and here I'll stay +Let the storm rage on... + +[Bridge] +My power flurries through the air into the ground +My soul is spiraling in frozen fractals all around +And one thought crystallizes like an icy blast: +I'm never going back, the past is in the past! + +[Chorus] +Let it go, let it go +And I'll rise like the break of dawn +Let it go, let it go +That perfect girl is gone +Here I stand in the light of day +Let the storm rage on! +The cold never bothered me anyway)", + true); + + scroll_view.SetChild(&text_block); + + window.GetWindowHost()->GetNativeWindow()->SetVisibility( + cru::platform::gui::WindowVisibilityType::Show); + + return application->Run(); +} diff --git a/demos/SvgPath/CMakeLists.txt b/demos/SvgPath/CMakeLists.txt new file mode 100644 index 00000000..34120111 --- /dev/null +++ b/demos/SvgPath/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(CruDemoSvgPath main.cpp) + +if(APPLE) + set_target_properties(CruDemoSvgPath PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_BUNDLE_NAME cru-demo-svg-path + MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.demo-svg-path + ) +endif() + +target_link_libraries(CruDemoSvgPath PRIVATE CruDemoBase) + diff --git a/demos/SvgPath/main.cpp b/demos/SvgPath/main.cpp new file mode 100644 index 00000000..87c410e9 --- /dev/null +++ b/demos/SvgPath/main.cpp @@ -0,0 +1,48 @@ +#include "cru/platform/Color.h" +#include "cru/platform/bootstrap/Bootstrap.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/Font.h" +#include "cru/platform/graphics/Painter.h" +#include "cru/platform/gui/InputMethod.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/platform/gui/Window.h" + +int main() { + using namespace cru; + using namespace cru::platform; + using namespace cru::platform::graphics; + using namespace cru::platform::gui; + + IUiApplication* application = bootstrap::CreateUiApplication(); + + auto graphics_factory = application->GetGraphicsFactory(); + + auto window = application->CreateWindow(); + + auto brush = graphics_factory->CreateSolidColorBrush(colors::black); + + auto create_geometry = [graphics_factory](StringView path_d) { + auto geometry_builder = graphics_factory->CreateGeometryBuilder(); + geometry_builder->ParseAndApplySvgPathData(path_d); + return geometry_builder->Build(); + }; + + auto geometry = create_geometry( + uR"( +M8.5 5.5a.5.5 0 0 0-1 0v3.362l-1.429 2.38a.5.5 0 1 0 .858.515l1.5-2.5A.5.5 0 0 0 8.5 9V5.5z +M6.5 0a.5.5 0 0 0 0 1H7v1.07a7.001 7.001 0 0 0-3.273 12.474l-.602.602a.5.5 0 0 0 .707.708l.746-.746A6.97 6.97 0 0 0 8 16a6.97 6.97 0 0 0 3.422-.892l.746.746a.5.5 0 0 0 .707-.708l-.601-.602A7.001 7.001 0 0 0 9 2.07V1h.5a.5.5 0 0 0 0-1h-3zm1.038 3.018a6.093 6.093 0 0 1 .924 0 6 6 0 1 1-.924 0zM0 3.5c0 .753.333 1.429.86 1.887A8.035 8.035 0 0 1 4.387 1.86 2.5 2.5 0 0 0 0 3.5zM13.5 1c-.753 0-1.429.333-1.887.86a8.035 8.035 0 0 1 3.527 3.527A2.5 2.5 0 0 0 13.5 1z + )"); + + window->PaintEvent()->AddHandler([&](auto) { + auto painter = window->BeginPaint(); + painter->PushState(); + painter->ConcatTransform(Matrix::Scale(10, 10)); + painter->FillGeometry(geometry.get(), brush.get()); + painter->PopState(); + painter->EndDraw(); + }); + + window->SetVisibility(WindowVisibilityType::Show); + + return application->Run(); +} diff --git a/demos/graphics/CMakeLists.txt b/demos/graphics/CMakeLists.txt index 3a249b1d..b290ba13 100644 --- a/demos/graphics/CMakeLists.txt +++ b/demos/graphics/CMakeLists.txt @@ -1,3 +1,3 @@ add_executable(CruDemoGraphicsDrawCircle DrawCircle.cpp) -target_link_libraries(CruDemoGraphicsDrawCircle PRIVATE cru_demo_base) +target_link_libraries(CruDemoGraphicsDrawCircle PRIVATE CruDemoBase) diff --git a/demos/input_method/CMakeLists.txt b/demos/input_method/CMakeLists.txt deleted file mode 100644 index 7c19c4dd..00000000 --- a/demos/input_method/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable(CruDemoInputMethod main.cpp) - -if(APPLE) - set_target_properties(CruDemoInputMethod PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_BUNDLE_NAME demo-input-method - MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-input-method - ) -endif() - -target_link_libraries(CruDemoInputMethod PRIVATE cru_demo_base) - diff --git a/demos/input_method/main.cpp b/demos/input_method/main.cpp deleted file mode 100644 index abbbed2c..00000000 --- a/demos/input_method/main.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "cru/platform/Color.h" -#include "cru/platform/bootstrap/Bootstrap.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/graphics/Font.h" -#include "cru/platform/graphics/Painter.h" -#include "cru/platform/gui/InputMethod.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/platform/gui/Window.h" - -int main() { - using namespace cru; - using namespace cru::platform; - using namespace cru::platform::graphics; - using namespace cru::platform::gui; - - IUiApplication* application = bootstrap::CreateUiApplication(); - - auto graphics_factory = application->GetGraphicsFactory(); - - auto window = application->CreateWindow(); - - auto input_method_context = window->GetInputMethodContext(); - - auto brush = graphics_factory->CreateSolidColorBrush(); - brush->SetColor(colors::black); - - auto odd_clause_brush = graphics_factory->CreateSolidColorBrush(); - odd_clause_brush->SetColor(colors::yellow); - auto even_clause_brush = graphics_factory->CreateSolidColorBrush(); - even_clause_brush->SetColor(colors::green); - auto target_clause_brush = graphics_factory->CreateSolidColorBrush(); - target_clause_brush->SetColor(colors::blue); - - std::shared_ptr font = graphics_factory->CreateFont(String{}, 30); - - float window_width = 10000; - - auto prompt_text_layout = - graphics_factory->CreateTextLayout(font, - u"Ctrl+1: Enable IME\n" - u"Ctrl+2: Disable IME\n" - u"Ctrl+3: Complete composition.\n" - u"Ctrl+4: Cancel composition."); - - std::optional optional_composition_text; - String committed_text; - - window->ResizeEvent()->AddHandler( - [&prompt_text_layout, &window_width](const Size& size) { - prompt_text_layout->SetMaxWidth(size.width); - window_width = size.width; - }); - - window->PaintEvent()->AddHandler([&](auto) { - auto painter = window->BeginPaint(); - painter->Clear(colors::white); - - painter->DrawText(Point{}, prompt_text_layout.get(), brush.get()); - - const auto anchor_y = prompt_text_layout->GetTextBounds().height; - - auto text_layout = graphics_factory->CreateTextLayout( - font, committed_text + (optional_composition_text - ? optional_composition_text->text - : u"")); - text_layout->SetMaxWidth(window_width); - - if (optional_composition_text) { - const auto& composition_text = *optional_composition_text; - - for (int i = 0; i < static_cast(composition_text.clauses.size()); - i++) { - const auto& clause = composition_text.clauses[i]; - auto rects = text_layout->TextRangeRect(TextRange::FromTwoSides( - clause.start, clause.end, committed_text.size())); - const auto& b = clause.target - ? target_clause_brush - : (i % 2 ? odd_clause_brush : even_clause_brush); - for (auto& rect : rects) { - rect.top += anchor_y; - painter->FillRectangle(rect, b.get()); - } - } - } - - painter->DrawText(Point{0, anchor_y}, text_layout.get(), brush.get()); - - if (optional_composition_text) { - const auto& composition_text = *optional_composition_text; - - const auto cursor_pos = composition_text.selection.position + - gsl::narrow_cast(committed_text.size()); - - const auto cursor_lefttop = - text_layout->TextSinglePoint(cursor_pos, false); - - painter->FillRectangle( - Rect{cursor_lefttop.left, cursor_lefttop.top + anchor_y, 3, - cursor_lefttop.height}, - brush.get()); - } - - painter->EndDraw(); - }); - - window->KeyDownEvent()->AddHandler( - [&input_method_context](const NativeKeyEventArgs& args) { - if (args.modifier & KeyModifiers::ctrl) { - switch (args.key) { - case KeyCode::N1: - input_method_context->EnableIME(); - break; - case KeyCode::N2: - input_method_context->DisableIME(); - break; - case KeyCode::N3: - input_method_context->CompleteComposition(); - break; - case KeyCode::N4: - input_method_context->CancelComposition(); - break; - default: - break; - } - } - }); - - input_method_context->TextEvent()->AddHandler( - [window, &committed_text](const StringView& c) { - committed_text += c; - window->RequestRepaint(); - }); - - input_method_context->CompositionEvent()->AddHandler( - [window, &input_method_context, &optional_composition_text](auto) { - optional_composition_text = input_method_context->GetCompositionText(); - window->RequestRepaint(); - }); - - input_method_context->CompositionEndEvent()->AddHandler( - [window, &optional_composition_text](auto) { - optional_composition_text = std::nullopt; - window->RequestRepaint(); - }); - - window->SetVisibility(WindowVisibilityType::Show); - - return application->Run(); -} diff --git a/demos/main/CMakeLists.txt b/demos/main/CMakeLists.txt index 721ace19..2da90405 100644 --- a/demos/main/CMakeLists.txt +++ b/demos/main/CMakeLists.txt @@ -9,4 +9,4 @@ if(APPLE) endif() target_add_resources(CruDemoMain cru/ui) -target_link_libraries(CruDemoMain PRIVATE cru_demo_base CruUi) +target_link_libraries(CruDemoMain PRIVATE CruDemoBase CruUi) diff --git a/demos/scroll_view/CMakeLists.txt b/demos/scroll_view/CMakeLists.txt deleted file mode 100644 index 0b9196fe..00000000 --- a/demos/scroll_view/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable(CruDemoScrollView main.cpp) - -if(APPLE) - set_target_properties(CruDemoScrollView PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-scroll-view - MACOSX_BUNDLE_BUNDLE_NAME demo-scroll-view - ) -endif() - -target_add_resources(CruDemoScrollView cru/ui) -target_link_libraries(CruDemoScrollView PRIVATE cru_demo_base CruUi) diff --git a/demos/scroll_view/main.cpp b/demos/scroll_view/main.cpp deleted file mode 100644 index b049a408..00000000 --- a/demos/scroll_view/main.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "cru/platform/bootstrap/Bootstrap.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/platform/gui/Window.h" -#include "cru/ui/controls/ScrollView.h" -#include "cru/ui/controls/TextBlock.h" -#include "cru/ui/controls/Window.h" - -using cru::platform::gui::IUiApplication; -using cru::ui::controls::ScrollView; -using cru::ui::controls::TextBlock; -using cru::ui::controls::Window; - -int main() { - std::unique_ptr application( - cru::platform::bootstrap::CreateUiApplication()); - - Window window; - ScrollView scroll_view; - window.AddChild(&scroll_view); - - TextBlock text_block( - uR"([Verse 1] -The snow glows white on the mountain tonight -Not a footprint to be seen -A kingdom of isolation -And it looks like I'm the queen -The wind is howling like this swirling storm inside -Couldn't keep it in, Heaven knows I tried - -[Pre-Chorus] -Don't let them in, don't let them see -Be the good girl you always have to be -Conceal, don't feel, don't let them know -Well, now they know - -[Chorus] -Let it go, let it go -Can't hold it back anymore -Let it go, let it go -Turn away and slam the door -I don't care what they're going to say -Let the storm rage on -The cold never bothered me anyway - -[Verse 2] -It's funny how some distance -Makes everything seem small -And the fears that once controlled me -Can't get to me at all - -[Pre-Chorus] -It's time to see what I can do -To test the limits and break through -No right, no wrong, no rules for me -I'm free - -[Chorus] -Let it go, let it go -I'm one with the wind and sky -Let it go, let it go -You'll never see me cry -Here I stand, and here I'll stay -Let the storm rage on... - -[Bridge] -My power flurries through the air into the ground -My soul is spiraling in frozen fractals all around -And one thought crystallizes like an icy blast: -I'm never going back, the past is in the past! - -[Chorus] -Let it go, let it go -And I'll rise like the break of dawn -Let it go, let it go -That perfect girl is gone -Here I stand in the light of day -Let the storm rage on! -The cold never bothered me anyway)", - true); - - scroll_view.SetChild(&text_block); - - window.GetWindowHost()->GetNativeWindow()->SetVisibility( - cru::platform::gui::WindowVisibilityType::Show); - - return application->Run(); -} diff --git a/demos/svg_path/CMakeLists.txt b/demos/svg_path/CMakeLists.txt deleted file mode 100644 index 5488c6b0..00000000 --- a/demos/svg_path/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable(CruDemoSvgPath main.cpp) - -if(APPLE) - set_target_properties(CruDemoSvgPath PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_BUNDLE_NAME cru-demo-svg-path - MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.demo-svg-path - ) -endif() - -target_link_libraries(CruDemoSvgPath PRIVATE cru_demo_base) - diff --git a/demos/svg_path/main.cpp b/demos/svg_path/main.cpp deleted file mode 100644 index 87c410e9..00000000 --- a/demos/svg_path/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "cru/platform/Color.h" -#include "cru/platform/bootstrap/Bootstrap.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/graphics/Font.h" -#include "cru/platform/graphics/Painter.h" -#include "cru/platform/gui/InputMethod.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/platform/gui/Window.h" - -int main() { - using namespace cru; - using namespace cru::platform; - using namespace cru::platform::graphics; - using namespace cru::platform::gui; - - IUiApplication* application = bootstrap::CreateUiApplication(); - - auto graphics_factory = application->GetGraphicsFactory(); - - auto window = application->CreateWindow(); - - auto brush = graphics_factory->CreateSolidColorBrush(colors::black); - - auto create_geometry = [graphics_factory](StringView path_d) { - auto geometry_builder = graphics_factory->CreateGeometryBuilder(); - geometry_builder->ParseAndApplySvgPathData(path_d); - return geometry_builder->Build(); - }; - - auto geometry = create_geometry( - uR"( -M8.5 5.5a.5.5 0 0 0-1 0v3.362l-1.429 2.38a.5.5 0 1 0 .858.515l1.5-2.5A.5.5 0 0 0 8.5 9V5.5z -M6.5 0a.5.5 0 0 0 0 1H7v1.07a7.001 7.001 0 0 0-3.273 12.474l-.602.602a.5.5 0 0 0 .707.708l.746-.746A6.97 6.97 0 0 0 8 16a6.97 6.97 0 0 0 3.422-.892l.746.746a.5.5 0 0 0 .707-.708l-.601-.602A7.001 7.001 0 0 0 9 2.07V1h.5a.5.5 0 0 0 0-1h-3zm1.038 3.018a6.093 6.093 0 0 1 .924 0 6 6 0 1 1-.924 0zM0 3.5c0 .753.333 1.429.86 1.887A8.035 8.035 0 0 1 4.387 1.86 2.5 2.5 0 0 0 0 3.5zM13.5 1c-.753 0-1.429.333-1.887.86a8.035 8.035 0 0 1 3.527 3.527A2.5 2.5 0 0 0 13.5 1z - )"); - - window->PaintEvent()->AddHandler([&](auto) { - auto painter = window->BeginPaint(); - painter->PushState(); - painter->ConcatTransform(Matrix::Scale(10, 10)); - painter->FillGeometry(geometry.get(), brush.get()); - painter->PopState(); - painter->EndDraw(); - }); - - window->SetVisibility(WindowVisibilityType::Show); - - return application->Run(); -} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3fdbff2..9cb01e47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,4 +7,4 @@ add_subdirectory(parse) add_subdirectory(toml) add_subdirectory(xml) -add_subdirectory(theme_builder) +add_subdirectory(ThemeBuilder) diff --git a/src/ThemeBuilder/CMakeLists.txt b/src/ThemeBuilder/CMakeLists.txt new file mode 100644 index 00000000..93b24e85 --- /dev/null +++ b/src/ThemeBuilder/CMakeLists.txt @@ -0,0 +1,45 @@ +add_executable(CruThemeBuilder + main.cpp + components/Common.cpp + components/Editor.cpp + components/HeadBodyEditor.cpp + components/MainWindow.cpp + components/StyleRuleEditor.cpp + components/StyleRuleSetEditor.cpp + components/conditions/CheckedConditionEditor.cpp + components/conditions/ClickStateConditionEditor.cpp + components/conditions/CompoundConditionEditor.cpp + components/conditions/ConditionEditor.cpp + components/conditions/FocusConditionEditor.cpp + components/conditions/NoConditionEditor.cpp + components/properties/CheckBoxPropertyEditor.cpp + components/properties/ColorPropertyEditor.cpp + components/properties/CornerRadiusPropertyEditor.cpp + components/properties/FontPropertyEditor.cpp + components/properties/MeasureLengthPropertyEditor.cpp + components/properties/PointPropertyEditor.cpp + components/properties/SelectPropertyEditor.cpp + components/properties/TextPropertyEditor.cpp + components/properties/ThicknessPropertyEditor.cpp + components/stylers/BorderStylerEditor.cpp + components/stylers/CompoundStylerEditor.cpp + components/stylers/ContentBrushStylerEditor.cpp + components/stylers/CursorStylerEditor.cpp + components/stylers/FontStylerEditor.cpp + components/stylers/MarginStylerEditor.cpp + components/stylers/PaddingStylerEditor.cpp + components/stylers/PreferredSizeStylerEditor.cpp + components/stylers/StylerEditor.cpp +) + +if(APPLE) + set_target_properties(CruThemeBuilder PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_BUNDLE_NAME cru-theme-builder + MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.theme-builder + ) +endif() + +target_add_resources(CruThemeBuilder cru/ui) +target_add_resources(CruThemeBuilder cru/theme_builder) +target_link_libraries(CruThemeBuilder PRIVATE CruPlatformBootstrap CruUi) diff --git a/src/ThemeBuilder/components/Common.cpp b/src/ThemeBuilder/components/Common.cpp new file mode 100644 index 00000000..75d5deb0 --- /dev/null +++ b/src/ThemeBuilder/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 + +namespace cru::theme_builder::components { +std::unique_ptr +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/ThemeBuilder/components/Common.h b/src/ThemeBuilder/components/Common.h new file mode 100644 index 00000000..b91fcf88 --- /dev/null +++ b/src/ThemeBuilder/components/Common.h @@ -0,0 +1,7 @@ +#pragma once +#include "cru/platform/graphics/Brush.h" + +namespace cru::theme_builder::components { +std::unique_ptr +CreateRandomEditorBackgroundBrush(); +} diff --git a/src/ThemeBuilder/components/Editor.cpp b/src/ThemeBuilder/components/Editor.cpp new file mode 100644 index 00000000..89e27e83 --- /dev/null +++ b/src/ThemeBuilder/components/Editor.cpp @@ -0,0 +1,23 @@ +#include "Editor.h" + +namespace cru::theme_builder::components { + +void Editor::RaiseChangeEvent() { + if (suppress_next_change_event_) { + suppress_next_change_event_ = false; + } else { + change_event_.Raise(nullptr); + } +} + +void Editor::SuppressNextChangeEvent() { suppress_next_change_event_ = true; } + +void Editor::ConnectChangeEvent(IEvent* event) { + event->AddHandler([this](std::nullptr_t) { RaiseChangeEvent(); }); +} + +void Editor::ConnectChangeEvent(Editor* editor) { + ConnectChangeEvent(editor->ChangeEvent()); +} + +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/Editor.h b/src/ThemeBuilder/components/Editor.h new file mode 100644 index 00000000..29809c82 --- /dev/null +++ b/src/ThemeBuilder/components/Editor.h @@ -0,0 +1,25 @@ +#pragma once +#include "cru/common/Event.h" +#include "cru/ui/components/Component.h" + +namespace cru::theme_builder::components { +class Editor : public ui::components::Component { + public: + Editor() = default; + ~Editor() override = default; + + public: + IEvent* ChangeEvent() { return &change_event_; } + + protected: + void RaiseChangeEvent(); + void SuppressNextChangeEvent(); + void ConnectChangeEvent(IEvent* event); + void ConnectChangeEvent(Editor* editor); + void ConnectChangeEvent(Editor& editor) { ConnectChangeEvent(&editor); } + + private: + bool suppress_next_change_event_ = false; + Event change_event_; +}; +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/HeadBodyEditor.cpp b/src/ThemeBuilder/components/HeadBodyEditor.cpp new file mode 100644 index 00000000..6d7ace66 --- /dev/null +++ b/src/ThemeBuilder/components/HeadBodyEditor.cpp @@ -0,0 +1,30 @@ +#include "HeadBodyEditor.h" +#include "Common.h" +#include "cru/ui/ThemeManager.h" +#include "cru/ui/controls/FlexLayout.h" + +namespace cru::theme_builder::components { +HeadBodyEditor::HeadBodyEditor() { + border_.SetChild(&container_); + border_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush()); + + container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + container_.AddChild(&head_container_); + container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Stretch); + head_container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); + head_container_.AddChild(&label_); + + remove_button_.GetStyleRuleSet()->SetParent( + ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( + u"cru.theme_builder.icon-button.style")); + remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close", + {0, 0, 16, 16}); + remove_button_.SetIconFillColor(ui::colors::red); + head_container_.AddChild(&remove_button_); + + remove_button_.ClickEvent()->AddSpyOnlyHandler( + [this] { remove_event_.Raise(nullptr); }); +} + +HeadBodyEditor::~HeadBodyEditor() {} +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/HeadBodyEditor.h b/src/ThemeBuilder/components/HeadBodyEditor.h new file mode 100644 index 00000000..8119724f --- /dev/null +++ b/src/ThemeBuilder/components/HeadBodyEditor.h @@ -0,0 +1,36 @@ +#pragma once +#include "Editor.h" +#include "cru/common/Event.h" +#include "cru/ui/controls/Container.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/IconButton.h" +#include "cru/ui/controls/TextBlock.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components { +class HeadBodyEditor : public Editor { + public: + HeadBodyEditor(); + ~HeadBodyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &border_; } + + ui::controls::FlexLayout* GetContainer() { return &container_; } + ui::controls::FlexLayout* GetHeadContainer() { return &head_container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + IEvent* RemoveEvent() { return &remove_event_; } + + private: + ui::controls::Container border_; + ui::controls::FlexLayout container_; + ui::controls::FlexLayout head_container_; + ui::controls::TextBlock label_; + ui::controls::IconButton remove_button_; + + Event remove_event_; +}; +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/MainWindow.cpp b/src/ThemeBuilder/components/MainWindow.cpp new file mode 100644 index 00000000..0c78ef25 --- /dev/null +++ b/src/ThemeBuilder/components/MainWindow.cpp @@ -0,0 +1,37 @@ +#include "MainWindow.h" +#include "cru/ui/Base.h" +#include "cru/ui/controls/StackLayout.h" +#include "cru/ui/controls/TextBlock.h" + +namespace cru::theme_builder::components { +using namespace cru::ui; +using namespace cru::ui::controls; +using namespace cru::platform::gui; + +MainWindow::MainWindow() { + window_.GetNativeWindow()->SetTitle(u"CruUI Theme Builder"); + main_layout_.SetFlexDirection(FlexDirection::Horizontal); + window_.AddChild(&main_layout_); + main_layout_.AddChild(&preview_layout_); + + preview_button_text_.SetText(u"Preview"); + preview_button_.SetChild(&preview_button_text_); + preview_layout_.AddChild(&preview_button_); + preview_layout_.SetChildLayoutData( + 0, StackChildLayoutData{Alignment::Center, Alignment::Center}); + + style_rule_set_editor_.BindStyleRuleSet( + preview_button_.GetStyleRuleSet()->GetParent()); + main_layout_.AddChild(style_rule_set_editor_.GetRootControl()); + + main_layout_.SetChildLayoutData(0, {1, 0}); + main_layout_.SetChildLayoutData(1, {0, 1}); +} + +MainWindow::~MainWindow() {} + +void MainWindow::Show() { + window_.GetNativeWindow()->SetVisibility(WindowVisibilityType::Show); + window_.GetNativeWindow()->SetToForeground(); +} +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/MainWindow.h b/src/ThemeBuilder/components/MainWindow.h new file mode 100644 index 00000000..ede1c38f --- /dev/null +++ b/src/ThemeBuilder/components/MainWindow.h @@ -0,0 +1,32 @@ +#pragma once +#include "StyleRuleSetEditor.h" +#include "cru/ui/components/Component.h" +#include "cru/ui/controls/Button.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/StackLayout.h" +#include "cru/ui/controls/TextBlock.h" +#include "cru/ui/controls/Window.h" + +namespace cru::theme_builder::components { +class MainWindow : public ui::components::Component { + public: + MainWindow(); + + CRU_DELETE_COPY(MainWindow) + CRU_DELETE_MOVE(MainWindow) + + ~MainWindow() override; + + ui::controls::Control* GetRootControl() override { return &window_; } + + void Show(); + + private: + ui::controls::Window window_; + ui::controls::FlexLayout main_layout_; + ui::controls::StackLayout preview_layout_; + ui::controls::Button preview_button_; + ui::controls::TextBlock preview_button_text_; + StyleRuleSetEditor style_rule_set_editor_; +}; +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/StyleRuleEditor.cpp b/src/ThemeBuilder/components/StyleRuleEditor.cpp new file mode 100644 index 00000000..dcb33184 --- /dev/null +++ b/src/ThemeBuilder/components/StyleRuleEditor.cpp @@ -0,0 +1,62 @@ +#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::components { +StyleRuleEditor::StyleRuleEditor() { + container_.SetChild(&main_layout_); + container_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush()); + + main_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + main_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); + + main_layout_.AddChild(&head_layout_); + + label_.SetText(u"Style Rule"); + head_layout_.AddChild(&label_); + head_layout_.AddChild(&remove_button_); + + remove_button_.GetStyleRuleSet()->SetParent( + ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( + u"cru.theme_builder.icon-button.style")); + remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close", + {0, 0, 16, 16}); + remove_button_.SetIconFillColor(ui::colors::red); + + main_layout_.AddChild(&body_layout_); + body_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + body_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); + body_layout_.SetMargin({10, 0, 0, 0}); + + remove_button_.ClickEvent()->AddSpyOnlyHandler( + [this] { remove_event_.Raise(nullptr); }); +} + +StyleRuleEditor::~StyleRuleEditor() {} + +ui::style::StyleRule StyleRuleEditor::GetValue() const { + return ui::style::StyleRule(condition_editor_->GetCondition(), + styler_editor_->GetStyler()); +} + +void StyleRuleEditor::SetValue(const ui::style::StyleRule& style_rule, + bool trigger_change) { + body_layout_.ClearChildren(); + condition_editor_ = + components::conditions::CreateConditionEditor(style_rule.GetCondition()); + styler_editor_ = + components::stylers::CreateStylerEditor(style_rule.GetStyler()); + body_layout_.AddChild(condition_editor_->GetRootControl()); + body_layout_.AddChild(styler_editor_->GetRootControl()); + condition_editor_->ChangeEvent()->AddSpyOnlyHandler( + [this] { change_event_.Raise(nullptr); }); + styler_editor_->ChangeEvent()->AddSpyOnlyHandler( + [this] { change_event_.Raise(nullptr); }); + + if (trigger_change) { + change_event_.Raise(nullptr); + } +} +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/StyleRuleEditor.h b/src/ThemeBuilder/components/StyleRuleEditor.h new file mode 100644 index 00000000..8e3db3de --- /dev/null +++ b/src/ThemeBuilder/components/StyleRuleEditor.h @@ -0,0 +1,45 @@ +#pragma once +#include "conditions/ConditionEditor.h" +#include "cru/ui/components/Component.h" +#include "cru/ui/controls/Button.h" +#include "cru/ui/controls/Control.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/IconButton.h" +#include "cru/ui/controls/TextBlock.h" +#include "cru/ui/style/StyleRule.h" +#include "stylers/StylerEditor.h" + +namespace cru::theme_builder::components { +class StyleRuleEditor : public ui::components::Component { + public: + StyleRuleEditor(); + + CRU_DELETE_COPY(StyleRuleEditor) + CRU_DELETE_MOVE(StyleRuleEditor) + + ~StyleRuleEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + ui::style::StyleRule GetValue() const; + void SetValue(const ui::style::StyleRule& style_rule, + bool trigger_change = true); + + IEvent* ChangeEvent() { return &change_event_; } + IEvent* RemoveEvent() { return &remove_event_; } + + private: + ui::controls::Container container_; + ui::controls::FlexLayout main_layout_; + ui::controls::TextBlock label_; + ui::controls::FlexLayout head_layout_; + ui::controls::IconButton remove_button_; + ui::controls::FlexLayout body_layout_; + std::unique_ptr condition_editor_; + std::unique_ptr styler_editor_; + + Event change_event_; + Event remove_event_; +}; +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp new file mode 100644 index 00000000..8cf5af6d --- /dev/null +++ b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp @@ -0,0 +1,123 @@ +#include "StyleRuleSetEditor.h" +#include "cru/common/Exception.h" +#include "cru/common/String.h" +#include "cru/ui/DeleteLater.h" +#include "cru/ui/ThemeManager.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/model/IListChangeNotify.h" +#include "cru/ui/render/FlexLayoutRenderObject.h" +#include "cru/ui/style/Condition.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components { +using namespace cru::ui::controls; +StyleRuleSetEditor::StyleRuleSetEditor() { + scroll_view_.SetChild(&container_); + + container_.SetFlexDirection(ui::render::FlexDirection::Vertical); + container_.AddChild(&rules_layout_); + container_.AddChild(&add_button_); + + rules_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + rules_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Stretch); + + add_button_.GetStyleRuleSet()->SetParent( + ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( + u"cru.theme_builder.icon-button.style")); + add_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.plus", + {0, 0, 16, 16}); + add_button_.SetPreferredSize({24, 24}); + add_button_.SetPadding(ui::Thickness(2)); + add_button_.SetIconFillColor(ui::colors::green); + + add_button_.ClickEvent()->AddSpyOnlyHandler([this] { + auto rule_set = ui::style::StyleRule(ui::style::NoCondition::Create(), + ui::style::CompoundStyler::Create({})); + style_rule_set_->AddStyleRule(rule_set); + }); +} + +StyleRuleSetEditor::~StyleRuleSetEditor() {} + +void StyleRuleSetEditor::BindStyleRuleSet( + std::shared_ptr rule_set) { + Expects(style_rule_set_ == nullptr && rule_set); + style_rule_set_ = std::move(rule_set); + UpdateView(style_rule_set_.get()); + style_rule_set_->ListChangeEvent()->AddHandler( + [this](const ui::model::ListChange& change) { + UpdateView(style_rule_set_.get(), change); + }); +} + +Index StyleRuleSetEditor::IndexOfRuleEditor(StyleRuleEditor* editor) { + auto iter = + std::find_if(style_rule_editors_.cbegin(), style_rule_editors_.cend(), + [editor](const ui::DeleteLaterPtr& p) { + return p.get() == editor; + }); + return iter - style_rule_editors_.cbegin(); +} + +void StyleRuleSetEditor::UpdateView( + ui::style::StyleRuleSet* style_rule_set, + std::optional change) { + if (change) { + switch (change->type) { + case ui::model::ListChangeType::kItemAdd: { + for (auto i = change->position; i < change->position + change->count; + ++i) { + const auto& rule = style_rule_set->GetStyleRule(i); + auto style_rule_editor = ui::MakeDeleteLaterPtr(); + style_rule_editor->SetValue(rule, false); + style_rule_editor->RemoveEvent()->AddSpyOnlyHandler( + [this, editor = style_rule_editor.get()] { + style_rule_set_->RemoveStyleRule(IndexOfRuleEditor(editor)); + }); + style_rule_editor->ChangeEvent()->AddSpyOnlyHandler( + [this, editor = style_rule_editor.get()]() { + suppress_next_set_ = true; + style_rule_set_->SetStyleRule(IndexOfRuleEditor(editor), + editor->GetValue()); + }); + style_rule_editors_.insert(style_rule_editors_.cbegin() + i, + std::move(style_rule_editor)); + rules_layout_.AddChildAt(style_rule_editors_.back()->GetRootControl(), + i); + } + break; + } + case ui::model::ListChangeType::kItemRemove: { + for (auto i = change->position; i < change->position + change->count; + ++i) { + style_rule_editors_.erase(style_rule_editors_.begin() + i); + } + break; + } + case ui::model::ListChangeType::kItemSet: { + if (suppress_next_set_) { + suppress_next_set_ = false; + break; + } + for (auto i = change->position; i < change->position + change->count; + ++i) { + const auto& rule = style_rule_set->GetStyleRule(i); + style_rule_editors_[i]->SetValue(rule, false); + } + break; + } + case ui::model::ListChangeType::kItemMove: { + throw Exception(u"Not supported now!"); + break; + } + case ui::model::ListChangeType::kClear: { + style_rule_editors_.clear(); + } + } + } else { + UpdateView(style_rule_set, ui::model::ListChange::Clear()); + UpdateView(style_rule_set, + ui::model::ListChange::ItemAdd(0, style_rule_set->GetSize())); + } +} +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/StyleRuleSetEditor.h b/src/ThemeBuilder/components/StyleRuleSetEditor.h new file mode 100644 index 00000000..03148889 --- /dev/null +++ b/src/ThemeBuilder/components/StyleRuleSetEditor.h @@ -0,0 +1,44 @@ +#pragma once +#include "StyleRuleEditor.h" +#include "cru/ui/DeleteLater.h" +#include "cru/ui/components/Component.h" +#include "cru/ui/controls/Button.h" +#include "cru/ui/controls/Control.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/ScrollView.h" +#include "cru/ui/model/IListChangeNotify.h" +#include "cru/ui/style/StyleRuleSet.h" + +namespace cru::theme_builder::components { +class StyleRuleSetEditor : public ui::components::Component { + public: + StyleRuleSetEditor(); + + CRU_DELETE_COPY(StyleRuleSetEditor) + CRU_DELETE_MOVE(StyleRuleSetEditor) + + ~StyleRuleSetEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &scroll_view_; } + + void BindStyleRuleSet(std::shared_ptr rule_set); + + private: + Index IndexOfRuleEditor(StyleRuleEditor* editor); + + void UpdateView(ui::style::StyleRuleSet* style_rule_set, + std::optional change = std::nullopt); + + private: + std::shared_ptr style_rule_set_; + + ui::controls::ScrollView scroll_view_; + ui::controls::FlexLayout container_; + ui::controls::FlexLayout rules_layout_; + std::vector> style_rule_editors_; + ui::controls::IconButton add_button_; + + bool suppress_next_set_ = false; +}; +} // namespace cru::theme_builder::components diff --git a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp new file mode 100644 index 00000000..64370981 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp @@ -0,0 +1,26 @@ +#include "CheckedConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +CheckedConditionEditor::CheckedConditionEditor() { + SetLabel(u"Checked Condition"); + + checked_check_box_.SetLabel(u"Checked"); + GetContainer()->AddChild(checked_check_box_.GetRootControl()); + + ConnectChangeEvent(checked_check_box_); +} + +CheckedConditionEditor::~CheckedConditionEditor() {} + +ClonablePtr CheckedConditionEditor::GetValue() + const { + return ui::style::CheckedCondition::Create(checked_check_box_.GetValue()); +} + +void CheckedConditionEditor::SetValue(ui::style::CheckedCondition* value, + bool trigger_change) { + checked_check_box_.SetValue(value->IsChecked(), trigger_change); +} +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.h b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.h new file mode 100644 index 00000000..7cf14912 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.h @@ -0,0 +1,28 @@ +#pragma once +#include "../properties/CheckBoxPropertyEditor.h" +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class CheckedConditionEditor : public ConditionEditor { + public: + CheckedConditionEditor(); + ~CheckedConditionEditor() override; + + public: + ClonablePtr GetValue() const; + void SetValue(ui::style::CheckedCondition* value, bool trigger_change = true); + void SetValue(const ClonablePtr& value, + bool trigger_change = true) { + SetValue(value.get(), trigger_change); + } + + ClonablePtr GetCondition() override { + return GetValue(); + } + + private: + properties::CheckBoxPropertyEditor checked_check_box_; +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp new file mode 100644 index 00000000..a8d5cc87 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp @@ -0,0 +1,69 @@ +#include "ClickStateConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/helper/ClickDetector.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +using ui::helper::ClickState; +namespace { +const std::vector kClickStates{ + u"None", + u"Hover", + u"Press", + u"PressInactive", +}; + +Index ConvertClickStateToIndex(ClickState click_state) { + switch (click_state) { + case ClickState::None: + return 0; + case ClickState::Hover: + return 1; + case ClickState::Press: + return 2; + case ClickState::PressInactive: + return 3; + } + return -1; +} + +ClickState ConvertIndexToClickState(Index index) { + switch (index) { + case 0: + return ClickState::None; + case 1: + return ClickState::Hover; + case 2: + return ClickState::Press; + case 3: + return ClickState::PressInactive; + } + return ClickState::None; +} +} // namespace + +ClickStateConditionEditor::ClickStateConditionEditor() { + SetLabel(u"Click State Condition"); + GetContainer()->AddChild(click_state_select_.GetRootControl()); + + click_state_select_.SetLabel(u"Click State"); + click_state_select_.SetItems(kClickStates); + click_state_select_.SetSelectedIndex(0, false); + + ConnectChangeEvent(click_state_select_); +} + +ClickStateConditionEditor::~ClickStateConditionEditor() {} + +ClonablePtr +ClickStateConditionEditor::GetValue() const { + return ui::style::ClickStateCondition::Create( + ConvertIndexToClickState(click_state_select_.GetSelectedIndex())); +} + +void ClickStateConditionEditor::SetValue(ui::style::ClickStateCondition* value, + bool trigger_change) { + click_state_select_.SetSelectedIndex( + ConvertClickStateToIndex(value->GetClickState()), trigger_change); +} +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h new file mode 100644 index 00000000..454a1346 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.h @@ -0,0 +1,30 @@ +#pragma once +#include "../properties/SelectPropertyEditor.h" +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/common/Event.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class ClickStateConditionEditor : public ConditionEditor { + public: + ClickStateConditionEditor(); + ~ClickStateConditionEditor(); + + public: + ClonablePtr GetValue() const; + void SetValue(ui::style::ClickStateCondition* value, + bool trigger_change = true); + void SetValue(const ClonablePtr& value, + bool trigger_change = true) { + SetValue(value.get(), trigger_change); + } + + ClonablePtr GetCondition() override { + return GetValue(); + } + + private: + properties::SelectPropertyEditor click_state_select_; +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp new file mode 100644 index 00000000..69b8ed02 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp @@ -0,0 +1,109 @@ +#include "CompoundConditionEditor.h" +#include "CheckedConditionEditor.h" +#include "ClickStateConditionEditor.h" +#include "ConditionEditor.h" +#include "FocusConditionEditor.h" +#include "NoConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/platform/Color.h" +#include "cru/ui/Base.h" +#include "cru/ui/ThemeManager.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { + +CompoundConditionEditor::CompoundConditionEditor() { + SetLabel(u"Compound Condition"); + + GetContainer()->AddChild(&children_container_); + children_container_.SetMargin({10, 0, 0, 0}); + children_container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + children_container_.SetItemCrossAlign( + ui::controls::FlexCrossAlignment::Start); + + GetHeadContainer()->AddChild(add_child_button_.GetRootControl()); + + add_child_button_.GetButton()->GetStyleRuleSet()->SetParent( + ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( + u"cru.theme_builder.icon-button.style")); + add_child_button_.GetButton()->SetIconWithSvgPathDataStringResourceKey( + u"icon.plus", {0, 0, 16, 16}); + add_child_button_.GetButton()->SetPreferredSize({24, 24}); + add_child_button_.GetButton()->SetPadding(ui::Thickness(2)); + add_child_button_.GetButton()->SetIconFillColor(ui::colors::green); + add_child_button_.SetMenuItems({u"And Condition", u"Or Condition", + u"Click State Condition", u"Focus Condition", + u"Checked Condition", u"No Condition"}); + add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) { + std::unique_ptr editor; + switch (index) { + case 0: + editor = std::make_unique(); + break; + case 1: + editor = std::make_unique(); + break; + case 2: + editor = std::make_unique(); + break; + case 3: + editor = std::make_unique(); + break; + case 4: + editor = std::make_unique(); + break; + case 5: + editor = std::make_unique(); + break; + default: + break; + } + if (editor) { + ConnectChangeEvent(editor.get()); + editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { + auto index = this->children_container_.IndexOf(c->GetRootControl()); + this->children_.erase(this->children_.begin() + index); + this->children_container_.RemoveChildAt(index); + RaiseChangeEvent(); + }); + children_.push_back(std::move(editor)); + children_container_.AddChild(children_.back()->GetRootControl()); + RaiseChangeEvent(); + } + }); +} + +CompoundConditionEditor::~CompoundConditionEditor() {} + +std::vector> +CompoundConditionEditor::GetChildren() { + std::vector> children; + for (auto& child : children_) { + children.push_back(child->GetCondition()); + } + return children; +} + +void CompoundConditionEditor::SetChildren( + std::vector> children, + bool trigger_change) { + children_container_.ClearChildren(); + children_.clear(); + for (const auto& condition : children) { + auto editor = CreateConditionEditor(condition.get()); + ConnectChangeEvent(editor.get()); + editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { + auto index = this->children_container_.IndexOf(c->GetRootControl()); + this->children_.erase(this->children_.begin() + index); + this->children_container_.RemoveChildAt(index); + RaiseChangeEvent(); + }); + children_.push_back(std::move(editor)); + children_container_.AddChild(children_.back()->GetRootControl()); + } + if (trigger_change) { + RaiseChangeEvent(); + } +} +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.h b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.h new file mode 100644 index 00000000..e1398514 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.h @@ -0,0 +1,72 @@ +#pragma once +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/common/Event.h" +#include "cru/ui/components/Component.h" +#include "cru/ui/components/PopupButton.h" +#include "cru/ui/controls/Button.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class CompoundConditionEditor : public ConditionEditor { + public: + CompoundConditionEditor(); + ~CompoundConditionEditor(); + + protected: + std::vector> GetChildren(); + void SetChildren(std::vector> children, + bool trigger_change = true); + + private: + ui::components::PopupMenuIconButton add_child_button_; + ui::controls::FlexLayout children_container_; + std::vector> children_; +}; + +class AndConditionEditor : public CompoundConditionEditor { + public: + AndConditionEditor() = default; + ~AndConditionEditor() override = default; + + public: + ClonablePtr GetValue() { + return ui::style::AndCondition::Create(GetChildren()); + } + void SetValue(ui::style::AndCondition* value, bool trigger_change = true) { + SetChildren(value->GetChildren(), trigger_change); + } + void SetValue(const ClonablePtr& value, + bool trigger_change = true) { + SetValue(value.get(), trigger_change); + } + + ClonablePtr GetCondition() override { + return GetValue(); + } +}; + +class OrConditionEditor : public CompoundConditionEditor { + public: + OrConditionEditor() = default; + ~OrConditionEditor() override = default; + + public: + ClonablePtr GetValue() { + return ui::style::OrCondition::Create(GetChildren()); + } + void SetValue(ui::style::OrCondition* value, bool trigger_change = true) { + SetChildren(value->GetChildren(), trigger_change); + } + void SetValue(const ClonablePtr& value, + bool trigger_change = true) { + SetValue(value.get(), trigger_change); + } + + ClonablePtr GetCondition() override { + return GetValue(); + } +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/ConditionEditor.cpp b/src/ThemeBuilder/components/conditions/ConditionEditor.cpp new file mode 100644 index 00000000..5b79c639 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/ConditionEditor.cpp @@ -0,0 +1,50 @@ +#include "ConditionEditor.h" +#include "../Common.h" +#include "CheckedConditionEditor.h" +#include "ClickStateConditionEditor.h" +#include "CompoundConditionEditor.h" +#include "FocusConditionEditor.h" +#include "NoConditionEditor.h" +#include "cru/common/Exception.h" +#include "cru/ui/controls/FlexLayout.h" + +namespace cru::theme_builder::components::conditions { +ConditionEditor::ConditionEditor() {} + +ConditionEditor::~ConditionEditor() {} + +std::unique_ptr CreateConditionEditor( + ui::style::Condition* condition) { + if (auto and_condition = dynamic_cast(condition)) { + auto result = std::make_unique(); + result->SetValue(and_condition); + return result; + } else if (auto or_condition = + dynamic_cast(condition)) { + auto result = std::make_unique(); + result->SetValue(or_condition); + return result; + } else if (auto no_condition = + dynamic_cast(condition)) { + auto result = std::make_unique(); + return result; + } else if (auto click_state_condition = + dynamic_cast(condition)) { + auto result = std::make_unique(); + result->SetValue(click_state_condition); + return result; + } else if (auto focus_condition = + dynamic_cast(condition)) { + auto result = std::make_unique(); + result->SetValue(focus_condition); + return result; + } else if (auto checked_condition = + dynamic_cast(condition)) { + auto result = std::make_unique(); + result->SetValue(checked_condition); + return result; + } else { + throw Exception(u"Unknown condition type"); + } +} +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/ConditionEditor.h b/src/ThemeBuilder/components/conditions/ConditionEditor.h new file mode 100644 index 00000000..f20132f6 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/ConditionEditor.h @@ -0,0 +1,17 @@ +#pragma once +#include "../HeadBodyEditor.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class ConditionEditor : public HeadBodyEditor { + public: + ConditionEditor(); + ~ConditionEditor() override; + + public: + virtual ClonablePtr GetCondition() = 0; +}; + +std::unique_ptr CreateConditionEditor( + ui::style::Condition* condition); +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp b/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp new file mode 100644 index 00000000..1fb99d64 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp @@ -0,0 +1,25 @@ +#include "FocusConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +FocusConditionEditor::FocusConditionEditor() { + SetLabel(u"Focus Condition"); + GetContainer()->AddChild(focus_check_box_.GetRootControl()); + + focus_check_box_.SetLabel(u"Focus"); + + ConnectChangeEvent(focus_check_box_); +} + +FocusConditionEditor::~FocusConditionEditor() {} + +ClonablePtr FocusConditionEditor::GetValue() const { + return ui::style::FocusCondition::Create(focus_check_box_.GetValue()); +} + +void FocusConditionEditor::SetValue(ui::style::FocusCondition* value, + bool trigger_change) { + focus_check_box_.SetValue(value->IsHasFocus(), trigger_change); +} +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/FocusConditionEditor.h b/src/ThemeBuilder/components/conditions/FocusConditionEditor.h new file mode 100644 index 00000000..1faf4d7d --- /dev/null +++ b/src/ThemeBuilder/components/conditions/FocusConditionEditor.h @@ -0,0 +1,28 @@ +#pragma once +#include "../properties/CheckBoxPropertyEditor.h" +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class FocusConditionEditor : public ConditionEditor { + public: + FocusConditionEditor(); + ~FocusConditionEditor() override; + + public: + ClonablePtr GetValue() const; + void SetValue(ui::style::FocusCondition* value, bool trigger_change = true); + void SetValue(const ClonablePtr& value, + bool trigger_change = true) { + SetValue(value.get(), trigger_change); + } + + ClonablePtr GetCondition() override { + return GetValue(); + } + + private: + properties::CheckBoxPropertyEditor focus_check_box_; +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/NoConditionEditor.cpp b/src/ThemeBuilder/components/conditions/NoConditionEditor.cpp new file mode 100644 index 00000000..a5087159 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/NoConditionEditor.cpp @@ -0,0 +1,7 @@ +#include "NoConditionEditor.h" + +namespace cru::theme_builder::components::conditions { +NoConditionEditor::NoConditionEditor() { SetLabel(u"No condition"); } + +NoConditionEditor::~NoConditionEditor() {} +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/conditions/NoConditionEditor.h b/src/ThemeBuilder/components/conditions/NoConditionEditor.h new file mode 100644 index 00000000..19616319 --- /dev/null +++ b/src/ThemeBuilder/components/conditions/NoConditionEditor.h @@ -0,0 +1,17 @@ +#pragma once +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class NoConditionEditor : public ConditionEditor { + public: + NoConditionEditor(); + ~NoConditionEditor() override; + + public: + ClonablePtr GetCondition() override { + return ui::style::NoCondition::Create(); + } +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.cpp b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.cpp new file mode 100644 index 00000000..fb6f4705 --- /dev/null +++ b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.cpp @@ -0,0 +1,19 @@ +#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] { RaiseChangeEvent(); }); +} + +CheckBoxPropertyEditor::~CheckBoxPropertyEditor() {} + +void CheckBoxPropertyEditor::SetValue(bool value, bool trigger_change) { + if (!trigger_change) SuppressNextChangeEvent(); + check_box_.SetChecked(value); +} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h new file mode 100644 index 00000000..f78ed6c9 --- /dev/null +++ b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h @@ -0,0 +1,29 @@ +#pragma once +#include "../Editor.h" +#include "cru/ui/controls/CheckBox.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" + +namespace cru::theme_builder::components::properties { +class CheckBoxPropertyEditor : public Editor { + 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); + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::CheckBox check_box_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp new file mode 100644 index 00000000..e9e486ac --- /dev/null +++ b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp @@ -0,0 +1,48 @@ +#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() { + container_.AddChild(&label_); + 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()); + color_text_.SetMargin(ui::Thickness(10, 0, 0, 0)); + + color_text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text = color_text_.GetTextView(); + auto color = ui::Color::Parse(text); + if (color) { + color_ = *color; + color_cube_brush_->SetColor(*color); + is_color_text_valid_ = true; + RaiseChangeEvent(); + } else { + is_color_text_valid_ = false; + // TODO: Show error! + } + }); +} + +ColorPropertyEditor::~ColorPropertyEditor() {} + +void ColorPropertyEditor::SetValue(const ui::Color &color, + bool trigger_change) { + if (!trigger_change) SuppressNextChangeEvent(); + color_text_.SetText(color.ToString()); +} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/ColorPropertyEditor.h b/src/ThemeBuilder/components/properties/ColorPropertyEditor.h new file mode 100644 index 00000000..aa6cfcfa --- /dev/null +++ b/src/ThemeBuilder/components/properties/ColorPropertyEditor.h @@ -0,0 +1,36 @@ +#pragma once +#include "../Editor.h" +#include "cru/platform/graphics/Base.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 Editor { + public: + using PropertyType = ui::Color; + + ColorPropertyEditor(); + ~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)); } + + ui::Color GetValue() const { return color_; } + void SetValue(const ui::Color& color, bool trigger_change = true); + + private: + ui::Color color_ = ui::colors::transparent; + + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::Container color_cube_; + std::shared_ptr color_cube_brush_; + ui::controls::TextBox color_text_; + bool is_color_text_valid_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp new file mode 100644 index 00000000..fc86b0ed --- /dev/null +++ b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp @@ -0,0 +1,42 @@ +#include "CornerRadiusPropertyEditor.h" +#include "cru/ui/Base.h" +#include "cru/ui/controls/FlexLayout.h" + +namespace cru::theme_builder::components::properties { +CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() { + container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); + + left_top_editor_.SetLabel(u"⌜"); + right_top_editor_.SetLabel(u"⌝"); + left_bottom_editor_.SetLabel(u"⌞"); + right_bottom_editor_.SetLabel(u"⌟"); + + container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + container_.AddChild(left_top_editor_.GetRootControl()); + container_.AddChild(right_top_editor_.GetRootControl()); + container_.AddChild(left_bottom_editor_.GetRootControl()); + container_.AddChild(right_bottom_editor_.GetRootControl()); + + 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) RaiseChangeEvent(); +} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h new file mode 100644 index 00000000..6b6833d1 --- /dev/null +++ b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.h @@ -0,0 +1,28 @@ +#pragma once +#include "../Editor.h" +#include "PointPropertyEditor.h" +#include "cru/ui/Base.h" +#include "cru/ui/controls/FlexLayout.h" + +namespace cru::theme_builder::components::properties { +class CornerRadiusPropertyEditor : public Editor { + public: + using PropertyType = ui::CornerRadius; + + CornerRadiusPropertyEditor(); + ~CornerRadiusPropertyEditor() override; + + ui::controls::Control* GetRootControl() override { return &container_; } + + ui::CornerRadius GetValue() const; + void SetValue(const ui::CornerRadius& corner_radius, + bool trigger_change = true); + + private: + ui::controls::FlexLayout container_; + PointPropertyEditor left_top_editor_; + PointPropertyEditor right_top_editor_; + PointPropertyEditor left_bottom_editor_; + PointPropertyEditor right_bottom_editor_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp b/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp new file mode 100644 index 00000000..927ada7d --- /dev/null +++ b/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp @@ -0,0 +1,60 @@ +#include "FontPropertyEditor.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/Font.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/render/FlexLayoutRenderObject.h" + +namespace cru::theme_builder::components::properties { +using namespace cru::ui::controls; + +FontPropertyEditor::FontPropertyEditor() { + main_container_.SetFlexDirection(FlexDirection::Horizontal); + main_container_.AddChild(&label_); + main_container_.AddChild(&right_container_); + + right_container_.SetFlexDirection(FlexDirection::Vertical); + right_container_.AddChild(&font_family_container_); + right_container_.AddChild(&font_size_container_); + + font_family_container_.SetFlexDirection(FlexDirection::Horizontal); + font_family_container_.AddChild(&font_family_label_); + font_family_container_.AddChild(&font_family_text_); + font_family_label_.SetText(u"Font Family"); + + font_size_container_.SetFlexDirection(FlexDirection::Horizontal); + font_size_container_.AddChild(&font_size_label_); + font_size_container_.AddChild(font_size_input_.GetRootControl()); + font_size_label_.SetText(u"Font Size"); + font_size_input_.SetMin(0.0f); + + font_family_text_.TextChangeEvent()->AddSpyOnlyHandler( + [this] { RaiseChangeEvent(); }); + + font_size_input_.ChangeEvent()->AddSpyOnlyHandler( + [this] { RaiseChangeEvent(); }); +} + +FontPropertyEditor::~FontPropertyEditor() {} + +Control* FontPropertyEditor::GetRootControl() { return &main_container_; } + +std::shared_ptr FontPropertyEditor::GetValue() + const { + return platform::gui::IUiApplication::GetInstance() + ->GetGraphicsFactory() + ->CreateFont(font_family_text_.GetText(), font_size_input_.GetValue()); +} + +void FontPropertyEditor::SetValue( + std::shared_ptr value, bool trigger_change) { + SuppressNextChangeEvent(); + font_family_text_.SetText(value->GetFontName()); + SuppressNextChangeEvent(); + font_size_input_.SetValue(value->GetFontSize()); + + if (trigger_change) { + RaiseChangeEvent(); + } +} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/FontPropertyEditor.h b/src/ThemeBuilder/components/properties/FontPropertyEditor.h new file mode 100644 index 00000000..d349f1f2 --- /dev/null +++ b/src/ThemeBuilder/components/properties/FontPropertyEditor.h @@ -0,0 +1,38 @@ +#pragma once +#include "../Editor.h" +#include "cru/platform/graphics/Font.h" +#include "cru/ui/components/Input.h" +#include "cru/ui/controls/Control.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 FontPropertyEditor : public Editor { + public: + using PropertyType = std::shared_ptr; + + FontPropertyEditor(); + ~FontPropertyEditor() override; + + ui::controls::Control* GetRootControl() override; + + String GetLabelText() const { return label_.GetText(); } + void SetLabelText(String label) { label_.SetText(std::move(label)); } + + std::shared_ptr GetValue() const; + void SetValue(std::shared_ptr value, + bool trigger_change = true); + + private: + ui::controls::FlexLayout main_container_; + ui::controls::TextBlock label_; + ui::controls::FlexLayout right_container_; + ui::controls::FlexLayout font_family_container_; + ui::controls::TextBlock font_family_label_; + ui::controls::TextBox font_family_text_; + ui::controls::FlexLayout font_size_container_; + ui::controls::TextBlock font_size_label_; + ui::components::FloatInput font_size_input_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp new file mode 100644 index 00000000..d1f4afce --- /dev/null +++ b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp @@ -0,0 +1,37 @@ +#include "MeasureLengthPropertyEditor.h" +#include "cru/common/Format.h" +#include "cru/ui/mapper/MapperRegistry.h" +#include "cru/ui/render/MeasureRequirement.h" + +namespace cru::theme_builder::components::properties { +MeasureLengthPropertyEditor::MeasureLengthPropertyEditor() { + container_.AddChild(&label_); + container_.AddChild(&text_); + + text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text = text_.GetTextView(); + auto measure_length_mapper = ui::mapper::MapperRegistry::GetInstance() + ->GetMapper(); + try { + auto measure_length = + measure_length_mapper->MapFromString(text.ToString()); + measure_length_ = measure_length; + is_text_valid_ = true; + RaiseChangeEvent(); + } catch (const Exception&) { + is_text_valid_ = false; + // TODO: Show error! + } + }); +} + +MeasureLengthPropertyEditor::~MeasureLengthPropertyEditor() {} + +void MeasureLengthPropertyEditor::SetValue( + const ui::render::MeasureLength& value, bool trigger_change) { + if (!trigger_change) SuppressNextChangeEvent(); + text_.SetText(measure_length_.IsNotSpecified() + ? u"unspecified" + : ToString(measure_length_.GetLengthOrUndefined())); +} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h new file mode 100644 index 00000000..43e783c5 --- /dev/null +++ b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h @@ -0,0 +1,35 @@ +#pragma once +#include "../Editor.h" +#include "cru/platform/graphics/Base.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" +#include "cru/ui/render/MeasureRequirement.h" + +namespace cru::theme_builder::components::properties { +class MeasureLengthPropertyEditor : public Editor { + public: + using PropertyType = ui::render::MeasureLength; + + MeasureLengthPropertyEditor(); + ~MeasureLengthPropertyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + PropertyType GetValue() const { return measure_length_; } + void SetValue(const PropertyType& value, bool trigger_change = true); + + private: + PropertyType measure_length_; + + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::TextBox text_; + bool is_text_valid_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h b/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h new file mode 100644 index 00000000..0f22616a --- /dev/null +++ b/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h @@ -0,0 +1,65 @@ +#pragma once +#include "../Editor.h" +#include "cru/ui/controls/CheckBox.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" + +#include + +namespace cru::theme_builder::components::properties { +template +class OptionalPropertyEditor : public Editor { + public: + using PropertyType = typename TEditor::PropertyType; + + OptionalPropertyEditor() { + container_.AddChild(&label_); + container_.AddChild(&check_box_); + check_box_.SetMargin({0, 0, 10, 0}); + container_.AddChild(editor_.GetRootControl()); + + editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) { + if (IsEnabled()) { + RaiseChangeEvent(); + } + }); + } + ~OptionalPropertyEditor() override {} + + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + bool IsEnabled() const { return check_box_.IsChecked(); } + void SetEnabled(bool enabled, bool trigger_change = true) { + check_box_.SetChecked(enabled); + if (trigger_change) { + RaiseChangeEvent(); + } + } + + std::optional GetValue() const { + return IsEnabled() ? std::optional(editor_.GetValue()) + : std::nullopt; + } + + void SetValue(std::optional value, bool trigger_change = true) { + if (value) { + SetEnabled(true, false); + editor_.SetValue(*value, false); + if (trigger_change) RaiseChangeEvent(); + } else { + SetEnabled(false, trigger_change); + } + } + + TEditor* GetEditor() { return &editor_; } + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::CheckBox check_box_; + TEditor editor_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp new file mode 100644 index 00000000..6d4277aa --- /dev/null +++ b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp @@ -0,0 +1,38 @@ +#include "PointPropertyEditor.h" +#include "cru/common/Format.h" +#include "cru/ui/mapper/MapperRegistry.h" +#include "cru/ui/mapper/PointMapper.h" + +namespace cru::theme_builder::components::properties { +PointPropertyEditor::PointPropertyEditor() { + container_.AddChild(&label_); + container_.AddChild(&text_); + + text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text = text_.GetTextView(); + auto point_mapper = + ui::mapper::MapperRegistry::GetInstance()->GetMapper(); + 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! + } + }); +} + +PointPropertyEditor::~PointPropertyEditor() {} + +void PointPropertyEditor::SetValue(const ui::Point& point, + bool trigger_change) { + if (!trigger_change) SuppressNextChangeEvent(); + text_.SetText(ConvertPointToString(point)); +} + +String PointPropertyEditor::ConvertPointToString(const ui::Point& point) { + return Format(u"{} {}", point.x, point.y); +} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/PointPropertyEditor.h b/src/ThemeBuilder/components/properties/PointPropertyEditor.h new file mode 100644 index 00000000..bd852e3a --- /dev/null +++ b/src/ThemeBuilder/components/properties/PointPropertyEditor.h @@ -0,0 +1,35 @@ +#pragma once +#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 Editor { + public: + using PropertyType = ui::Point; + + PointPropertyEditor(); + ~PointPropertyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + ui::Point GetValue() const { return point_; } + void SetValue(const ui::Point& point, bool trigger_change = true); + + private: + static String ConvertPointToString(const ui::Point& point); + + private: + ui::Point point_; + + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::TextBox text_; + bool is_text_valid_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/SelectPropertyEditor.cpp b/src/ThemeBuilder/components/properties/SelectPropertyEditor.cpp new file mode 100644 index 00000000..835b2d12 --- /dev/null +++ b/src/ThemeBuilder/components/properties/SelectPropertyEditor.cpp @@ -0,0 +1,15 @@ +#include "SelectPropertyEditor.h" +#include "cru/ui/controls/FlexLayout.h" + +namespace cru::theme_builder::components::properties { +SelectPropertyEditor::SelectPropertyEditor() { + container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); + container_.AddChild(&label_); + container_.AddChild(select_.GetRootControl()); + + select_.ItemSelectedEvent()->AddHandler( + [this](Index index) { RaiseChangeEvent(); }); +} + +SelectPropertyEditor::~SelectPropertyEditor() {} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/SelectPropertyEditor.h b/src/ThemeBuilder/components/properties/SelectPropertyEditor.h new file mode 100644 index 00000000..475d2d0a --- /dev/null +++ b/src/ThemeBuilder/components/properties/SelectPropertyEditor.h @@ -0,0 +1,42 @@ +#pragma once +#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 Editor { + public: + using PropertyType = Index; + + SelectPropertyEditor(); + ~SelectPropertyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + Index GetSelectedIndex() const { return select_.GetSelectedIndex(); } + void SetSelectedIndex(Index index, bool trigger_change = true) { + if (trigger_change == false) SuppressNextChangeEvent(); + select_.SetSelectedIndex(index); + } + + std::vector GetItems() const { return select_.GetItems(); } + void SetItems(std::vector items) { + select_.SetItems(std::move(items)); + } + + Index GetValue() const { return GetSelectedIndex(); } + void SetValue(Index value, bool trigger_change = true) { + SetSelectedIndex(value, trigger_change); + } + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::components::Select select_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/TextPropertyEditor.cpp b/src/ThemeBuilder/components/properties/TextPropertyEditor.cpp new file mode 100644 index 00000000..9854019c --- /dev/null +++ b/src/ThemeBuilder/components/properties/TextPropertyEditor.cpp @@ -0,0 +1,22 @@ +#include "TextPropertyEditor.h" + +namespace cru::theme_builder::components::properties { +TextPropertyEditor::TextPropertyEditor() { + editor_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text_view = editor_.GetTextView(); + String error_message; + auto validation_result = Validate(text_view, &error_message); + if (validation_result) { + OnTextChanged(text_view); + } + }); +} + +TextPropertyEditor::~TextPropertyEditor() {} + +bool TextPropertyEditor::Validate(StringView text, String* error_message) { + return true; +} + +void TextPropertyEditor::OnTextChanged(StringView text) {} +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/TextPropertyEditor.h b/src/ThemeBuilder/components/properties/TextPropertyEditor.h new file mode 100644 index 00000000..c4944228 --- /dev/null +++ b/src/ThemeBuilder/components/properties/TextPropertyEditor.h @@ -0,0 +1,31 @@ +#pragma once +#include "cru/ui/components/Component.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 TextPropertyEditor : public ui::components::Component { + public: + TextPropertyEditor(); + ~TextPropertyEditor() override; + + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + String GetText() const { return editor_.GetText(); } + StringView GetTextView() const { return editor_.GetTextView(); } + void SetText(String text) { editor_.SetText(std::move(text)); } + + protected: + virtual bool Validate(StringView text, String* error_message); + virtual void OnTextChanged(StringView text); + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::TextBox editor_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp new file mode 100644 index 00000000..3e022bb1 --- /dev/null +++ b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp @@ -0,0 +1,34 @@ +#include "ThicknessPropertyEditor.h" +#include "cru/ui/mapper/MapperRegistry.h" +#include "cru/ui/mapper/ThicknessMapper.h" + +namespace cru::theme_builder::components::properties { +ThicknessPropertyEditor::ThicknessPropertyEditor() { + container_.AddChild(&label_); + container_.AddChild(&text_); + + text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { + auto text = text_.GetText(); + auto thickness_mapper = + ui::mapper::MapperRegistry::GetInstance()->GetMapper(); + try { + auto thickness = thickness_mapper->MapFromString(text); + thickness_ = thickness; + is_text_valid_ = true; + RaiseChangeEvent(); + } catch (const Exception &) { + is_text_valid_ = false; + // TODO: Show error! + } + }); +} + +ThicknessPropertyEditor::~ThicknessPropertyEditor() {} + +void ThicknessPropertyEditor::SetValue(const ui::Thickness &thickness, + bool trigger_change) { + 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/ThemeBuilder/components/properties/ThicknessPropertyEditor.h b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h new file mode 100644 index 00000000..cea9ae9d --- /dev/null +++ b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h @@ -0,0 +1,31 @@ +#pragma once +#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 Editor { + public: + using PropertyType = ui::Thickness; + + ThicknessPropertyEditor(); + ~ThicknessPropertyEditor() override; + + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + ui::Thickness GetValue() const { return thickness_; } + void SetValue(const ui::Thickness& thickness, bool trigger_change = true); + + private: + ui::Thickness thickness_; + + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::controls::TextBox text_; + bool is_text_valid_; +}; +} // namespace cru::theme_builder::components::properties diff --git a/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp b/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp new file mode 100644 index 00000000..81eb66d3 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp @@ -0,0 +1,100 @@ +#include "BorderStylerEditor.h" +#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::stylers { +BorderStylerEditor::BorderStylerEditor() { + SetLabel(u"Border Styler"); + GetContainer()->AddChild(corner_radius_editor_.GetRootControl()); + GetContainer()->AddChild(thickness_editor_.GetRootControl()); + GetContainer()->AddChild(brush_editor_.GetRootControl()); + GetContainer()->AddChild(foreground_brush_editor_.GetRootControl()); + GetContainer()->AddChild(background_brush_editor_.GetRootControl()); + + thickness_editor_.GetEditor()->SetLabel(u"Thickness"); + brush_editor_.GetEditor()->SetLabel(u"Border"); + foreground_brush_editor_.GetEditor()->SetLabel(u"Foreground"); + background_brush_editor_.GetEditor()->SetLabel(u"Background"); + + ConnectChangeEvent(corner_radius_editor_); + ConnectChangeEvent(thickness_editor_); + ConnectChangeEvent(brush_editor_); + ConnectChangeEvent(foreground_brush_editor_); + ConnectChangeEvent(background_brush_editor_); +} + +BorderStylerEditor::~BorderStylerEditor() {} + +ClonablePtr BorderStylerEditor::GetValue() { + auto graphics_factory = + platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory(); + + ui::style::ApplyBorderStyleInfo border_style; + border_style.border_radius = corner_radius_editor_.GetValue(); + border_style.border_thickness = thickness_editor_.GetValue(); + + if (brush_editor_.IsEnabled()) { + border_style.border_brush = graphics_factory->CreateSolidColorBrush( + brush_editor_.GetEditor()->GetValue()); + } + + if (foreground_brush_editor_.IsEnabled()) { + border_style.foreground_brush = graphics_factory->CreateSolidColorBrush( + foreground_brush_editor_.GetEditor()->GetValue()); + } + + if (background_brush_editor_.IsEnabled()) { + border_style.background_brush = graphics_factory->CreateSolidColorBrush( + background_brush_editor_.GetEditor()->GetValue()); + } + + return ui::style::BorderStyler::Create(border_style); +} + +void BorderStylerEditor::SetValue(ui::style::BorderStyler* styler, + bool trigger_change) { + Expects(styler); + + auto border_style = styler->GetBorderStyle(); + corner_radius_editor_.SetValue(border_style.border_radius, false); + thickness_editor_.SetValue(border_style.border_thickness, false); + + brush_editor_.SetEnabled(border_style.border_brush.has_value(), false); + if (border_style.border_brush.has_value()) { + brush_editor_.GetEditor()->SetValue( + std::dynamic_pointer_cast( + border_style.border_brush.value()) + ->GetColor(), + false); + } + + foreground_brush_editor_.SetEnabled(border_style.foreground_brush.has_value(), + false); + if (border_style.foreground_brush.has_value()) { + foreground_brush_editor_.GetEditor()->SetValue( + std::dynamic_pointer_cast( + border_style.foreground_brush.value()) + ->GetColor(), + false); + } + + background_brush_editor_.SetEnabled(border_style.background_brush.has_value(), + false); + if (border_style.background_brush.has_value()) { + background_brush_editor_.GetEditor()->SetValue( + std::dynamic_pointer_cast( + border_style.background_brush.value()) + ->GetColor(), + false); + } + + if (trigger_change) { + RaiseChangeEvent(); + } +} + +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/BorderStylerEditor.h b/src/ThemeBuilder/components/stylers/BorderStylerEditor.h new file mode 100644 index 00000000..539262d6 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/BorderStylerEditor.h @@ -0,0 +1,36 @@ +#pragma once +#include "../properties/ColorPropertyEditor.h" +#include "../properties/CornerRadiusPropertyEditor.h" +#include "../properties/OptionalPropertyEditor.h" +#include "../properties/ThicknessPropertyEditor.h" +#include "StylerEditor.h" +#include "cru/common/ClonablePtr.h" + +namespace cru::theme_builder::components::stylers { +class BorderStylerEditor : public StylerEditor { + public: + BorderStylerEditor(); + ~BorderStylerEditor() override; + + ClonablePtr GetValue(); + void SetValue(ui::style::BorderStyler* styler, bool trigger_change = true); + void SetValue(const ClonablePtr& styler, + bool trigger_change = true) { + SetValue(styler.get(), trigger_change); + } + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + properties::OptionalPropertyEditor + corner_radius_editor_; + properties::OptionalPropertyEditor + thickness_editor_; + properties::OptionalPropertyEditor + brush_editor_; + properties::OptionalPropertyEditor + foreground_brush_editor_; + properties::OptionalPropertyEditor + background_brush_editor_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp new file mode 100644 index 00000000..6b8a5033 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp @@ -0,0 +1,105 @@ +#include "CompoundStylerEditor.h" +#include "BorderStylerEditor.h" +#include "ContentBrushStylerEditor.h" +#include "CursorStylerEditor.h" +#include "FontStylerEditor.h" +#include "MarginStylerEditor.h" +#include "PaddingStylerEditor.h" +#include "PreferredSizeStylerEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/ThemeManager.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +CompoundStylerEditor::CompoundStylerEditor() { + SetLabel(u"Compound Styler"); + GetContainer()->AddChild(&children_container_); + children_container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); + children_container_.SetItemCrossAlign( + ui::controls::FlexCrossAlignment::Start); + + GetHeadContainer()->AddChild(add_child_button_.GetRootControl()); + add_child_button_.GetButton()->GetStyleRuleSet()->SetParent( + ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( + u"cru.theme_builder.icon-button.style")); + add_child_button_.GetButton()->SetIconWithSvgPathDataStringResourceKey( + u"icon.plus", {0, 0, 16, 16}); + add_child_button_.GetButton()->SetPreferredSize({24, 24}); + add_child_button_.GetButton()->SetPadding(ui::Thickness(2)); + add_child_button_.GetButton()->SetIconFillColor(ui::colors::green); + add_child_button_.SetMenuItems({u"Compound Styler", u"Border Styler", + u"Cursor Styler", u"Content Brush Styler", + u"Font Styler", u"Margin Styler", + u"Padding Styler", u"Preferred Size Styler"}); + add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) { + std::unique_ptr editor; + switch (index) { + case 0: + editor = std::make_unique(); + break; + case 1: + editor = std::make_unique(); + break; + case 2: + editor = std::make_unique(); + break; + case 3: + editor = std::make_unique(); + break; + case 4: + editor = std::make_unique(); + break; + case 5: + editor = std::make_unique(); + break; + case 6: + editor = std::make_unique(); + break; + case 7: + editor = std::make_unique(); + break; + default: + break; + } + if (editor) { + ConnectChangeEvent(editor.get()); + editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { + auto index = this->children_container_.IndexOf(c->GetRootControl()); + this->children_.erase(this->children_.begin() + index); + this->children_container_.RemoveChildAt(index); + RaiseChangeEvent(); + }); + children_.push_back(std::move(editor)); + children_container_.AddChild(editor->GetRootControl()); + RaiseChangeEvent(); + } + }); +} + +CompoundStylerEditor::~CompoundStylerEditor() {} + +ClonablePtr CompoundStylerEditor::GetValue() { + std::vector> children_styler; + for (auto& child : children_) { + children_styler.push_back(child->GetStyler()); + } + return ui::style::CompoundStyler::Create(std::move(children_styler)); +} + +void CompoundStylerEditor::SetValue(ui::style::CompoundStyler* value, + bool trigger_change) { + children_.clear(); + for (const auto& styler : value->GetChildren()) { + auto editor = CreateStylerEditor(styler.get()); + ConnectChangeEvent(editor.get()); + editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { + auto index = this->children_container_.IndexOf(c->GetRootControl()); + this->children_.erase(this->children_.begin() + index); + this->children_container_.RemoveChildAt(index); + RaiseChangeEvent(); + }); + children_.push_back(std::move(editor)); + children_container_.AddChild(children_.back()->GetRootControl()); + } +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/CompoundStylerEditor.h b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.h new file mode 100644 index 00000000..57150e83 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.h @@ -0,0 +1,30 @@ +#pragma once +#include "StylerEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/DeleteLater.h" +#include "cru/ui/components/PopupButton.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +class CompoundStylerEditor : public StylerEditor { + public: + CompoundStylerEditor(); + ~CompoundStylerEditor() override; + + public: + ClonablePtr GetValue(); + void SetValue(ui::style::CompoundStyler* styler, bool trigger_change = true); + void SetValue(const ClonablePtr& styler, + bool trigger_change = true) { + SetValue(styler.get(), trigger_change); + } + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + ui::controls::FlexLayout children_container_; + std::vector> children_; + ui::components::PopupMenuIconButton add_child_button_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp new file mode 100644 index 00000000..bd649c67 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.cpp @@ -0,0 +1,31 @@ +#include "ContentBrushStylerEditor.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +ContentBrushStylerEditor::ContentBrushStylerEditor() { + GetContainer()->AddChild(color_editor_.GetRootControl()); + + ConnectChangeEvent(color_editor_); +} + +ContentBrushStylerEditor::~ContentBrushStylerEditor() {} + +ClonablePtr ContentBrushStylerEditor::GetValue() + const { + return ui::style::ContentBrushStyler::Create( + platform::gui::IUiApplication::GetInstance() + ->GetGraphicsFactory() + ->CreateSolidColorBrush(color_editor_.GetValue())); +} + +void ContentBrushStylerEditor::SetValue(ui::style::ContentBrushStyler* value, + bool trigger_change) { + color_editor_.SetValue( + std::dynamic_pointer_cast( + value->GetBrush()) + ->GetColor(), + trigger_change); +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h new file mode 100644 index 00000000..8385b7c3 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/ContentBrushStylerEditor.h @@ -0,0 +1,24 @@ +#pragma once +#include "../Editor.h" +#include "../properties/ColorPropertyEditor.h" +#include "StylerEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +class ContentBrushStylerEditor : public StylerEditor { + public: + ContentBrushStylerEditor(); + ~ContentBrushStylerEditor(); + + public: + ClonablePtr GetValue() const; + void SetValue(ui::style::ContentBrushStyler* value, + bool trigger_change = true); + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + properties::ColorPropertyEditor color_editor_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp b/src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp new file mode 100644 index 00000000..9984d81a --- /dev/null +++ b/src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp @@ -0,0 +1,65 @@ +#include "CursorStylerEditor.h" +#include "cru/platform/gui/Cursor.h" +#include "cru/platform/gui/UiApplication.h" + +namespace cru::theme_builder::components::stylers { +CursorStylerEditor::CursorStylerEditor() { + SetLabel(u"Cursor Styler"); + GetContainer()->AddChild(cursor_select_.GetRootControl()); + + cursor_select_.SetLabel(u"Cursor"); + cursor_select_.SetItems({u"arrow", u"hand", u"ibeam"}); + cursor_select_.SetSelectedIndex(0); + + ConnectChangeEvent(cursor_select_); +} + +CursorStylerEditor::~CursorStylerEditor() {} + +ClonablePtr CursorStylerEditor::GetValue() { + auto cursor_manager = + platform::gui::IUiApplication::GetInstance()->GetCursorManager(); + + std::shared_ptr cursor; + + switch (cursor_select_.GetSelectedIndex()) { + case 0: + cursor = cursor_manager->GetSystemCursor( + platform::gui::SystemCursorType::Arrow); + break; + case 1: + cursor = cursor_manager->GetSystemCursor( + platform::gui::SystemCursorType::Hand); + break; + case 2: + cursor = cursor_manager->GetSystemCursor( + platform::gui::SystemCursorType::IBeam); + break; + } + + return ui::style::CursorStyler::Create(cursor); +} + +void CursorStylerEditor::SetValue(ui::style::CursorStyler* styler, + bool trigger_change) { + auto cursor_manager = + platform::gui::IUiApplication::GetInstance()->GetCursorManager(); + + auto cursor = styler->GetCursor(); + + if (cursor == + cursor_manager->GetSystemCursor(platform::gui::SystemCursorType::Arrow)) { + cursor_select_.SetSelectedIndex(0); + } else if (cursor == cursor_manager->GetSystemCursor( + platform::gui::SystemCursorType::Hand)) { + cursor_select_.SetSelectedIndex(1); + } else if (cursor == cursor_manager->GetSystemCursor( + platform::gui::SystemCursorType::IBeam)) { + cursor_select_.SetSelectedIndex(2); + } + + if (trigger_change) { + RaiseChangeEvent(); + } +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/CursorStylerEditor.h b/src/ThemeBuilder/components/stylers/CursorStylerEditor.h new file mode 100644 index 00000000..552619a0 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/CursorStylerEditor.h @@ -0,0 +1,24 @@ +#pragma once +#include "../properties/SelectPropertyEditor.h" +#include "StylerEditor.h" + +namespace cru::theme_builder::components::stylers { +class CursorStylerEditor : public StylerEditor { + public: + CursorStylerEditor(); + ~CursorStylerEditor() override; + + public: + ClonablePtr GetValue(); + void SetValue(ui::style::CursorStyler* styler, bool trigger_change = true); + void SetValue(const ClonablePtr& styler, + bool trigger_change = true) { + SetValue(styler.get(), trigger_change); + } + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + properties::SelectPropertyEditor cursor_select_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/FontStylerEditor.cpp b/src/ThemeBuilder/components/stylers/FontStylerEditor.cpp new file mode 100644 index 00000000..9787a4fd --- /dev/null +++ b/src/ThemeBuilder/components/stylers/FontStylerEditor.cpp @@ -0,0 +1,23 @@ +#include "FontStylerEditor.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/gui/UiApplication.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +FontStylerEditor::FontStylerEditor() { + GetContainer()->AddChild(font_editor_.GetRootControl()); + + ConnectChangeEvent(font_editor_); +} + +FontStylerEditor::~FontStylerEditor() {} + +ClonablePtr FontStylerEditor::GetValue() const { + return ui::style::FontStyler::Create(font_editor_.GetValue()); +} + +void FontStylerEditor::SetValue(ui::style::FontStyler* value, + bool trigger_change) { + font_editor_.SetValue(value->GetFont(), trigger_change); +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/FontStylerEditor.h b/src/ThemeBuilder/components/stylers/FontStylerEditor.h new file mode 100644 index 00000000..ccd12113 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/FontStylerEditor.h @@ -0,0 +1,23 @@ +#pragma once +#include "../Editor.h" +#include "../properties/FontPropertyEditor.h" +#include "StylerEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +class FontStylerEditor : public StylerEditor { + public: + FontStylerEditor(); + ~FontStylerEditor(); + + public: + ClonablePtr GetValue() const; + void SetValue(ui::style::FontStyler* value, bool trigger_change = true); + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + properties::FontPropertyEditor font_editor_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp b/src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp new file mode 100644 index 00000000..d7d89acb --- /dev/null +++ b/src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp @@ -0,0 +1,28 @@ +#include "MarginStylerEditor.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +MarginStylerEditor::MarginStylerEditor() { + SetLabel(u"Margin Styler"); + GetContainer()->AddChild(thickness_editor_.GetRootControl()); + + thickness_editor_.SetLabel(u"Thickness"); + + ConnectChangeEvent(thickness_editor_); +} + +MarginStylerEditor::~MarginStylerEditor() {} + +ClonablePtr MarginStylerEditor::GetValue() { + return ui::style::MarginStyler::Create(thickness_editor_.GetValue()); +} + +void MarginStylerEditor::SetValue(ui::style::MarginStyler* styler, + bool trigger_change) { + thickness_editor_.SetValue(styler->GetMargin(), false); + + if (trigger_change) { + RaiseChangeEvent(); + } +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/MarginStylerEditor.h b/src/ThemeBuilder/components/stylers/MarginStylerEditor.h new file mode 100644 index 00000000..9de6f1a2 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/MarginStylerEditor.h @@ -0,0 +1,25 @@ +#pragma once +#include "../properties/ThicknessPropertyEditor.h" +#include "StylerEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +class MarginStylerEditor : public StylerEditor { + public: + MarginStylerEditor(); + ~MarginStylerEditor() override; + + ClonablePtr GetValue(); + void SetValue(ui::style::MarginStyler* styler, bool trigger_change = true); + void SetValue(const ClonablePtr& styler, + bool trigger_change = true) { + SetValue(styler.get(), trigger_change); + } + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + properties::ThicknessPropertyEditor thickness_editor_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp b/src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp new file mode 100644 index 00000000..476d21f1 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp @@ -0,0 +1,28 @@ +#include "PaddingStylerEditor.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +PaddingStylerEditor::PaddingStylerEditor() { + SetLabel(u"Padding Styler"); + GetContainer()->AddChild(thickness_editor_.GetRootControl()); + + thickness_editor_.SetLabel(u"Thickness"); + + ConnectChangeEvent(thickness_editor_); +} + +PaddingStylerEditor::~PaddingStylerEditor() {} + +ClonablePtr PaddingStylerEditor::GetValue() { + return ui::style::PaddingStyler::Create(thickness_editor_.GetValue()); +} + +void PaddingStylerEditor::SetValue(ui::style::PaddingStyler* styler, + bool trigger_change) { + thickness_editor_.SetValue(styler->GetPadding(), false); + + if (trigger_change) { + RaiseChangeEvent(); + } +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/PaddingStylerEditor.h b/src/ThemeBuilder/components/stylers/PaddingStylerEditor.h new file mode 100644 index 00000000..b78d310b --- /dev/null +++ b/src/ThemeBuilder/components/stylers/PaddingStylerEditor.h @@ -0,0 +1,25 @@ +#pragma once +#include "../properties/ThicknessPropertyEditor.h" +#include "StylerEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +class PaddingStylerEditor : public StylerEditor { + public: + PaddingStylerEditor(); + ~PaddingStylerEditor() override; + + ClonablePtr GetValue(); + void SetValue(ui::style::PaddingStyler* styler, bool trigger_change = true); + void SetValue(const ClonablePtr& styler, + bool trigger_change = true) { + SetValue(styler.get(), trigger_change); + } + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + properties::ThicknessPropertyEditor thickness_editor_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp b/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp new file mode 100644 index 00000000..fb713c8c --- /dev/null +++ b/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp @@ -0,0 +1,34 @@ +#include "PreferredSizeStylerEditor.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +PreferredSizeStylerEditor::PreferredSizeStylerEditor() { + SetLabel(u"Preferred Size Styler"); + GetContainer()->AddChild(width_editor_.GetRootControl()); + GetContainer()->AddChild(height_editor_.GetRootControl()); + + width_editor_.SetLabel(u"Width"); + height_editor_.SetLabel(u"Height"); + + ConnectChangeEvent(width_editor_); + ConnectChangeEvent(height_editor_); +} + +PreferredSizeStylerEditor::~PreferredSizeStylerEditor() {} + +ClonablePtr +PreferredSizeStylerEditor::GetValue() { + return ui::style::PreferredSizeStyler::Create(ui::render::MeasureSize{ + width_editor_.GetValue(), height_editor_.GetValue()}); +} + +void PreferredSizeStylerEditor::SetValue(ui::style::PreferredSizeStyler* styler, + bool trigger_change) { + width_editor_.SetValue(styler->GetPreferredSize().width, false); + height_editor_.SetValue(styler->GetPreferredSize().height, false); + + if (trigger_change) { + RaiseChangeEvent(); + } +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.h b/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.h new file mode 100644 index 00000000..4a64da10 --- /dev/null +++ b/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.h @@ -0,0 +1,27 @@ +#pragma once +#include "../properties/MeasureLengthPropertyEditor.h" +#include "StylerEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +class PreferredSizeStylerEditor : public StylerEditor { + public: + PreferredSizeStylerEditor(); + ~PreferredSizeStylerEditor() override; + + ClonablePtr GetValue(); + void SetValue(ui::style::PreferredSizeStyler* styler, + bool trigger_change = true); + void SetValue(const ClonablePtr& styler, + bool trigger_change = true) { + SetValue(styler.get(), trigger_change); + } + + ClonablePtr GetStyler() override { return GetValue(); } + + private: + properties::MeasureLengthPropertyEditor width_editor_; + properties::MeasureLengthPropertyEditor height_editor_; +}; +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/StylerEditor.cpp b/src/ThemeBuilder/components/stylers/StylerEditor.cpp new file mode 100644 index 00000000..0348adbd --- /dev/null +++ b/src/ThemeBuilder/components/stylers/StylerEditor.cpp @@ -0,0 +1,63 @@ +#include "StylerEditor.h" +#include "../Common.h" +#include "BorderStylerEditor.h" +#include "CompoundStylerEditor.h" +#include "ContentBrushStylerEditor.h" +#include "CursorStylerEditor.h" +#include "FontStylerEditor.h" +#include "MarginStylerEditor.h" +#include "PaddingStylerEditor.h" +#include "PreferredSizeStylerEditor.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/render/FlexLayoutRenderObject.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +StylerEditor::StylerEditor() {} + +StylerEditor::~StylerEditor() {} + +std::unique_ptr CreateStylerEditor(ui::style::Styler* styler) { + if (auto compound_styler = dynamic_cast(styler)) { + auto result = std::make_unique(); + result->SetValue(compound_styler); + return result; + } else if (auto border_styler = + dynamic_cast(styler)) { + auto editor = std::make_unique(); + editor->SetValue(border_styler); + return editor; + } else if (auto cursor_styler = + dynamic_cast(styler)) { + auto editor = std::make_unique(); + editor->SetValue(cursor_styler); + return editor; + } else if (auto preferred_size_styler = + dynamic_cast(styler)) { + auto editor = std::make_unique(); + editor->SetValue(preferred_size_styler); + return editor; + } else if (auto margin_styler = + dynamic_cast(styler)) { + auto editor = std::make_unique(); + editor->SetValue(margin_styler); + return editor; + } else if (auto padding_styler = + dynamic_cast(styler)) { + auto editor = std::make_unique(); + editor->SetValue(padding_styler); + return editor; + } else if (auto content_brush_styler = + dynamic_cast(styler)) { + auto editor = std::make_unique(); + editor->SetValue(content_brush_styler); + return editor; + } else if (auto font_styler = dynamic_cast(styler)) { + auto editor = std::make_unique(); + editor->SetValue(font_styler); + return editor; + } else { + throw Exception(u"Unknown styler type"); + } +} +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/components/stylers/StylerEditor.h b/src/ThemeBuilder/components/stylers/StylerEditor.h new file mode 100644 index 00000000..8aa52bda --- /dev/null +++ b/src/ThemeBuilder/components/stylers/StylerEditor.h @@ -0,0 +1,16 @@ +#pragma once +#include "../HeadBodyEditor.h" +#include "cru/ui/style/Styler.h" + +namespace cru::theme_builder::components::stylers { +class StylerEditor : public HeadBodyEditor { + public: + StylerEditor(); + ~StylerEditor() override; + + public: + virtual ClonablePtr GetStyler() = 0; +}; + +std::unique_ptr CreateStylerEditor(ui::style::Styler* styler); +} // namespace cru::theme_builder::components::stylers diff --git a/src/ThemeBuilder/main.cpp b/src/ThemeBuilder/main.cpp new file mode 100644 index 00000000..0c5b2159 --- /dev/null +++ b/src/ThemeBuilder/main.cpp @@ -0,0 +1,25 @@ +#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::components; + 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()); + + auto main_window = std::make_unique(); + + main_window->Show(); + + return application->Run(); +} diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt deleted file mode 100644 index 656f9f0a..00000000 --- a/src/theme_builder/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -add_executable(cru_theme_builder - main.cpp - components/Common.cpp - components/Editor.cpp - components/HeadBodyEditor.cpp - components/MainWindow.cpp - components/StyleRuleEditor.cpp - components/StyleRuleSetEditor.cpp - components/conditions/CheckedConditionEditor.cpp - components/conditions/ClickStateConditionEditor.cpp - components/conditions/CompoundConditionEditor.cpp - components/conditions/ConditionEditor.cpp - components/conditions/FocusConditionEditor.cpp - components/conditions/NoConditionEditor.cpp - components/properties/CheckBoxPropertyEditor.cpp - components/properties/ColorPropertyEditor.cpp - components/properties/CornerRadiusPropertyEditor.cpp - components/properties/FontPropertyEditor.cpp - components/properties/MeasureLengthPropertyEditor.cpp - components/properties/PointPropertyEditor.cpp - components/properties/SelectPropertyEditor.cpp - components/properties/TextPropertyEditor.cpp - components/properties/ThicknessPropertyEditor.cpp - components/stylers/BorderStylerEditor.cpp - components/stylers/CompoundStylerEditor.cpp - components/stylers/ContentBrushStylerEditor.cpp - components/stylers/CursorStylerEditor.cpp - components/stylers/FontStylerEditor.cpp - components/stylers/MarginStylerEditor.cpp - components/stylers/PaddingStylerEditor.cpp - components/stylers/PreferredSizeStylerEditor.cpp - components/stylers/StylerEditor.cpp -) - -if(APPLE) - set_target_properties(cru_theme_builder PROPERTIES - MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_BUNDLE_NAME cru-theme-builder - MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.theme-builder - ) -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 CruPlatformBootstrap CruUi) diff --git a/src/theme_builder/components/Common.cpp b/src/theme_builder/components/Common.cpp deleted file mode 100644 index 75d5deb0..00000000 --- a/src/theme_builder/components/Common.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "Common.h" -#include "cru/platform/Color.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/gui/UiApplication.h" - -#include - -namespace cru::theme_builder::components { -std::unique_ptr -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 deleted file mode 100644 index b91fcf88..00000000 --- a/src/theme_builder/components/Common.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include "cru/platform/graphics/Brush.h" - -namespace cru::theme_builder::components { -std::unique_ptr -CreateRandomEditorBackgroundBrush(); -} diff --git a/src/theme_builder/components/Editor.cpp b/src/theme_builder/components/Editor.cpp deleted file mode 100644 index 89e27e83..00000000 --- a/src/theme_builder/components/Editor.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "Editor.h" - -namespace cru::theme_builder::components { - -void Editor::RaiseChangeEvent() { - if (suppress_next_change_event_) { - suppress_next_change_event_ = false; - } else { - change_event_.Raise(nullptr); - } -} - -void Editor::SuppressNextChangeEvent() { suppress_next_change_event_ = true; } - -void Editor::ConnectChangeEvent(IEvent* event) { - event->AddHandler([this](std::nullptr_t) { RaiseChangeEvent(); }); -} - -void Editor::ConnectChangeEvent(Editor* editor) { - ConnectChangeEvent(editor->ChangeEvent()); -} - -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/Editor.h b/src/theme_builder/components/Editor.h deleted file mode 100644 index 29809c82..00000000 --- a/src/theme_builder/components/Editor.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "cru/common/Event.h" -#include "cru/ui/components/Component.h" - -namespace cru::theme_builder::components { -class Editor : public ui::components::Component { - public: - Editor() = default; - ~Editor() override = default; - - public: - IEvent* ChangeEvent() { return &change_event_; } - - protected: - void RaiseChangeEvent(); - void SuppressNextChangeEvent(); - void ConnectChangeEvent(IEvent* event); - void ConnectChangeEvent(Editor* editor); - void ConnectChangeEvent(Editor& editor) { ConnectChangeEvent(&editor); } - - private: - bool suppress_next_change_event_ = false; - Event change_event_; -}; -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/HeadBodyEditor.cpp b/src/theme_builder/components/HeadBodyEditor.cpp deleted file mode 100644 index 6d7ace66..00000000 --- a/src/theme_builder/components/HeadBodyEditor.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "HeadBodyEditor.h" -#include "Common.h" -#include "cru/ui/ThemeManager.h" -#include "cru/ui/controls/FlexLayout.h" - -namespace cru::theme_builder::components { -HeadBodyEditor::HeadBodyEditor() { - border_.SetChild(&container_); - border_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush()); - - container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); - container_.AddChild(&head_container_); - container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Stretch); - head_container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); - head_container_.AddChild(&label_); - - remove_button_.GetStyleRuleSet()->SetParent( - ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( - u"cru.theme_builder.icon-button.style")); - remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close", - {0, 0, 16, 16}); - remove_button_.SetIconFillColor(ui::colors::red); - head_container_.AddChild(&remove_button_); - - remove_button_.ClickEvent()->AddSpyOnlyHandler( - [this] { remove_event_.Raise(nullptr); }); -} - -HeadBodyEditor::~HeadBodyEditor() {} -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/HeadBodyEditor.h b/src/theme_builder/components/HeadBodyEditor.h deleted file mode 100644 index 8119724f..00000000 --- a/src/theme_builder/components/HeadBodyEditor.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include "Editor.h" -#include "cru/common/Event.h" -#include "cru/ui/controls/Container.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/IconButton.h" -#include "cru/ui/controls/TextBlock.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components { -class HeadBodyEditor : public Editor { - public: - HeadBodyEditor(); - ~HeadBodyEditor() override; - - public: - ui::controls::Control* GetRootControl() override { return &border_; } - - ui::controls::FlexLayout* GetContainer() { return &container_; } - ui::controls::FlexLayout* GetHeadContainer() { return &head_container_; } - - String GetLabel() const { return label_.GetText(); } - void SetLabel(String label) { label_.SetText(std::move(label)); } - - IEvent* RemoveEvent() { return &remove_event_; } - - private: - ui::controls::Container border_; - ui::controls::FlexLayout container_; - ui::controls::FlexLayout head_container_; - ui::controls::TextBlock label_; - ui::controls::IconButton remove_button_; - - Event remove_event_; -}; -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/MainWindow.cpp b/src/theme_builder/components/MainWindow.cpp deleted file mode 100644 index 0c78ef25..00000000 --- a/src/theme_builder/components/MainWindow.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "MainWindow.h" -#include "cru/ui/Base.h" -#include "cru/ui/controls/StackLayout.h" -#include "cru/ui/controls/TextBlock.h" - -namespace cru::theme_builder::components { -using namespace cru::ui; -using namespace cru::ui::controls; -using namespace cru::platform::gui; - -MainWindow::MainWindow() { - window_.GetNativeWindow()->SetTitle(u"CruUI Theme Builder"); - main_layout_.SetFlexDirection(FlexDirection::Horizontal); - window_.AddChild(&main_layout_); - main_layout_.AddChild(&preview_layout_); - - preview_button_text_.SetText(u"Preview"); - preview_button_.SetChild(&preview_button_text_); - preview_layout_.AddChild(&preview_button_); - preview_layout_.SetChildLayoutData( - 0, StackChildLayoutData{Alignment::Center, Alignment::Center}); - - style_rule_set_editor_.BindStyleRuleSet( - preview_button_.GetStyleRuleSet()->GetParent()); - main_layout_.AddChild(style_rule_set_editor_.GetRootControl()); - - main_layout_.SetChildLayoutData(0, {1, 0}); - main_layout_.SetChildLayoutData(1, {0, 1}); -} - -MainWindow::~MainWindow() {} - -void MainWindow::Show() { - window_.GetNativeWindow()->SetVisibility(WindowVisibilityType::Show); - window_.GetNativeWindow()->SetToForeground(); -} -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/MainWindow.h b/src/theme_builder/components/MainWindow.h deleted file mode 100644 index ede1c38f..00000000 --- a/src/theme_builder/components/MainWindow.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include "StyleRuleSetEditor.h" -#include "cru/ui/components/Component.h" -#include "cru/ui/controls/Button.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/StackLayout.h" -#include "cru/ui/controls/TextBlock.h" -#include "cru/ui/controls/Window.h" - -namespace cru::theme_builder::components { -class MainWindow : public ui::components::Component { - public: - MainWindow(); - - CRU_DELETE_COPY(MainWindow) - CRU_DELETE_MOVE(MainWindow) - - ~MainWindow() override; - - ui::controls::Control* GetRootControl() override { return &window_; } - - void Show(); - - private: - ui::controls::Window window_; - ui::controls::FlexLayout main_layout_; - ui::controls::StackLayout preview_layout_; - ui::controls::Button preview_button_; - ui::controls::TextBlock preview_button_text_; - StyleRuleSetEditor style_rule_set_editor_; -}; -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleEditor.cpp b/src/theme_builder/components/StyleRuleEditor.cpp deleted file mode 100644 index dcb33184..00000000 --- a/src/theme_builder/components/StyleRuleEditor.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#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::components { -StyleRuleEditor::StyleRuleEditor() { - container_.SetChild(&main_layout_); - container_.SetBackgroundBrush(CreateRandomEditorBackgroundBrush()); - - main_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); - main_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); - - main_layout_.AddChild(&head_layout_); - - label_.SetText(u"Style Rule"); - head_layout_.AddChild(&label_); - head_layout_.AddChild(&remove_button_); - - remove_button_.GetStyleRuleSet()->SetParent( - ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( - u"cru.theme_builder.icon-button.style")); - remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close", - {0, 0, 16, 16}); - remove_button_.SetIconFillColor(ui::colors::red); - - main_layout_.AddChild(&body_layout_); - body_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); - body_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); - body_layout_.SetMargin({10, 0, 0, 0}); - - remove_button_.ClickEvent()->AddSpyOnlyHandler( - [this] { remove_event_.Raise(nullptr); }); -} - -StyleRuleEditor::~StyleRuleEditor() {} - -ui::style::StyleRule StyleRuleEditor::GetValue() const { - return ui::style::StyleRule(condition_editor_->GetCondition(), - styler_editor_->GetStyler()); -} - -void StyleRuleEditor::SetValue(const ui::style::StyleRule& style_rule, - bool trigger_change) { - body_layout_.ClearChildren(); - condition_editor_ = - components::conditions::CreateConditionEditor(style_rule.GetCondition()); - styler_editor_ = - components::stylers::CreateStylerEditor(style_rule.GetStyler()); - body_layout_.AddChild(condition_editor_->GetRootControl()); - body_layout_.AddChild(styler_editor_->GetRootControl()); - condition_editor_->ChangeEvent()->AddSpyOnlyHandler( - [this] { change_event_.Raise(nullptr); }); - styler_editor_->ChangeEvent()->AddSpyOnlyHandler( - [this] { change_event_.Raise(nullptr); }); - - if (trigger_change) { - change_event_.Raise(nullptr); - } -} -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleEditor.h b/src/theme_builder/components/StyleRuleEditor.h deleted file mode 100644 index 8e3db3de..00000000 --- a/src/theme_builder/components/StyleRuleEditor.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#include "conditions/ConditionEditor.h" -#include "cru/ui/components/Component.h" -#include "cru/ui/controls/Button.h" -#include "cru/ui/controls/Control.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/IconButton.h" -#include "cru/ui/controls/TextBlock.h" -#include "cru/ui/style/StyleRule.h" -#include "stylers/StylerEditor.h" - -namespace cru::theme_builder::components { -class StyleRuleEditor : public ui::components::Component { - public: - StyleRuleEditor(); - - CRU_DELETE_COPY(StyleRuleEditor) - CRU_DELETE_MOVE(StyleRuleEditor) - - ~StyleRuleEditor() override; - - public: - ui::controls::Control* GetRootControl() override { return &container_; } - - ui::style::StyleRule GetValue() const; - void SetValue(const ui::style::StyleRule& style_rule, - bool trigger_change = true); - - IEvent* ChangeEvent() { return &change_event_; } - IEvent* RemoveEvent() { return &remove_event_; } - - private: - ui::controls::Container container_; - ui::controls::FlexLayout main_layout_; - ui::controls::TextBlock label_; - ui::controls::FlexLayout head_layout_; - ui::controls::IconButton remove_button_; - ui::controls::FlexLayout body_layout_; - std::unique_ptr condition_editor_; - std::unique_ptr styler_editor_; - - Event change_event_; - Event remove_event_; -}; -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleSetEditor.cpp b/src/theme_builder/components/StyleRuleSetEditor.cpp deleted file mode 100644 index 8cf5af6d..00000000 --- a/src/theme_builder/components/StyleRuleSetEditor.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "StyleRuleSetEditor.h" -#include "cru/common/Exception.h" -#include "cru/common/String.h" -#include "cru/ui/DeleteLater.h" -#include "cru/ui/ThemeManager.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/model/IListChangeNotify.h" -#include "cru/ui/render/FlexLayoutRenderObject.h" -#include "cru/ui/style/Condition.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components { -using namespace cru::ui::controls; -StyleRuleSetEditor::StyleRuleSetEditor() { - scroll_view_.SetChild(&container_); - - container_.SetFlexDirection(ui::render::FlexDirection::Vertical); - container_.AddChild(&rules_layout_); - container_.AddChild(&add_button_); - - rules_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); - rules_layout_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Stretch); - - add_button_.GetStyleRuleSet()->SetParent( - ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( - u"cru.theme_builder.icon-button.style")); - add_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.plus", - {0, 0, 16, 16}); - add_button_.SetPreferredSize({24, 24}); - add_button_.SetPadding(ui::Thickness(2)); - add_button_.SetIconFillColor(ui::colors::green); - - add_button_.ClickEvent()->AddSpyOnlyHandler([this] { - auto rule_set = ui::style::StyleRule(ui::style::NoCondition::Create(), - ui::style::CompoundStyler::Create({})); - style_rule_set_->AddStyleRule(rule_set); - }); -} - -StyleRuleSetEditor::~StyleRuleSetEditor() {} - -void StyleRuleSetEditor::BindStyleRuleSet( - std::shared_ptr rule_set) { - Expects(style_rule_set_ == nullptr && rule_set); - style_rule_set_ = std::move(rule_set); - UpdateView(style_rule_set_.get()); - style_rule_set_->ListChangeEvent()->AddHandler( - [this](const ui::model::ListChange& change) { - UpdateView(style_rule_set_.get(), change); - }); -} - -Index StyleRuleSetEditor::IndexOfRuleEditor(StyleRuleEditor* editor) { - auto iter = - std::find_if(style_rule_editors_.cbegin(), style_rule_editors_.cend(), - [editor](const ui::DeleteLaterPtr& p) { - return p.get() == editor; - }); - return iter - style_rule_editors_.cbegin(); -} - -void StyleRuleSetEditor::UpdateView( - ui::style::StyleRuleSet* style_rule_set, - std::optional change) { - if (change) { - switch (change->type) { - case ui::model::ListChangeType::kItemAdd: { - for (auto i = change->position; i < change->position + change->count; - ++i) { - const auto& rule = style_rule_set->GetStyleRule(i); - auto style_rule_editor = ui::MakeDeleteLaterPtr(); - style_rule_editor->SetValue(rule, false); - style_rule_editor->RemoveEvent()->AddSpyOnlyHandler( - [this, editor = style_rule_editor.get()] { - style_rule_set_->RemoveStyleRule(IndexOfRuleEditor(editor)); - }); - style_rule_editor->ChangeEvent()->AddSpyOnlyHandler( - [this, editor = style_rule_editor.get()]() { - suppress_next_set_ = true; - style_rule_set_->SetStyleRule(IndexOfRuleEditor(editor), - editor->GetValue()); - }); - style_rule_editors_.insert(style_rule_editors_.cbegin() + i, - std::move(style_rule_editor)); - rules_layout_.AddChildAt(style_rule_editors_.back()->GetRootControl(), - i); - } - break; - } - case ui::model::ListChangeType::kItemRemove: { - for (auto i = change->position; i < change->position + change->count; - ++i) { - style_rule_editors_.erase(style_rule_editors_.begin() + i); - } - break; - } - case ui::model::ListChangeType::kItemSet: { - if (suppress_next_set_) { - suppress_next_set_ = false; - break; - } - for (auto i = change->position; i < change->position + change->count; - ++i) { - const auto& rule = style_rule_set->GetStyleRule(i); - style_rule_editors_[i]->SetValue(rule, false); - } - break; - } - case ui::model::ListChangeType::kItemMove: { - throw Exception(u"Not supported now!"); - break; - } - case ui::model::ListChangeType::kClear: { - style_rule_editors_.clear(); - } - } - } else { - UpdateView(style_rule_set, ui::model::ListChange::Clear()); - UpdateView(style_rule_set, - ui::model::ListChange::ItemAdd(0, style_rule_set->GetSize())); - } -} -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/StyleRuleSetEditor.h b/src/theme_builder/components/StyleRuleSetEditor.h deleted file mode 100644 index 03148889..00000000 --- a/src/theme_builder/components/StyleRuleSetEditor.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once -#include "StyleRuleEditor.h" -#include "cru/ui/DeleteLater.h" -#include "cru/ui/components/Component.h" -#include "cru/ui/controls/Button.h" -#include "cru/ui/controls/Control.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/ScrollView.h" -#include "cru/ui/model/IListChangeNotify.h" -#include "cru/ui/style/StyleRuleSet.h" - -namespace cru::theme_builder::components { -class StyleRuleSetEditor : public ui::components::Component { - public: - StyleRuleSetEditor(); - - CRU_DELETE_COPY(StyleRuleSetEditor) - CRU_DELETE_MOVE(StyleRuleSetEditor) - - ~StyleRuleSetEditor() override; - - public: - ui::controls::Control* GetRootControl() override { return &scroll_view_; } - - void BindStyleRuleSet(std::shared_ptr rule_set); - - private: - Index IndexOfRuleEditor(StyleRuleEditor* editor); - - void UpdateView(ui::style::StyleRuleSet* style_rule_set, - std::optional change = std::nullopt); - - private: - std::shared_ptr style_rule_set_; - - ui::controls::ScrollView scroll_view_; - ui::controls::FlexLayout container_; - ui::controls::FlexLayout rules_layout_; - std::vector> style_rule_editors_; - ui::controls::IconButton add_button_; - - bool suppress_next_set_ = false; -}; -} // namespace cru::theme_builder::components diff --git a/src/theme_builder/components/conditions/CheckedConditionEditor.cpp b/src/theme_builder/components/conditions/CheckedConditionEditor.cpp deleted file mode 100644 index 64370981..00000000 --- a/src/theme_builder/components/conditions/CheckedConditionEditor.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "CheckedConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -CheckedConditionEditor::CheckedConditionEditor() { - SetLabel(u"Checked Condition"); - - checked_check_box_.SetLabel(u"Checked"); - GetContainer()->AddChild(checked_check_box_.GetRootControl()); - - ConnectChangeEvent(checked_check_box_); -} - -CheckedConditionEditor::~CheckedConditionEditor() {} - -ClonablePtr CheckedConditionEditor::GetValue() - const { - return ui::style::CheckedCondition::Create(checked_check_box_.GetValue()); -} - -void CheckedConditionEditor::SetValue(ui::style::CheckedCondition* value, - bool trigger_change) { - checked_check_box_.SetValue(value->IsChecked(), trigger_change); -} -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/CheckedConditionEditor.h b/src/theme_builder/components/conditions/CheckedConditionEditor.h deleted file mode 100644 index 7cf14912..00000000 --- a/src/theme_builder/components/conditions/CheckedConditionEditor.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include "../properties/CheckBoxPropertyEditor.h" -#include "ConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -class CheckedConditionEditor : public ConditionEditor { - public: - CheckedConditionEditor(); - ~CheckedConditionEditor() override; - - public: - ClonablePtr GetValue() const; - void SetValue(ui::style::CheckedCondition* value, bool trigger_change = true); - void SetValue(const ClonablePtr& value, - bool trigger_change = true) { - SetValue(value.get(), trigger_change); - } - - ClonablePtr GetCondition() override { - return GetValue(); - } - - private: - properties::CheckBoxPropertyEditor checked_check_box_; -}; -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp b/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp deleted file mode 100644 index a8d5cc87..00000000 --- a/src/theme_builder/components/conditions/ClickStateConditionEditor.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "ClickStateConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/helper/ClickDetector.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -using ui::helper::ClickState; -namespace { -const std::vector kClickStates{ - u"None", - u"Hover", - u"Press", - u"PressInactive", -}; - -Index ConvertClickStateToIndex(ClickState click_state) { - switch (click_state) { - case ClickState::None: - return 0; - case ClickState::Hover: - return 1; - case ClickState::Press: - return 2; - case ClickState::PressInactive: - return 3; - } - return -1; -} - -ClickState ConvertIndexToClickState(Index index) { - switch (index) { - case 0: - return ClickState::None; - case 1: - return ClickState::Hover; - case 2: - return ClickState::Press; - case 3: - return ClickState::PressInactive; - } - return ClickState::None; -} -} // namespace - -ClickStateConditionEditor::ClickStateConditionEditor() { - SetLabel(u"Click State Condition"); - GetContainer()->AddChild(click_state_select_.GetRootControl()); - - click_state_select_.SetLabel(u"Click State"); - click_state_select_.SetItems(kClickStates); - click_state_select_.SetSelectedIndex(0, false); - - ConnectChangeEvent(click_state_select_); -} - -ClickStateConditionEditor::~ClickStateConditionEditor() {} - -ClonablePtr -ClickStateConditionEditor::GetValue() const { - return ui::style::ClickStateCondition::Create( - ConvertIndexToClickState(click_state_select_.GetSelectedIndex())); -} - -void ClickStateConditionEditor::SetValue(ui::style::ClickStateCondition* value, - bool trigger_change) { - click_state_select_.SetSelectedIndex( - ConvertClickStateToIndex(value->GetClickState()), trigger_change); -} -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/ClickStateConditionEditor.h b/src/theme_builder/components/conditions/ClickStateConditionEditor.h deleted file mode 100644 index 454a1346..00000000 --- a/src/theme_builder/components/conditions/ClickStateConditionEditor.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include "../properties/SelectPropertyEditor.h" -#include "ConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/common/Event.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -class ClickStateConditionEditor : public ConditionEditor { - public: - ClickStateConditionEditor(); - ~ClickStateConditionEditor(); - - public: - ClonablePtr GetValue() const; - void SetValue(ui::style::ClickStateCondition* value, - bool trigger_change = true); - void SetValue(const ClonablePtr& value, - bool trigger_change = true) { - SetValue(value.get(), trigger_change); - } - - ClonablePtr GetCondition() override { - return GetValue(); - } - - private: - properties::SelectPropertyEditor click_state_select_; -}; -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp deleted file mode 100644 index 69b8ed02..00000000 --- a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "CompoundConditionEditor.h" -#include "CheckedConditionEditor.h" -#include "ClickStateConditionEditor.h" -#include "ConditionEditor.h" -#include "FocusConditionEditor.h" -#include "NoConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/platform/Color.h" -#include "cru/ui/Base.h" -#include "cru/ui/ThemeManager.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { - -CompoundConditionEditor::CompoundConditionEditor() { - SetLabel(u"Compound Condition"); - - GetContainer()->AddChild(&children_container_); - children_container_.SetMargin({10, 0, 0, 0}); - children_container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); - children_container_.SetItemCrossAlign( - ui::controls::FlexCrossAlignment::Start); - - GetHeadContainer()->AddChild(add_child_button_.GetRootControl()); - - add_child_button_.GetButton()->GetStyleRuleSet()->SetParent( - ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( - u"cru.theme_builder.icon-button.style")); - add_child_button_.GetButton()->SetIconWithSvgPathDataStringResourceKey( - u"icon.plus", {0, 0, 16, 16}); - add_child_button_.GetButton()->SetPreferredSize({24, 24}); - add_child_button_.GetButton()->SetPadding(ui::Thickness(2)); - add_child_button_.GetButton()->SetIconFillColor(ui::colors::green); - add_child_button_.SetMenuItems({u"And Condition", u"Or Condition", - u"Click State Condition", u"Focus Condition", - u"Checked Condition", u"No Condition"}); - add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) { - std::unique_ptr editor; - switch (index) { - case 0: - editor = std::make_unique(); - break; - case 1: - editor = std::make_unique(); - break; - case 2: - editor = std::make_unique(); - break; - case 3: - editor = std::make_unique(); - break; - case 4: - editor = std::make_unique(); - break; - case 5: - editor = std::make_unique(); - break; - default: - break; - } - if (editor) { - ConnectChangeEvent(editor.get()); - editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { - auto index = this->children_container_.IndexOf(c->GetRootControl()); - this->children_.erase(this->children_.begin() + index); - this->children_container_.RemoveChildAt(index); - RaiseChangeEvent(); - }); - children_.push_back(std::move(editor)); - children_container_.AddChild(children_.back()->GetRootControl()); - RaiseChangeEvent(); - } - }); -} - -CompoundConditionEditor::~CompoundConditionEditor() {} - -std::vector> -CompoundConditionEditor::GetChildren() { - std::vector> children; - for (auto& child : children_) { - children.push_back(child->GetCondition()); - } - return children; -} - -void CompoundConditionEditor::SetChildren( - std::vector> children, - bool trigger_change) { - children_container_.ClearChildren(); - children_.clear(); - for (const auto& condition : children) { - auto editor = CreateConditionEditor(condition.get()); - ConnectChangeEvent(editor.get()); - editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { - auto index = this->children_container_.IndexOf(c->GetRootControl()); - this->children_.erase(this->children_.begin() + index); - this->children_container_.RemoveChildAt(index); - RaiseChangeEvent(); - }); - children_.push_back(std::move(editor)); - children_container_.AddChild(children_.back()->GetRootControl()); - } - if (trigger_change) { - RaiseChangeEvent(); - } -} -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.h b/src/theme_builder/components/conditions/CompoundConditionEditor.h deleted file mode 100644 index e1398514..00000000 --- a/src/theme_builder/components/conditions/CompoundConditionEditor.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once -#include "ConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/common/Event.h" -#include "cru/ui/components/Component.h" -#include "cru/ui/components/PopupButton.h" -#include "cru/ui/controls/Button.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -class CompoundConditionEditor : public ConditionEditor { - public: - CompoundConditionEditor(); - ~CompoundConditionEditor(); - - protected: - std::vector> GetChildren(); - void SetChildren(std::vector> children, - bool trigger_change = true); - - private: - ui::components::PopupMenuIconButton add_child_button_; - ui::controls::FlexLayout children_container_; - std::vector> children_; -}; - -class AndConditionEditor : public CompoundConditionEditor { - public: - AndConditionEditor() = default; - ~AndConditionEditor() override = default; - - public: - ClonablePtr GetValue() { - return ui::style::AndCondition::Create(GetChildren()); - } - void SetValue(ui::style::AndCondition* value, bool trigger_change = true) { - SetChildren(value->GetChildren(), trigger_change); - } - void SetValue(const ClonablePtr& value, - bool trigger_change = true) { - SetValue(value.get(), trigger_change); - } - - ClonablePtr GetCondition() override { - return GetValue(); - } -}; - -class OrConditionEditor : public CompoundConditionEditor { - public: - OrConditionEditor() = default; - ~OrConditionEditor() override = default; - - public: - ClonablePtr GetValue() { - return ui::style::OrCondition::Create(GetChildren()); - } - void SetValue(ui::style::OrCondition* value, bool trigger_change = true) { - SetChildren(value->GetChildren(), trigger_change); - } - void SetValue(const ClonablePtr& value, - bool trigger_change = true) { - SetValue(value.get(), trigger_change); - } - - ClonablePtr GetCondition() override { - return GetValue(); - } -}; -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/ConditionEditor.cpp b/src/theme_builder/components/conditions/ConditionEditor.cpp deleted file mode 100644 index 5b79c639..00000000 --- a/src/theme_builder/components/conditions/ConditionEditor.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "ConditionEditor.h" -#include "../Common.h" -#include "CheckedConditionEditor.h" -#include "ClickStateConditionEditor.h" -#include "CompoundConditionEditor.h" -#include "FocusConditionEditor.h" -#include "NoConditionEditor.h" -#include "cru/common/Exception.h" -#include "cru/ui/controls/FlexLayout.h" - -namespace cru::theme_builder::components::conditions { -ConditionEditor::ConditionEditor() {} - -ConditionEditor::~ConditionEditor() {} - -std::unique_ptr CreateConditionEditor( - ui::style::Condition* condition) { - if (auto and_condition = dynamic_cast(condition)) { - auto result = std::make_unique(); - result->SetValue(and_condition); - return result; - } else if (auto or_condition = - dynamic_cast(condition)) { - auto result = std::make_unique(); - result->SetValue(or_condition); - return result; - } else if (auto no_condition = - dynamic_cast(condition)) { - auto result = std::make_unique(); - return result; - } else if (auto click_state_condition = - dynamic_cast(condition)) { - auto result = std::make_unique(); - result->SetValue(click_state_condition); - return result; - } else if (auto focus_condition = - dynamic_cast(condition)) { - auto result = std::make_unique(); - result->SetValue(focus_condition); - return result; - } else if (auto checked_condition = - dynamic_cast(condition)) { - auto result = std::make_unique(); - result->SetValue(checked_condition); - return result; - } else { - throw Exception(u"Unknown condition type"); - } -} -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/ConditionEditor.h b/src/theme_builder/components/conditions/ConditionEditor.h deleted file mode 100644 index f20132f6..00000000 --- a/src/theme_builder/components/conditions/ConditionEditor.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "../HeadBodyEditor.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -class ConditionEditor : public HeadBodyEditor { - public: - ConditionEditor(); - ~ConditionEditor() override; - - public: - virtual ClonablePtr GetCondition() = 0; -}; - -std::unique_ptr CreateConditionEditor( - ui::style::Condition* condition); -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/FocusConditionEditor.cpp b/src/theme_builder/components/conditions/FocusConditionEditor.cpp deleted file mode 100644 index 1fb99d64..00000000 --- a/src/theme_builder/components/conditions/FocusConditionEditor.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "FocusConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -FocusConditionEditor::FocusConditionEditor() { - SetLabel(u"Focus Condition"); - GetContainer()->AddChild(focus_check_box_.GetRootControl()); - - focus_check_box_.SetLabel(u"Focus"); - - ConnectChangeEvent(focus_check_box_); -} - -FocusConditionEditor::~FocusConditionEditor() {} - -ClonablePtr FocusConditionEditor::GetValue() const { - return ui::style::FocusCondition::Create(focus_check_box_.GetValue()); -} - -void FocusConditionEditor::SetValue(ui::style::FocusCondition* value, - bool trigger_change) { - focus_check_box_.SetValue(value->IsHasFocus(), trigger_change); -} -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/FocusConditionEditor.h b/src/theme_builder/components/conditions/FocusConditionEditor.h deleted file mode 100644 index 1faf4d7d..00000000 --- a/src/theme_builder/components/conditions/FocusConditionEditor.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include "../properties/CheckBoxPropertyEditor.h" -#include "ConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -class FocusConditionEditor : public ConditionEditor { - public: - FocusConditionEditor(); - ~FocusConditionEditor() override; - - public: - ClonablePtr GetValue() const; - void SetValue(ui::style::FocusCondition* value, bool trigger_change = true); - void SetValue(const ClonablePtr& value, - bool trigger_change = true) { - SetValue(value.get(), trigger_change); - } - - ClonablePtr GetCondition() override { - return GetValue(); - } - - private: - properties::CheckBoxPropertyEditor focus_check_box_; -}; -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/NoConditionEditor.cpp b/src/theme_builder/components/conditions/NoConditionEditor.cpp deleted file mode 100644 index a5087159..00000000 --- a/src/theme_builder/components/conditions/NoConditionEditor.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "NoConditionEditor.h" - -namespace cru::theme_builder::components::conditions { -NoConditionEditor::NoConditionEditor() { SetLabel(u"No condition"); } - -NoConditionEditor::~NoConditionEditor() {} -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/NoConditionEditor.h b/src/theme_builder/components/conditions/NoConditionEditor.h deleted file mode 100644 index 19616319..00000000 --- a/src/theme_builder/components/conditions/NoConditionEditor.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "ConditionEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Condition.h" - -namespace cru::theme_builder::components::conditions { -class NoConditionEditor : public ConditionEditor { - public: - NoConditionEditor(); - ~NoConditionEditor() override; - - public: - ClonablePtr GetCondition() override { - return ui::style::NoCondition::Create(); - } -}; -} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp b/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp deleted file mode 100644 index fb6f4705..00000000 --- a/src/theme_builder/components/properties/CheckBoxPropertyEditor.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#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] { RaiseChangeEvent(); }); -} - -CheckBoxPropertyEditor::~CheckBoxPropertyEditor() {} - -void CheckBoxPropertyEditor::SetValue(bool value, bool trigger_change) { - 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 deleted file mode 100644 index f78ed6c9..00000000 --- a/src/theme_builder/components/properties/CheckBoxPropertyEditor.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "cru/ui/controls/CheckBox.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" - -namespace cru::theme_builder::components::properties { -class CheckBoxPropertyEditor : public Editor { - 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); - - private: - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::controls::CheckBox check_box_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.cpp b/src/theme_builder/components/properties/ColorPropertyEditor.cpp deleted file mode 100644 index e9e486ac..00000000 --- a/src/theme_builder/components/properties/ColorPropertyEditor.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#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() { - container_.AddChild(&label_); - 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()); - color_text_.SetMargin(ui::Thickness(10, 0, 0, 0)); - - color_text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { - auto text = color_text_.GetTextView(); - auto color = ui::Color::Parse(text); - if (color) { - color_ = *color; - color_cube_brush_->SetColor(*color); - is_color_text_valid_ = true; - RaiseChangeEvent(); - } else { - is_color_text_valid_ = false; - // TODO: Show error! - } - }); -} - -ColorPropertyEditor::~ColorPropertyEditor() {} - -void ColorPropertyEditor::SetValue(const ui::Color &color, - bool trigger_change) { - if (!trigger_change) SuppressNextChangeEvent(); - color_text_.SetText(color.ToString()); -} -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/ColorPropertyEditor.h b/src/theme_builder/components/properties/ColorPropertyEditor.h deleted file mode 100644 index aa6cfcfa..00000000 --- a/src/theme_builder/components/properties/ColorPropertyEditor.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "cru/platform/graphics/Base.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 Editor { - public: - using PropertyType = ui::Color; - - ColorPropertyEditor(); - ~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)); } - - ui::Color GetValue() const { return color_; } - void SetValue(const ui::Color& color, bool trigger_change = true); - - private: - ui::Color color_ = ui::colors::transparent; - - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::controls::Container color_cube_; - std::shared_ptr color_cube_brush_; - ui::controls::TextBox color_text_; - bool is_color_text_valid_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp b/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp deleted file mode 100644 index fc86b0ed..00000000 --- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "CornerRadiusPropertyEditor.h" -#include "cru/ui/Base.h" -#include "cru/ui/controls/FlexLayout.h" - -namespace cru::theme_builder::components::properties { -CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() { - container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start); - - left_top_editor_.SetLabel(u"⌜"); - right_top_editor_.SetLabel(u"⌝"); - left_bottom_editor_.SetLabel(u"⌞"); - right_bottom_editor_.SetLabel(u"⌟"); - - container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); - container_.AddChild(left_top_editor_.GetRootControl()); - container_.AddChild(right_top_editor_.GetRootControl()); - container_.AddChild(left_bottom_editor_.GetRootControl()); - container_.AddChild(right_bottom_editor_.GetRootControl()); - - 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) 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 deleted file mode 100644 index 6b6833d1..00000000 --- a/src/theme_builder/components/properties/CornerRadiusPropertyEditor.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "PointPropertyEditor.h" -#include "cru/ui/Base.h" -#include "cru/ui/controls/FlexLayout.h" - -namespace cru::theme_builder::components::properties { -class CornerRadiusPropertyEditor : public Editor { - public: - using PropertyType = ui::CornerRadius; - - CornerRadiusPropertyEditor(); - ~CornerRadiusPropertyEditor() override; - - ui::controls::Control* GetRootControl() override { return &container_; } - - ui::CornerRadius GetValue() const; - void SetValue(const ui::CornerRadius& corner_radius, - bool trigger_change = true); - - private: - ui::controls::FlexLayout container_; - PointPropertyEditor left_top_editor_; - PointPropertyEditor right_top_editor_; - PointPropertyEditor left_bottom_editor_; - PointPropertyEditor right_bottom_editor_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/FontPropertyEditor.cpp b/src/theme_builder/components/properties/FontPropertyEditor.cpp deleted file mode 100644 index 927ada7d..00000000 --- a/src/theme_builder/components/properties/FontPropertyEditor.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "FontPropertyEditor.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/graphics/Font.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/render/FlexLayoutRenderObject.h" - -namespace cru::theme_builder::components::properties { -using namespace cru::ui::controls; - -FontPropertyEditor::FontPropertyEditor() { - main_container_.SetFlexDirection(FlexDirection::Horizontal); - main_container_.AddChild(&label_); - main_container_.AddChild(&right_container_); - - right_container_.SetFlexDirection(FlexDirection::Vertical); - right_container_.AddChild(&font_family_container_); - right_container_.AddChild(&font_size_container_); - - font_family_container_.SetFlexDirection(FlexDirection::Horizontal); - font_family_container_.AddChild(&font_family_label_); - font_family_container_.AddChild(&font_family_text_); - font_family_label_.SetText(u"Font Family"); - - font_size_container_.SetFlexDirection(FlexDirection::Horizontal); - font_size_container_.AddChild(&font_size_label_); - font_size_container_.AddChild(font_size_input_.GetRootControl()); - font_size_label_.SetText(u"Font Size"); - font_size_input_.SetMin(0.0f); - - font_family_text_.TextChangeEvent()->AddSpyOnlyHandler( - [this] { RaiseChangeEvent(); }); - - font_size_input_.ChangeEvent()->AddSpyOnlyHandler( - [this] { RaiseChangeEvent(); }); -} - -FontPropertyEditor::~FontPropertyEditor() {} - -Control* FontPropertyEditor::GetRootControl() { return &main_container_; } - -std::shared_ptr FontPropertyEditor::GetValue() - const { - return platform::gui::IUiApplication::GetInstance() - ->GetGraphicsFactory() - ->CreateFont(font_family_text_.GetText(), font_size_input_.GetValue()); -} - -void FontPropertyEditor::SetValue( - std::shared_ptr value, bool trigger_change) { - SuppressNextChangeEvent(); - font_family_text_.SetText(value->GetFontName()); - SuppressNextChangeEvent(); - font_size_input_.SetValue(value->GetFontSize()); - - if (trigger_change) { - RaiseChangeEvent(); - } -} -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/FontPropertyEditor.h b/src/theme_builder/components/properties/FontPropertyEditor.h deleted file mode 100644 index d349f1f2..00000000 --- a/src/theme_builder/components/properties/FontPropertyEditor.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "cru/platform/graphics/Font.h" -#include "cru/ui/components/Input.h" -#include "cru/ui/controls/Control.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 FontPropertyEditor : public Editor { - public: - using PropertyType = std::shared_ptr; - - FontPropertyEditor(); - ~FontPropertyEditor() override; - - ui::controls::Control* GetRootControl() override; - - String GetLabelText() const { return label_.GetText(); } - void SetLabelText(String label) { label_.SetText(std::move(label)); } - - std::shared_ptr GetValue() const; - void SetValue(std::shared_ptr value, - bool trigger_change = true); - - private: - ui::controls::FlexLayout main_container_; - ui::controls::TextBlock label_; - ui::controls::FlexLayout right_container_; - ui::controls::FlexLayout font_family_container_; - ui::controls::TextBlock font_family_label_; - ui::controls::TextBox font_family_text_; - ui::controls::FlexLayout font_size_container_; - ui::controls::TextBlock font_size_label_; - ui::components::FloatInput font_size_input_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp b/src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp deleted file mode 100644 index d1f4afce..00000000 --- a/src/theme_builder/components/properties/MeasureLengthPropertyEditor.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "MeasureLengthPropertyEditor.h" -#include "cru/common/Format.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/render/MeasureRequirement.h" - -namespace cru::theme_builder::components::properties { -MeasureLengthPropertyEditor::MeasureLengthPropertyEditor() { - container_.AddChild(&label_); - container_.AddChild(&text_); - - text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { - auto text = text_.GetTextView(); - auto measure_length_mapper = ui::mapper::MapperRegistry::GetInstance() - ->GetMapper(); - try { - auto measure_length = - measure_length_mapper->MapFromString(text.ToString()); - measure_length_ = measure_length; - is_text_valid_ = true; - RaiseChangeEvent(); - } catch (const Exception&) { - is_text_valid_ = false; - // TODO: Show error! - } - }); -} - -MeasureLengthPropertyEditor::~MeasureLengthPropertyEditor() {} - -void MeasureLengthPropertyEditor::SetValue( - const ui::render::MeasureLength& value, bool trigger_change) { - if (!trigger_change) SuppressNextChangeEvent(); - text_.SetText(measure_length_.IsNotSpecified() - ? u"unspecified" - : ToString(measure_length_.GetLengthOrUndefined())); -} -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/MeasureLengthPropertyEditor.h b/src/theme_builder/components/properties/MeasureLengthPropertyEditor.h deleted file mode 100644 index 43e783c5..00000000 --- a/src/theme_builder/components/properties/MeasureLengthPropertyEditor.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "cru/platform/graphics/Base.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" -#include "cru/ui/render/MeasureRequirement.h" - -namespace cru::theme_builder::components::properties { -class MeasureLengthPropertyEditor : public Editor { - public: - using PropertyType = ui::render::MeasureLength; - - MeasureLengthPropertyEditor(); - ~MeasureLengthPropertyEditor() override; - - public: - ui::controls::Control* GetRootControl() override { return &container_; } - - String GetLabel() const { return label_.GetText(); } - void SetLabel(String label) { label_.SetText(std::move(label)); } - - PropertyType GetValue() const { return measure_length_; } - void SetValue(const PropertyType& value, bool trigger_change = true); - - private: - PropertyType measure_length_; - - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::controls::TextBox text_; - bool is_text_valid_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/OptionalPropertyEditor.h b/src/theme_builder/components/properties/OptionalPropertyEditor.h deleted file mode 100644 index 0f22616a..00000000 --- a/src/theme_builder/components/properties/OptionalPropertyEditor.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "cru/ui/controls/CheckBox.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/controls/TextBlock.h" - -#include - -namespace cru::theme_builder::components::properties { -template -class OptionalPropertyEditor : public Editor { - public: - using PropertyType = typename TEditor::PropertyType; - - OptionalPropertyEditor() { - container_.AddChild(&label_); - container_.AddChild(&check_box_); - check_box_.SetMargin({0, 0, 10, 0}); - container_.AddChild(editor_.GetRootControl()); - - editor_.ChangeEvent()->AddHandler([this](std::nullptr_t) { - if (IsEnabled()) { - RaiseChangeEvent(); - } - }); - } - ~OptionalPropertyEditor() override {} - - ui::controls::Control* GetRootControl() override { return &container_; } - - String GetLabel() const { return label_.GetText(); } - void SetLabel(String label) { label_.SetText(std::move(label)); } - - bool IsEnabled() const { return check_box_.IsChecked(); } - void SetEnabled(bool enabled, bool trigger_change = true) { - check_box_.SetChecked(enabled); - if (trigger_change) { - RaiseChangeEvent(); - } - } - - std::optional GetValue() const { - return IsEnabled() ? std::optional(editor_.GetValue()) - : std::nullopt; - } - - void SetValue(std::optional value, bool trigger_change = true) { - if (value) { - SetEnabled(true, false); - editor_.SetValue(*value, false); - if (trigger_change) RaiseChangeEvent(); - } else { - SetEnabled(false, trigger_change); - } - } - - TEditor* GetEditor() { return &editor_; } - - private: - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::controls::CheckBox check_box_; - TEditor editor_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/PointPropertyEditor.cpp b/src/theme_builder/components/properties/PointPropertyEditor.cpp deleted file mode 100644 index 6d4277aa..00000000 --- a/src/theme_builder/components/properties/PointPropertyEditor.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "PointPropertyEditor.h" -#include "cru/common/Format.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/mapper/PointMapper.h" - -namespace cru::theme_builder::components::properties { -PointPropertyEditor::PointPropertyEditor() { - container_.AddChild(&label_); - container_.AddChild(&text_); - - text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { - auto text = text_.GetTextView(); - auto point_mapper = - ui::mapper::MapperRegistry::GetInstance()->GetMapper(); - 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! - } - }); -} - -PointPropertyEditor::~PointPropertyEditor() {} - -void PointPropertyEditor::SetValue(const ui::Point& point, - bool trigger_change) { - if (!trigger_change) SuppressNextChangeEvent(); - text_.SetText(ConvertPointToString(point)); -} - -String PointPropertyEditor::ConvertPointToString(const ui::Point& point) { - return Format(u"{} {}", point.x, point.y); -} -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/PointPropertyEditor.h b/src/theme_builder/components/properties/PointPropertyEditor.h deleted file mode 100644 index bd852e3a..00000000 --- a/src/theme_builder/components/properties/PointPropertyEditor.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#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 Editor { - public: - using PropertyType = ui::Point; - - PointPropertyEditor(); - ~PointPropertyEditor() override; - - public: - ui::controls::Control* GetRootControl() override { return &container_; } - - String GetLabel() const { return label_.GetText(); } - void SetLabel(String label) { label_.SetText(std::move(label)); } - - ui::Point GetValue() const { return point_; } - void SetValue(const ui::Point& point, bool trigger_change = true); - - private: - static String ConvertPointToString(const ui::Point& point); - - private: - ui::Point point_; - - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::controls::TextBox text_; - bool is_text_valid_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.cpp b/src/theme_builder/components/properties/SelectPropertyEditor.cpp deleted file mode 100644 index 835b2d12..00000000 --- a/src/theme_builder/components/properties/SelectPropertyEditor.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "SelectPropertyEditor.h" -#include "cru/ui/controls/FlexLayout.h" - -namespace cru::theme_builder::components::properties { -SelectPropertyEditor::SelectPropertyEditor() { - container_.SetFlexDirection(ui::controls::FlexDirection::Horizontal); - container_.AddChild(&label_); - container_.AddChild(select_.GetRootControl()); - - 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 deleted file mode 100644 index 475d2d0a..00000000 --- a/src/theme_builder/components/properties/SelectPropertyEditor.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#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 Editor { - public: - using PropertyType = Index; - - SelectPropertyEditor(); - ~SelectPropertyEditor() override; - - public: - ui::controls::Control* GetRootControl() override { return &container_; } - - String GetLabel() const { return label_.GetText(); } - void SetLabel(String label) { label_.SetText(std::move(label)); } - - Index GetSelectedIndex() const { return select_.GetSelectedIndex(); } - void SetSelectedIndex(Index index, bool trigger_change = true) { - if (trigger_change == false) SuppressNextChangeEvent(); - select_.SetSelectedIndex(index); - } - - std::vector GetItems() const { return select_.GetItems(); } - void SetItems(std::vector items) { - select_.SetItems(std::move(items)); - } - - Index GetValue() const { return GetSelectedIndex(); } - void SetValue(Index value, bool trigger_change = true) { - SetSelectedIndex(value, trigger_change); - } - - private: - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::components::Select select_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/TextPropertyEditor.cpp b/src/theme_builder/components/properties/TextPropertyEditor.cpp deleted file mode 100644 index 9854019c..00000000 --- a/src/theme_builder/components/properties/TextPropertyEditor.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "TextPropertyEditor.h" - -namespace cru::theme_builder::components::properties { -TextPropertyEditor::TextPropertyEditor() { - editor_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { - auto text_view = editor_.GetTextView(); - String error_message; - auto validation_result = Validate(text_view, &error_message); - if (validation_result) { - OnTextChanged(text_view); - } - }); -} - -TextPropertyEditor::~TextPropertyEditor() {} - -bool TextPropertyEditor::Validate(StringView text, String* error_message) { - return true; -} - -void TextPropertyEditor::OnTextChanged(StringView text) {} -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/TextPropertyEditor.h b/src/theme_builder/components/properties/TextPropertyEditor.h deleted file mode 100644 index c4944228..00000000 --- a/src/theme_builder/components/properties/TextPropertyEditor.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "cru/ui/components/Component.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 TextPropertyEditor : public ui::components::Component { - public: - TextPropertyEditor(); - ~TextPropertyEditor() override; - - ui::controls::Control* GetRootControl() override { return &container_; } - - String GetLabel() const { return label_.GetText(); } - void SetLabel(String label) { label_.SetText(std::move(label)); } - - String GetText() const { return editor_.GetText(); } - StringView GetTextView() const { return editor_.GetTextView(); } - void SetText(String text) { editor_.SetText(std::move(text)); } - - protected: - virtual bool Validate(StringView text, String* error_message); - virtual void OnTextChanged(StringView text); - - private: - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::controls::TextBox editor_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp b/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp deleted file mode 100644 index 3e022bb1..00000000 --- a/src/theme_builder/components/properties/ThicknessPropertyEditor.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "ThicknessPropertyEditor.h" -#include "cru/ui/mapper/MapperRegistry.h" -#include "cru/ui/mapper/ThicknessMapper.h" - -namespace cru::theme_builder::components::properties { -ThicknessPropertyEditor::ThicknessPropertyEditor() { - container_.AddChild(&label_); - container_.AddChild(&text_); - - text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) { - auto text = text_.GetText(); - auto thickness_mapper = - ui::mapper::MapperRegistry::GetInstance()->GetMapper(); - try { - auto thickness = thickness_mapper->MapFromString(text); - thickness_ = thickness; - is_text_valid_ = true; - RaiseChangeEvent(); - } catch (const Exception &) { - is_text_valid_ = false; - // TODO: Show error! - } - }); -} - -ThicknessPropertyEditor::~ThicknessPropertyEditor() {} - -void ThicknessPropertyEditor::SetValue(const ui::Thickness &thickness, - bool trigger_change) { - 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 deleted file mode 100644 index cea9ae9d..00000000 --- a/src/theme_builder/components/properties/ThicknessPropertyEditor.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#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 Editor { - public: - using PropertyType = ui::Thickness; - - ThicknessPropertyEditor(); - ~ThicknessPropertyEditor() override; - - ui::controls::Control* GetRootControl() override { return &container_; } - - String GetLabel() const { return label_.GetText(); } - void SetLabel(String label) { label_.SetText(std::move(label)); } - - ui::Thickness GetValue() const { return thickness_; } - void SetValue(const ui::Thickness& thickness, bool trigger_change = true); - - private: - ui::Thickness thickness_; - - ui::controls::FlexLayout container_; - ui::controls::TextBlock label_; - ui::controls::TextBox text_; - bool is_text_valid_; -}; -} // namespace cru::theme_builder::components::properties diff --git a/src/theme_builder/components/stylers/BorderStylerEditor.cpp b/src/theme_builder/components/stylers/BorderStylerEditor.cpp deleted file mode 100644 index 81eb66d3..00000000 --- a/src/theme_builder/components/stylers/BorderStylerEditor.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "BorderStylerEditor.h" -#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::stylers { -BorderStylerEditor::BorderStylerEditor() { - SetLabel(u"Border Styler"); - GetContainer()->AddChild(corner_radius_editor_.GetRootControl()); - GetContainer()->AddChild(thickness_editor_.GetRootControl()); - GetContainer()->AddChild(brush_editor_.GetRootControl()); - GetContainer()->AddChild(foreground_brush_editor_.GetRootControl()); - GetContainer()->AddChild(background_brush_editor_.GetRootControl()); - - thickness_editor_.GetEditor()->SetLabel(u"Thickness"); - brush_editor_.GetEditor()->SetLabel(u"Border"); - foreground_brush_editor_.GetEditor()->SetLabel(u"Foreground"); - background_brush_editor_.GetEditor()->SetLabel(u"Background"); - - ConnectChangeEvent(corner_radius_editor_); - ConnectChangeEvent(thickness_editor_); - ConnectChangeEvent(brush_editor_); - ConnectChangeEvent(foreground_brush_editor_); - ConnectChangeEvent(background_brush_editor_); -} - -BorderStylerEditor::~BorderStylerEditor() {} - -ClonablePtr BorderStylerEditor::GetValue() { - auto graphics_factory = - platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory(); - - ui::style::ApplyBorderStyleInfo border_style; - border_style.border_radius = corner_radius_editor_.GetValue(); - border_style.border_thickness = thickness_editor_.GetValue(); - - if (brush_editor_.IsEnabled()) { - border_style.border_brush = graphics_factory->CreateSolidColorBrush( - brush_editor_.GetEditor()->GetValue()); - } - - if (foreground_brush_editor_.IsEnabled()) { - border_style.foreground_brush = graphics_factory->CreateSolidColorBrush( - foreground_brush_editor_.GetEditor()->GetValue()); - } - - if (background_brush_editor_.IsEnabled()) { - border_style.background_brush = graphics_factory->CreateSolidColorBrush( - background_brush_editor_.GetEditor()->GetValue()); - } - - return ui::style::BorderStyler::Create(border_style); -} - -void BorderStylerEditor::SetValue(ui::style::BorderStyler* styler, - bool trigger_change) { - Expects(styler); - - auto border_style = styler->GetBorderStyle(); - corner_radius_editor_.SetValue(border_style.border_radius, false); - thickness_editor_.SetValue(border_style.border_thickness, false); - - brush_editor_.SetEnabled(border_style.border_brush.has_value(), false); - if (border_style.border_brush.has_value()) { - brush_editor_.GetEditor()->SetValue( - std::dynamic_pointer_cast( - border_style.border_brush.value()) - ->GetColor(), - false); - } - - foreground_brush_editor_.SetEnabled(border_style.foreground_brush.has_value(), - false); - if (border_style.foreground_brush.has_value()) { - foreground_brush_editor_.GetEditor()->SetValue( - std::dynamic_pointer_cast( - border_style.foreground_brush.value()) - ->GetColor(), - false); - } - - background_brush_editor_.SetEnabled(border_style.background_brush.has_value(), - false); - if (border_style.background_brush.has_value()) { - background_brush_editor_.GetEditor()->SetValue( - std::dynamic_pointer_cast( - border_style.background_brush.value()) - ->GetColor(), - false); - } - - if (trigger_change) { - RaiseChangeEvent(); - } -} - -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/BorderStylerEditor.h b/src/theme_builder/components/stylers/BorderStylerEditor.h deleted file mode 100644 index 539262d6..00000000 --- a/src/theme_builder/components/stylers/BorderStylerEditor.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include "../properties/ColorPropertyEditor.h" -#include "../properties/CornerRadiusPropertyEditor.h" -#include "../properties/OptionalPropertyEditor.h" -#include "../properties/ThicknessPropertyEditor.h" -#include "StylerEditor.h" -#include "cru/common/ClonablePtr.h" - -namespace cru::theme_builder::components::stylers { -class BorderStylerEditor : public StylerEditor { - public: - BorderStylerEditor(); - ~BorderStylerEditor() override; - - ClonablePtr GetValue(); - void SetValue(ui::style::BorderStyler* styler, bool trigger_change = true); - void SetValue(const ClonablePtr& styler, - bool trigger_change = true) { - SetValue(styler.get(), trigger_change); - } - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - properties::OptionalPropertyEditor - corner_radius_editor_; - properties::OptionalPropertyEditor - thickness_editor_; - properties::OptionalPropertyEditor - brush_editor_; - properties::OptionalPropertyEditor - foreground_brush_editor_; - properties::OptionalPropertyEditor - background_brush_editor_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp deleted file mode 100644 index 6b8a5033..00000000 --- a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "CompoundStylerEditor.h" -#include "BorderStylerEditor.h" -#include "ContentBrushStylerEditor.h" -#include "CursorStylerEditor.h" -#include "FontStylerEditor.h" -#include "MarginStylerEditor.h" -#include "PaddingStylerEditor.h" -#include "PreferredSizeStylerEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/ThemeManager.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -CompoundStylerEditor::CompoundStylerEditor() { - SetLabel(u"Compound Styler"); - GetContainer()->AddChild(&children_container_); - children_container_.SetFlexDirection(ui::controls::FlexDirection::Vertical); - children_container_.SetItemCrossAlign( - ui::controls::FlexCrossAlignment::Start); - - GetHeadContainer()->AddChild(add_child_button_.GetRootControl()); - add_child_button_.GetButton()->GetStyleRuleSet()->SetParent( - ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet( - u"cru.theme_builder.icon-button.style")); - add_child_button_.GetButton()->SetIconWithSvgPathDataStringResourceKey( - u"icon.plus", {0, 0, 16, 16}); - add_child_button_.GetButton()->SetPreferredSize({24, 24}); - add_child_button_.GetButton()->SetPadding(ui::Thickness(2)); - add_child_button_.GetButton()->SetIconFillColor(ui::colors::green); - add_child_button_.SetMenuItems({u"Compound Styler", u"Border Styler", - u"Cursor Styler", u"Content Brush Styler", - u"Font Styler", u"Margin Styler", - u"Padding Styler", u"Preferred Size Styler"}); - add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) { - std::unique_ptr editor; - switch (index) { - case 0: - editor = std::make_unique(); - break; - case 1: - editor = std::make_unique(); - break; - case 2: - editor = std::make_unique(); - break; - case 3: - editor = std::make_unique(); - break; - case 4: - editor = std::make_unique(); - break; - case 5: - editor = std::make_unique(); - break; - case 6: - editor = std::make_unique(); - break; - case 7: - editor = std::make_unique(); - break; - default: - break; - } - if (editor) { - ConnectChangeEvent(editor.get()); - editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { - auto index = this->children_container_.IndexOf(c->GetRootControl()); - this->children_.erase(this->children_.begin() + index); - this->children_container_.RemoveChildAt(index); - RaiseChangeEvent(); - }); - children_.push_back(std::move(editor)); - children_container_.AddChild(editor->GetRootControl()); - RaiseChangeEvent(); - } - }); -} - -CompoundStylerEditor::~CompoundStylerEditor() {} - -ClonablePtr CompoundStylerEditor::GetValue() { - std::vector> children_styler; - for (auto& child : children_) { - children_styler.push_back(child->GetStyler()); - } - return ui::style::CompoundStyler::Create(std::move(children_styler)); -} - -void CompoundStylerEditor::SetValue(ui::style::CompoundStyler* value, - bool trigger_change) { - children_.clear(); - for (const auto& styler : value->GetChildren()) { - auto editor = CreateStylerEditor(styler.get()); - ConnectChangeEvent(editor.get()); - editor->RemoveEvent()->AddSpyOnlyHandler([this, c = editor.get()] { - auto index = this->children_container_.IndexOf(c->GetRootControl()); - this->children_.erase(this->children_.begin() + index); - this->children_container_.RemoveChildAt(index); - RaiseChangeEvent(); - }); - children_.push_back(std::move(editor)); - children_container_.AddChild(children_.back()->GetRootControl()); - } -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.h b/src/theme_builder/components/stylers/CompoundStylerEditor.h deleted file mode 100644 index 57150e83..00000000 --- a/src/theme_builder/components/stylers/CompoundStylerEditor.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include "StylerEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/DeleteLater.h" -#include "cru/ui/components/PopupButton.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -class CompoundStylerEditor : public StylerEditor { - public: - CompoundStylerEditor(); - ~CompoundStylerEditor() override; - - public: - ClonablePtr GetValue(); - void SetValue(ui::style::CompoundStyler* styler, bool trigger_change = true); - void SetValue(const ClonablePtr& styler, - bool trigger_change = true) { - SetValue(styler.get(), trigger_change); - } - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - ui::controls::FlexLayout children_container_; - std::vector> children_; - ui::components::PopupMenuIconButton add_child_button_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/ContentBrushStylerEditor.cpp b/src/theme_builder/components/stylers/ContentBrushStylerEditor.cpp deleted file mode 100644 index bd649c67..00000000 --- a/src/theme_builder/components/stylers/ContentBrushStylerEditor.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "ContentBrushStylerEditor.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -ContentBrushStylerEditor::ContentBrushStylerEditor() { - GetContainer()->AddChild(color_editor_.GetRootControl()); - - ConnectChangeEvent(color_editor_); -} - -ContentBrushStylerEditor::~ContentBrushStylerEditor() {} - -ClonablePtr ContentBrushStylerEditor::GetValue() - const { - return ui::style::ContentBrushStyler::Create( - platform::gui::IUiApplication::GetInstance() - ->GetGraphicsFactory() - ->CreateSolidColorBrush(color_editor_.GetValue())); -} - -void ContentBrushStylerEditor::SetValue(ui::style::ContentBrushStyler* value, - bool trigger_change) { - color_editor_.SetValue( - std::dynamic_pointer_cast( - value->GetBrush()) - ->GetColor(), - trigger_change); -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/ContentBrushStylerEditor.h b/src/theme_builder/components/stylers/ContentBrushStylerEditor.h deleted file mode 100644 index 8385b7c3..00000000 --- a/src/theme_builder/components/stylers/ContentBrushStylerEditor.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "../properties/ColorPropertyEditor.h" -#include "StylerEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -class ContentBrushStylerEditor : public StylerEditor { - public: - ContentBrushStylerEditor(); - ~ContentBrushStylerEditor(); - - public: - ClonablePtr GetValue() const; - void SetValue(ui::style::ContentBrushStyler* value, - bool trigger_change = true); - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - properties::ColorPropertyEditor color_editor_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/CursorStylerEditor.cpp b/src/theme_builder/components/stylers/CursorStylerEditor.cpp deleted file mode 100644 index 9984d81a..00000000 --- a/src/theme_builder/components/stylers/CursorStylerEditor.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "CursorStylerEditor.h" -#include "cru/platform/gui/Cursor.h" -#include "cru/platform/gui/UiApplication.h" - -namespace cru::theme_builder::components::stylers { -CursorStylerEditor::CursorStylerEditor() { - SetLabel(u"Cursor Styler"); - GetContainer()->AddChild(cursor_select_.GetRootControl()); - - cursor_select_.SetLabel(u"Cursor"); - cursor_select_.SetItems({u"arrow", u"hand", u"ibeam"}); - cursor_select_.SetSelectedIndex(0); - - ConnectChangeEvent(cursor_select_); -} - -CursorStylerEditor::~CursorStylerEditor() {} - -ClonablePtr CursorStylerEditor::GetValue() { - auto cursor_manager = - platform::gui::IUiApplication::GetInstance()->GetCursorManager(); - - std::shared_ptr cursor; - - switch (cursor_select_.GetSelectedIndex()) { - case 0: - cursor = cursor_manager->GetSystemCursor( - platform::gui::SystemCursorType::Arrow); - break; - case 1: - cursor = cursor_manager->GetSystemCursor( - platform::gui::SystemCursorType::Hand); - break; - case 2: - cursor = cursor_manager->GetSystemCursor( - platform::gui::SystemCursorType::IBeam); - break; - } - - return ui::style::CursorStyler::Create(cursor); -} - -void CursorStylerEditor::SetValue(ui::style::CursorStyler* styler, - bool trigger_change) { - auto cursor_manager = - platform::gui::IUiApplication::GetInstance()->GetCursorManager(); - - auto cursor = styler->GetCursor(); - - if (cursor == - cursor_manager->GetSystemCursor(platform::gui::SystemCursorType::Arrow)) { - cursor_select_.SetSelectedIndex(0); - } else if (cursor == cursor_manager->GetSystemCursor( - platform::gui::SystemCursorType::Hand)) { - cursor_select_.SetSelectedIndex(1); - } else if (cursor == cursor_manager->GetSystemCursor( - platform::gui::SystemCursorType::IBeam)) { - cursor_select_.SetSelectedIndex(2); - } - - if (trigger_change) { - RaiseChangeEvent(); - } -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/CursorStylerEditor.h b/src/theme_builder/components/stylers/CursorStylerEditor.h deleted file mode 100644 index 552619a0..00000000 --- a/src/theme_builder/components/stylers/CursorStylerEditor.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "../properties/SelectPropertyEditor.h" -#include "StylerEditor.h" - -namespace cru::theme_builder::components::stylers { -class CursorStylerEditor : public StylerEditor { - public: - CursorStylerEditor(); - ~CursorStylerEditor() override; - - public: - ClonablePtr GetValue(); - void SetValue(ui::style::CursorStyler* styler, bool trigger_change = true); - void SetValue(const ClonablePtr& styler, - bool trigger_change = true) { - SetValue(styler.get(), trigger_change); - } - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - properties::SelectPropertyEditor cursor_select_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/FontStylerEditor.cpp b/src/theme_builder/components/stylers/FontStylerEditor.cpp deleted file mode 100644 index 9787a4fd..00000000 --- a/src/theme_builder/components/stylers/FontStylerEditor.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "FontStylerEditor.h" -#include "cru/platform/graphics/Factory.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -FontStylerEditor::FontStylerEditor() { - GetContainer()->AddChild(font_editor_.GetRootControl()); - - ConnectChangeEvent(font_editor_); -} - -FontStylerEditor::~FontStylerEditor() {} - -ClonablePtr FontStylerEditor::GetValue() const { - return ui::style::FontStyler::Create(font_editor_.GetValue()); -} - -void FontStylerEditor::SetValue(ui::style::FontStyler* value, - bool trigger_change) { - font_editor_.SetValue(value->GetFont(), trigger_change); -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/FontStylerEditor.h b/src/theme_builder/components/stylers/FontStylerEditor.h deleted file mode 100644 index ccd12113..00000000 --- a/src/theme_builder/components/stylers/FontStylerEditor.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "../Editor.h" -#include "../properties/FontPropertyEditor.h" -#include "StylerEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -class FontStylerEditor : public StylerEditor { - public: - FontStylerEditor(); - ~FontStylerEditor(); - - public: - ClonablePtr GetValue() const; - void SetValue(ui::style::FontStyler* value, bool trigger_change = true); - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - properties::FontPropertyEditor font_editor_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/MarginStylerEditor.cpp b/src/theme_builder/components/stylers/MarginStylerEditor.cpp deleted file mode 100644 index d7d89acb..00000000 --- a/src/theme_builder/components/stylers/MarginStylerEditor.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "MarginStylerEditor.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -MarginStylerEditor::MarginStylerEditor() { - SetLabel(u"Margin Styler"); - GetContainer()->AddChild(thickness_editor_.GetRootControl()); - - thickness_editor_.SetLabel(u"Thickness"); - - ConnectChangeEvent(thickness_editor_); -} - -MarginStylerEditor::~MarginStylerEditor() {} - -ClonablePtr MarginStylerEditor::GetValue() { - return ui::style::MarginStyler::Create(thickness_editor_.GetValue()); -} - -void MarginStylerEditor::SetValue(ui::style::MarginStyler* styler, - bool trigger_change) { - thickness_editor_.SetValue(styler->GetMargin(), false); - - if (trigger_change) { - RaiseChangeEvent(); - } -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/MarginStylerEditor.h b/src/theme_builder/components/stylers/MarginStylerEditor.h deleted file mode 100644 index 9de6f1a2..00000000 --- a/src/theme_builder/components/stylers/MarginStylerEditor.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "../properties/ThicknessPropertyEditor.h" -#include "StylerEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -class MarginStylerEditor : public StylerEditor { - public: - MarginStylerEditor(); - ~MarginStylerEditor() override; - - ClonablePtr GetValue(); - void SetValue(ui::style::MarginStyler* styler, bool trigger_change = true); - void SetValue(const ClonablePtr& styler, - bool trigger_change = true) { - SetValue(styler.get(), trigger_change); - } - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - properties::ThicknessPropertyEditor thickness_editor_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/PaddingStylerEditor.cpp b/src/theme_builder/components/stylers/PaddingStylerEditor.cpp deleted file mode 100644 index 476d21f1..00000000 --- a/src/theme_builder/components/stylers/PaddingStylerEditor.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "PaddingStylerEditor.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -PaddingStylerEditor::PaddingStylerEditor() { - SetLabel(u"Padding Styler"); - GetContainer()->AddChild(thickness_editor_.GetRootControl()); - - thickness_editor_.SetLabel(u"Thickness"); - - ConnectChangeEvent(thickness_editor_); -} - -PaddingStylerEditor::~PaddingStylerEditor() {} - -ClonablePtr PaddingStylerEditor::GetValue() { - return ui::style::PaddingStyler::Create(thickness_editor_.GetValue()); -} - -void PaddingStylerEditor::SetValue(ui::style::PaddingStyler* styler, - bool trigger_change) { - thickness_editor_.SetValue(styler->GetPadding(), false); - - if (trigger_change) { - RaiseChangeEvent(); - } -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/PaddingStylerEditor.h b/src/theme_builder/components/stylers/PaddingStylerEditor.h deleted file mode 100644 index b78d310b..00000000 --- a/src/theme_builder/components/stylers/PaddingStylerEditor.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "../properties/ThicknessPropertyEditor.h" -#include "StylerEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -class PaddingStylerEditor : public StylerEditor { - public: - PaddingStylerEditor(); - ~PaddingStylerEditor() override; - - ClonablePtr GetValue(); - void SetValue(ui::style::PaddingStyler* styler, bool trigger_change = true); - void SetValue(const ClonablePtr& styler, - bool trigger_change = true) { - SetValue(styler.get(), trigger_change); - } - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - properties::ThicknessPropertyEditor thickness_editor_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/PreferredSizeStylerEditor.cpp b/src/theme_builder/components/stylers/PreferredSizeStylerEditor.cpp deleted file mode 100644 index fb713c8c..00000000 --- a/src/theme_builder/components/stylers/PreferredSizeStylerEditor.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "PreferredSizeStylerEditor.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -PreferredSizeStylerEditor::PreferredSizeStylerEditor() { - SetLabel(u"Preferred Size Styler"); - GetContainer()->AddChild(width_editor_.GetRootControl()); - GetContainer()->AddChild(height_editor_.GetRootControl()); - - width_editor_.SetLabel(u"Width"); - height_editor_.SetLabel(u"Height"); - - ConnectChangeEvent(width_editor_); - ConnectChangeEvent(height_editor_); -} - -PreferredSizeStylerEditor::~PreferredSizeStylerEditor() {} - -ClonablePtr -PreferredSizeStylerEditor::GetValue() { - return ui::style::PreferredSizeStyler::Create(ui::render::MeasureSize{ - width_editor_.GetValue(), height_editor_.GetValue()}); -} - -void PreferredSizeStylerEditor::SetValue(ui::style::PreferredSizeStyler* styler, - bool trigger_change) { - width_editor_.SetValue(styler->GetPreferredSize().width, false); - height_editor_.SetValue(styler->GetPreferredSize().height, false); - - if (trigger_change) { - RaiseChangeEvent(); - } -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/PreferredSizeStylerEditor.h b/src/theme_builder/components/stylers/PreferredSizeStylerEditor.h deleted file mode 100644 index 4a64da10..00000000 --- a/src/theme_builder/components/stylers/PreferredSizeStylerEditor.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "../properties/MeasureLengthPropertyEditor.h" -#include "StylerEditor.h" -#include "cru/common/ClonablePtr.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -class PreferredSizeStylerEditor : public StylerEditor { - public: - PreferredSizeStylerEditor(); - ~PreferredSizeStylerEditor() override; - - ClonablePtr GetValue(); - void SetValue(ui::style::PreferredSizeStyler* styler, - bool trigger_change = true); - void SetValue(const ClonablePtr& styler, - bool trigger_change = true) { - SetValue(styler.get(), trigger_change); - } - - ClonablePtr GetStyler() override { return GetValue(); } - - private: - properties::MeasureLengthPropertyEditor width_editor_; - properties::MeasureLengthPropertyEditor height_editor_; -}; -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/StylerEditor.cpp b/src/theme_builder/components/stylers/StylerEditor.cpp deleted file mode 100644 index 0348adbd..00000000 --- a/src/theme_builder/components/stylers/StylerEditor.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "StylerEditor.h" -#include "../Common.h" -#include "BorderStylerEditor.h" -#include "CompoundStylerEditor.h" -#include "ContentBrushStylerEditor.h" -#include "CursorStylerEditor.h" -#include "FontStylerEditor.h" -#include "MarginStylerEditor.h" -#include "PaddingStylerEditor.h" -#include "PreferredSizeStylerEditor.h" -#include "cru/ui/controls/FlexLayout.h" -#include "cru/ui/render/FlexLayoutRenderObject.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -StylerEditor::StylerEditor() {} - -StylerEditor::~StylerEditor() {} - -std::unique_ptr CreateStylerEditor(ui::style::Styler* styler) { - if (auto compound_styler = dynamic_cast(styler)) { - auto result = std::make_unique(); - result->SetValue(compound_styler); - return result; - } else if (auto border_styler = - dynamic_cast(styler)) { - auto editor = std::make_unique(); - editor->SetValue(border_styler); - return editor; - } else if (auto cursor_styler = - dynamic_cast(styler)) { - auto editor = std::make_unique(); - editor->SetValue(cursor_styler); - return editor; - } else if (auto preferred_size_styler = - dynamic_cast(styler)) { - auto editor = std::make_unique(); - editor->SetValue(preferred_size_styler); - return editor; - } else if (auto margin_styler = - dynamic_cast(styler)) { - auto editor = std::make_unique(); - editor->SetValue(margin_styler); - return editor; - } else if (auto padding_styler = - dynamic_cast(styler)) { - auto editor = std::make_unique(); - editor->SetValue(padding_styler); - return editor; - } else if (auto content_brush_styler = - dynamic_cast(styler)) { - auto editor = std::make_unique(); - editor->SetValue(content_brush_styler); - return editor; - } else if (auto font_styler = dynamic_cast(styler)) { - auto editor = std::make_unique(); - editor->SetValue(font_styler); - return editor; - } else { - throw Exception(u"Unknown styler type"); - } -} -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/components/stylers/StylerEditor.h b/src/theme_builder/components/stylers/StylerEditor.h deleted file mode 100644 index 8aa52bda..00000000 --- a/src/theme_builder/components/stylers/StylerEditor.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include "../HeadBodyEditor.h" -#include "cru/ui/style/Styler.h" - -namespace cru::theme_builder::components::stylers { -class StylerEditor : public HeadBodyEditor { - public: - StylerEditor(); - ~StylerEditor() override; - - public: - virtual ClonablePtr GetStyler() = 0; -}; - -std::unique_ptr CreateStylerEditor(ui::style::Styler* styler); -} // namespace cru::theme_builder::components::stylers diff --git a/src/theme_builder/main.cpp b/src/theme_builder/main.cpp deleted file mode 100644 index 0c5b2159..00000000 --- a/src/theme_builder/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#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::components; - 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()); - - auto main_window = std::make_unique(); - - main_window->Show(); - - return application->Run(); -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c354fba9..c4133193 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,14 +1,10 @@ include(Catch) -add_library(cru_test_base INTERFACE) -target_link_libraries(cru_test_base INTERFACE Catch2::Catch2WithMain) +add_library(CruTestBase INTERFACE) +target_link_libraries(CruTestBase INTERFACE Catch2::Catch2WithMain) add_subdirectory(common) add_subdirectory(platform) add_subdirectory(xml) add_subdirectory(toml) add_subdirectory(ui) - -if(WIN32) - add_subdirectory(win) -endif() diff --git a/test/common/CMakeLists.txt b/test/common/CMakeLists.txt index 17cfa85b..b3436105 100644 --- a/test/common/CMakeLists.txt +++ b/test/common/CMakeLists.txt @@ -5,7 +5,7 @@ add_executable(CruBaseTest StringToNumberConverterTest.cpp StringUtilTest.cpp ) -target_link_libraries(CruBaseTest PRIVATE CruBase cru_test_base) +target_link_libraries(CruBaseTest PRIVATE CruBase CruTestBase) if (UNIX) target_sources(CruBaseTest PRIVATE @@ -18,11 +18,6 @@ if (WIN32) platform/win/StreamConvertTest.cpp platform/win/Win32FileStreamTest.cpp ) - - add_custom_command(TARGET CruBaseTest POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) endif() catch_discover_tests(CruBaseTest) diff --git a/test/platform/CMakeLists.txt b/test/platform/CMakeLists.txt index 37bd7e4a..5116d54d 100644 --- a/test/platform/CMakeLists.txt +++ b/test/platform/CMakeLists.txt @@ -2,13 +2,10 @@ add_executable(CruPlatformBaseTest ColorTest.cpp MatrixTest.cpp ) -target_link_libraries(CruPlatformBaseTest PRIVATE CruPlatformBase cru_test_base) +target_link_libraries(CruPlatformBaseTest PRIVATE CruPlatformBase CruTestBase) if (WIN32) - add_custom_command(TARGET CruPlatformBaseTest POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) + add_subdirectory(graphics/direct2d) endif() catch_discover_tests(CruPlatformBaseTest) diff --git a/test/platform/graphics/direct2d/CMakeLists.txt b/test/platform/graphics/direct2d/CMakeLists.txt new file mode 100644 index 00000000..66a07d15 --- /dev/null +++ b/test/platform/graphics/direct2d/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(CruPlatformGraphicsDirect2dTest + ConvertTest.cpp +) +target_link_libraries(CruPlatformGraphicsDirect2dTest PRIVATE CruPlatformGraphicsDirect2d CruTestBase) + +catch_discover_tests(CruPlatformGraphicsDirect2dTest) diff --git a/test/platform/graphics/direct2d/ConvertTest.cpp b/test/platform/graphics/direct2d/ConvertTest.cpp new file mode 100644 index 00000000..c30bb6a5 --- /dev/null +++ b/test/platform/graphics/direct2d/ConvertTest.cpp @@ -0,0 +1,31 @@ +#include "cru/platform/Matrix.h" +#include "cru/platform/graphics/direct2d/ConvertUtil.h" + +#include +#include "catch2/catch_approx.hpp" + +using Catch::Approx; +using cru::platform::Matrix; +using cru::platform::graphics::direct2d::Convert; + +TEST_CASE("MatrixConvert Rotation", "[matrix]") { + auto matrix = Convert(Matrix::Rotation(90)); + + auto m = *D2D1::Matrix3x2F::ReinterpretBaseType(&matrix); + + auto p = m.TransformPoint({1, 1}); + + REQUIRE(p.x == Approx(-1)); + REQUIRE(p.y == Approx(1)); +} + +TEST_CASE("MatrixConvert RotationAndTranslation", "[matrix]") { + auto matrix = Convert(Matrix::Rotation(90) * Matrix::Translation(1, 1)); + + auto m = *D2D1::Matrix3x2F::ReinterpretBaseType(&matrix); + + auto p = m.TransformPoint({1, 1}); + + REQUIRE(p.x == Approx(0)); + REQUIRE(p.y == Approx(2)); +} diff --git a/test/toml/CMakeLists.txt b/test/toml/CMakeLists.txt index 03f81047..30705585 100644 --- a/test/toml/CMakeLists.txt +++ b/test/toml/CMakeLists.txt @@ -1,7 +1,7 @@ add_executable(CruTomlTest ParserTest.cpp ) -target_link_libraries(CruTomlTest PRIVATE CruToml cru_test_base) +target_link_libraries(CruTomlTest PRIVATE CruToml CruTestBase) if (WIN32) add_custom_command(TARGET CruTomlTest POST_BUILD diff --git a/test/win/CMakeLists.txt b/test/win/CMakeLists.txt deleted file mode 100644 index 0ebdd7fe..00000000 --- a/test/win/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(graphics) diff --git a/test/win/graphics/CMakeLists.txt b/test/win/graphics/CMakeLists.txt deleted file mode 100644 index c90537ac..00000000 --- a/test/win/graphics/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(direct) diff --git a/test/win/graphics/direct/CMakeLists.txt b/test/win/graphics/direct/CMakeLists.txt deleted file mode 100644 index c2eb0630..00000000 --- a/test/win/graphics/direct/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_executable(CruPlatformGraphicsDirect2dTest - ConvertTest.cpp -) -target_link_libraries(CruPlatformGraphicsDirect2dTest PRIVATE CruPlatformGraphicsDirect2d cru_test_base) - -if (WIN32) - add_custom_command(TARGET CruPlatformGraphicsDirect2dTest POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND_EXPAND_LISTS - ) -endif() - -catch_discover_tests(CruPlatformGraphicsDirect2dTest) diff --git a/test/win/graphics/direct/ConvertTest.cpp b/test/win/graphics/direct/ConvertTest.cpp deleted file mode 100644 index c30bb6a5..00000000 --- a/test/win/graphics/direct/ConvertTest.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "cru/platform/Matrix.h" -#include "cru/platform/graphics/direct2d/ConvertUtil.h" - -#include -#include "catch2/catch_approx.hpp" - -using Catch::Approx; -using cru::platform::Matrix; -using cru::platform::graphics::direct2d::Convert; - -TEST_CASE("MatrixConvert Rotation", "[matrix]") { - auto matrix = Convert(Matrix::Rotation(90)); - - auto m = *D2D1::Matrix3x2F::ReinterpretBaseType(&matrix); - - auto p = m.TransformPoint({1, 1}); - - REQUIRE(p.x == Approx(-1)); - REQUIRE(p.y == Approx(1)); -} - -TEST_CASE("MatrixConvert RotationAndTranslation", "[matrix]") { - auto matrix = Convert(Matrix::Rotation(90) * Matrix::Translation(1, 1)); - - auto m = *D2D1::Matrix3x2F::ReinterpretBaseType(&matrix); - - auto p = m.TransformPoint({1, 1}); - - REQUIRE(p.x == Approx(0)); - REQUIRE(p.y == Approx(2)); -} diff --git a/test/xml/CMakeLists.txt b/test/xml/CMakeLists.txt index 73838a35..b000c368 100644 --- a/test/xml/CMakeLists.txt +++ b/test/xml/CMakeLists.txt @@ -1,7 +1,7 @@ add_executable(CruXmlTest ParserTest.cpp ) -target_link_libraries(CruXmlTest PRIVATE CruXml cru_test_base) +target_link_libraries(CruXmlTest PRIVATE CruXml CruTestBase) if (WIN32) add_custom_command(TARGET CruXmlTest POST_BUILD -- cgit v1.2.3