aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CruUI.vcxproj4
-rw-r--r--CruUI.vcxproj.filters4
-rw-r--r--src/any_map.h4
-rw-r--r--src/application.cpp8
-rw-r--r--src/application.hpp26
-rw-r--r--src/graph/graph.cpp29
-rw-r--r--src/graph/graph.hpp3
-rw-r--r--src/ui/border_property.cpp4
-rw-r--r--src/ui/control.cpp11
-rw-r--r--src/ui/controls/button.cpp15
-rw-r--r--src/ui/controls/text_block.cpp7
-rw-r--r--src/ui/controls/text_block.hpp16
-rw-r--r--src/ui/controls/text_box.cpp12
-rw-r--r--src/ui/controls/text_box.hpp11
-rw-r--r--src/ui/controls/text_control.cpp12
-rw-r--r--src/ui/controls/toggle_button.cpp6
-rw-r--r--src/ui/predefine.cpp73
-rw-r--r--src/ui/predefine.hpp59
-rw-r--r--src/ui/theme.cpp6
-rw-r--r--src/ui/theme.hpp8
20 files changed, 184 insertions, 134 deletions
diff --git a/CruUI.vcxproj b/CruUI.vcxproj
index 97fb323d..352545d9 100644
--- a/CruUI.vcxproj
+++ b/CruUI.vcxproj
@@ -124,7 +124,6 @@
<ClCompile Include="src\exception.cpp" />
<ClCompile Include="src\graph\graph.cpp" />
<ClCompile Include="src\main.cpp" />
- <ClCompile Include="src\ui\theme.cpp" />
<ClCompile Include="src\timer.cpp" />
<ClCompile Include="src\ui\animations\animation.cpp" />
<ClCompile Include="src\ui\control.cpp" />
@@ -135,13 +134,13 @@
<ClCompile Include="src\ui\controls\text_box.cpp" />
<ClInclude Include="src\any_map.h" />
<ClInclude Include="src\format.hpp" />
- <ClInclude Include="src\ui\theme.hpp" />
<ClInclude Include="src\ui\border_property.hpp" />
<ClInclude Include="src\ui\controls\text_control.hpp" />
<ClCompile Include="src\ui\controls\toggle_button.cpp" />
<ClCompile Include="src\ui\cursor.cpp" />
<ClCompile Include="src\ui\events\ui_event.cpp" />
<ClCompile Include="src\ui\layout_base.cpp" />
+ <ClCompile Include="src\ui\predefine.cpp" />
<ClCompile Include="src\ui\ui_base.cpp" />
<ClCompile Include="src\ui\window.cpp" />
</ItemGroup>
@@ -166,6 +165,7 @@
<ClInclude Include="src\ui\cursor.hpp" />
<ClInclude Include="src\ui\events\ui_event.hpp" />
<ClInclude Include="src\ui\layout_base.hpp" />
+ <ClInclude Include="src\ui\predefine.hpp" />
<ClInclude Include="src\ui\ui_base.hpp" />
<ClInclude Include="src\ui\window.hpp" />
</ItemGroup>
diff --git a/CruUI.vcxproj.filters b/CruUI.vcxproj.filters
index 323b559e..3ae84977 100644
--- a/CruUI.vcxproj.filters
+++ b/CruUI.vcxproj.filters
@@ -78,7 +78,7 @@
<ClCompile Include="src\any_map.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\ui\theme.cpp">
+ <ClCompile Include="src\ui\predefine.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@@ -158,7 +158,7 @@
<ClInclude Include="src\any_map.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\ui\theme.hpp">
+ <ClInclude Include="src\ui\predefine.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
diff --git a/src/any_map.h b/src/any_map.h
index 2dee75a6..ea6044b1 100644
--- a/src/any_map.h
+++ b/src/any_map.h
@@ -67,10 +67,10 @@ namespace cru
// Set the value of key, and trigger all related listeners.
template <typename T>
- void SetValue(const String& key, const T& value)
+ void SetValue(const String& key, T&& value)
{
auto& p = map_[key];
- p.first = std::make_any<T>(value);
+ p.first = std::make_any<T>(std::forward<T>(value));
InvokeListeners(p.second, p.first);
}
diff --git a/src/application.cpp b/src/application.cpp
index dce01b11..672ee347 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -4,7 +4,7 @@
#include "timer.hpp"
#include "ui/window.hpp"
#include "ui/cursor.hpp"
-#include "graph/graph.hpp"
+#include "ui/predefine.hpp"
namespace cru {
constexpr auto god_window_class_name = L"GodWindowClass";
@@ -118,11 +118,7 @@ namespace cru {
god_window_ = std::make_unique<GodWindow>(this);
-#ifdef CRU_DEBUG_LAYOUT
- debug_layout_resource_.out_border_brush = graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Crimson));
- debug_layout_resource_.margin_brush = graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightCoral, 0.25f));
- debug_layout_resource_.padding_brush = graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::SkyBlue, 0.25f));
-#endif
+ ui::predefine::InitThemes(&predefine_resource_map_);
caret_info_ = GetSystemCaretInfo();
diff --git a/src/application.hpp b/src/application.hpp
index c286cc08..0c345328 100644
--- a/src/application.hpp
+++ b/src/application.hpp
@@ -38,15 +38,6 @@ namespace cru
float half_caret_width;
};
-#ifdef CRU_DEBUG_LAYOUT
- struct DebugLayoutResource
- {
- Microsoft::WRL::ComPtr<ID2D1Brush> out_border_brush;
- Microsoft::WRL::ComPtr<ID2D1Brush> margin_brush;
- Microsoft::WRL::ComPtr<ID2D1Brush> padding_brush;
- };
-#endif
-
class GodWindow : public Object
{
public:
@@ -122,18 +113,11 @@ namespace cru
return caret_info_;
}
- AnyMap* GetThemeMap()
+ const AnyMap* GetPredefineResourceMap() const
{
- return &theme_map_;
+ return &predefine_resource_map_;
}
-#ifdef CRU_DEBUG_LAYOUT
- const DebugLayoutResource* GetDebugLayoutResource() const
- {
- return &debug_layout_resource_;
- }
-#endif
-
private:
HINSTANCE h_instance_;
@@ -142,13 +126,9 @@ namespace cru
std::unordered_map<std::type_index, Object*> singleton_map_;
std::list<Object*> singleton_list_; // used for reverse destroy.
-#ifdef CRU_DEBUG_LAYOUT
- DebugLayoutResource debug_layout_resource_;
-#endif
-
CaretInfo caret_info_;
- AnyMap theme_map_{};
+ AnyMap predefine_resource_map_{};
};
diff --git a/src/graph/graph.cpp b/src/graph/graph.cpp
index d37b5e2d..70bec35b 100644
--- a/src/graph/graph.cpp
+++ b/src/graph/graph.cpp
@@ -216,33 +216,4 @@ namespace cru::graph
d2d1_factory_->ReloadSystemMetrics()
);
}
-
- ComPtr<ID2D1SolidColorBrush> CreateSolidBrush(const D2D1_COLOR_F& color)
- {
- const auto device_context = GraphManager::GetInstance()->GetD2D1DeviceContext();
- ComPtr<ID2D1SolidColorBrush> solid_color_brush;
- device_context->CreateSolidColorBrush(color, &solid_color_brush);
- return solid_color_brush;
- }
-
- ComPtr<IDWriteTextFormat> CreateDefaultTextFormat()
- {
- const auto dwrite_factory = GraphManager::GetInstance()->GetDWriteFactory();
-
- ComPtr<IDWriteTextFormat> text_format;
-
- ThrowIfFailed(dwrite_factory->CreateTextFormat(
- L"等线", nullptr,
- DWRITE_FONT_WEIGHT_NORMAL,
- DWRITE_FONT_STYLE_NORMAL,
- DWRITE_FONT_STRETCH_NORMAL,
- 24.0, L"zh-cn",
- &text_format
- ));
-
- ThrowIfFailed(text_format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
- ThrowIfFailed(text_format->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER));
- return text_format;
- }
}
-
diff --git a/src/graph/graph.hpp b/src/graph/graph.hpp
index b98db5f4..b859e82f 100644
--- a/src/graph/graph.hpp
+++ b/src/graph/graph.hpp
@@ -164,9 +164,6 @@ namespace cru::graph
return graph_manager_->GetD2D1DeviceContext();
}
- Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> CreateSolidBrush(const D2D1_COLOR_F& color);
- Microsoft::WRL::ComPtr<IDWriteTextFormat> CreateDefaultTextFormat();
-
inline void WithTransform(ID2D1DeviceContext* device_context, const D2D1_MATRIX_3X2_F matrix, const std::function<void(ID2D1DeviceContext*)>& action)
{
D2D1_MATRIX_3X2_F old_transform;
diff --git a/src/ui/border_property.cpp b/src/ui/border_property.cpp
index 7f61c1b7..bd06a96a 100644
--- a/src/ui/border_property.cpp
+++ b/src/ui/border_property.cpp
@@ -1,10 +1,10 @@
#include "border_property.hpp"
-#include "graph/graph.hpp"
+#include "predefine.hpp"
namespace cru::ui
{
- BorderProperty::BorderProperty(): BorderProperty(graph::CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)))
+ BorderProperty::BorderProperty(): BorderProperty(predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_border_property_brush))
{
}
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 31910328..1ec2f704 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -8,6 +8,10 @@
#include "exception.hpp"
#include "cru_debug.hpp"
+#ifdef CRU_DEBUG_LAYOUT
+#include "predefine.hpp"
+#endif
+
namespace cru::ui
{
using namespace events;
@@ -391,12 +395,11 @@ namespace cru::ui
#ifdef CRU_DEBUG_LAYOUT
if (GetWindow()->IsDebugLayout())
{
- const auto resource = Application::GetInstance()->GetDebugLayoutResource();
if (padding_geometry_ != nullptr)
- device_context->FillGeometry(padding_geometry_.Get(), resource->padding_brush.Get());
+ device_context->FillGeometry(padding_geometry_.Get(), predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_debug_layout_padding_brush).Get());
if (margin_geometry_ != nullptr)
- device_context->FillGeometry(margin_geometry_.Get(), resource->margin_brush.Get());
- device_context->DrawRectangle(Convert(GetRect(RectRange::Margin)), resource->out_border_brush.Get());
+ device_context->FillGeometry(margin_geometry_.Get(), predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_debug_layout_margin_brush).Get());
+ device_context->DrawRectangle(Convert(GetRect(RectRange::Margin)), predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_debug_layout_out_border_brush).Get());
}
#endif
diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp
index 0422506b..a90c218d 100644
--- a/src/ui/controls/button.cpp
+++ b/src/ui/controls/button.cpp
@@ -1,23 +1,14 @@
#include "button.hpp"
#include "graph/graph.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
-
Button::Button() : Control(true),
- normal_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue))},
- pressed_border_{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue))}
+ normal_border_{predefine::GetPredefineResource<BorderProperty>(predefine::key_button_normal_border)},
+ pressed_border_{predefine::GetPredefineResource<BorderProperty>(predefine::key_button_press_border)}
{
- normal_border_.SetStrokeWidth(2);
- normal_border_.SetRadiusX(6);
- normal_border_.SetRadiusY(6);
-
- pressed_border_.SetStrokeWidth(2);
- pressed_border_.SetRadiusX(6);
- pressed_border_.SetRadiusY(6);
-
SetBordered(true);
GetBorderProperty() = normal_border_;
diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp
index b8a7e8a6..290ddd58 100644
--- a/src/ui/controls/text_block.cpp
+++ b/src/ui/controls/text_block.cpp
@@ -1,11 +1,14 @@
#include "text_block.hpp"
#include "ui/window.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- TextBlock::TextBlock(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : TextControl(init_text_format, init_brush)
+ TextBlock::TextBlock() : TextControl(
+ predefine::GetPredefineResourceComPtr<IDWriteTextFormat>(predefine::key_text_block_text_format),
+ predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_block_text_brush)
+ )
{
}
diff --git a/src/ui/controls/text_block.hpp b/src/ui/controls/text_block.hpp
index b2b4aaf9..4d017da5 100644
--- a/src/ui/controls/text_block.hpp
+++ b/src/ui/controls/text_block.hpp
@@ -9,23 +9,15 @@ namespace cru::ui::controls
public:
static constexpr auto control_type = L"TextBlock";
- static TextBlock* Create(
- const String& text = L"",
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format = nullptr,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr)
+ static TextBlock* Create(const String& text = L"")
{
- const auto text_block = new TextBlock(init_text_format, init_brush);
+ const auto text_block = new TextBlock();
text_block->SetText(text);
return text_block;
}
- using TextControl::SetSelectable; // Make this public.
-
protected:
- TextBlock(
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush
- );
+ TextBlock();
public:
TextBlock(const TextBlock& other) = delete;
TextBlock(TextBlock&& other) = delete;
@@ -34,5 +26,7 @@ namespace cru::ui::controls
~TextBlock() override = default;
StringView GetControlType() const override final;
+
+ using TextControl::SetSelectable; // Make this public.
};
}
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp
index cb5d79a2..0ed1248c 100644
--- a/src/ui/controls/text_box.cpp
+++ b/src/ui/controls/text_box.cpp
@@ -6,23 +6,25 @@
#include "graph/graph.hpp"
#include "exception.hpp"
#include "application.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
-
inline Microsoft::WRL::ComPtr<IDWriteFactory> GetDWriteFactory()
{
return graph::GraphManager::GetInstance()->GetDWriteFactory();
}
- TextBox::TextBox(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : TextControl(init_text_format, init_brush)
+ TextBox::TextBox() : TextControl(
+ predefine::GetPredefineResourceComPtr<IDWriteTextFormat>(predefine::key_text_box_text_format),
+ predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_box_text_brush)
+ )
{
SetSelectable(true);
- caret_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black));
+ caret_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_box_caret_brush);
+ GetBorderProperty() = predefine::GetPredefineResource<BorderProperty>(predefine::key_text_box_border);
SetBordered(true);
}
diff --git a/src/ui/controls/text_box.hpp b/src/ui/controls/text_box.hpp
index 434aa232..65f81fc3 100644
--- a/src/ui/controls/text_box.hpp
+++ b/src/ui/controls/text_box.hpp
@@ -10,18 +10,13 @@ namespace cru::ui::controls
public:
static constexpr auto control_type = L"TextBox";
- static TextBox* Create(
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format = nullptr,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr)
+ static TextBox* Create()
{
- return new TextBox(init_text_format, init_brush);
+ return new TextBox();
}
protected:
- explicit TextBox(
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush
- );
+ TextBox();
public:
TextBox(const TextBox& other) = delete;
TextBox(TextBox&& other) = delete;
diff --git a/src/ui/controls/text_control.cpp b/src/ui/controls/text_control.cpp
index 5d2c840e..42214583 100644
--- a/src/ui/controls/text_control.cpp
+++ b/src/ui/controls/text_control.cpp
@@ -1,14 +1,14 @@
#include "text_control.hpp"
+#include <cassert>
+
#include "ui/window.hpp"
#include "graph/graph.hpp"
#include "exception.hpp"
-#include <cassert>
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
-
inline Microsoft::WRL::ComPtr<IDWriteFactory> GetDWriteFactory()
{
return graph::GraphManager::GetInstance()->GetDWriteFactory();
@@ -17,13 +17,13 @@ namespace cru::ui::controls
TextControl::TextControl(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : Control(false)
{
- text_format_ = init_text_format == nullptr ? graph::CreateDefaultTextFormat() : init_text_format;
+ text_format_ = init_text_format;
RecreateTextLayout();
- brush_ = init_brush == nullptr ? CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)) : init_brush;
+ brush_ = init_brush;
- selection_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightSkyBlue));
+ selection_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_text_control_selection_brush);
}
diff --git a/src/ui/controls/toggle_button.cpp b/src/ui/controls/toggle_button.cpp
index f35b8bfe..a901f650 100644
--- a/src/ui/controls/toggle_button.cpp
+++ b/src/ui/controls/toggle_button.cpp
@@ -2,10 +2,10 @@
#include "graph/graph.hpp"
#include "ui/animations/animation.hpp"
+#include "ui/predefine.hpp"
namespace cru::ui::controls
{
- using graph::CreateSolidBrush;
using animations::AnimationBuilder;
// ui length parameters of toggle button.
@@ -19,8 +19,8 @@ namespace cru::ui::controls
{
graph::GraphManager::GetInstance()->GetD2D1Factory()->CreateRoundedRectangleGeometry(D2D1::RoundedRect(D2D1::RectF(-half_width, -half_height, half_width, half_height), half_height, half_height), &frame_path_);
- on_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::DeepSkyBlue));
- off_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightGray));
+ on_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_toggle_button_on_brush);
+ off_brush_ = predefine::GetPredefineResourceComPtr<ID2D1Brush>(predefine::key_toggle_button_off_brush);
}
inline D2D1_POINT_2F ConvertPoint(const Point& point)
diff --git a/src/ui/predefine.cpp b/src/ui/predefine.cpp
new file mode 100644
index 00000000..259b3a2a
--- /dev/null
+++ b/src/ui/predefine.cpp
@@ -0,0 +1,73 @@
+#include "predefine.hpp"
+
+#include "border_property.hpp"
+#include "graph/graph.hpp"
+#include "exception.hpp"
+
+namespace cru::ui::predefine
+{
+ Microsoft::WRL::ComPtr<ID2D1Brush> CreateSolidBrush(const D2D1_COLOR_F& color)
+ {
+ const auto device_context = graph::GraphManager::GetInstance()->GetD2D1DeviceContext();
+ Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solid_color_brush;
+ device_context->CreateSolidColorBrush(color, &solid_color_brush);
+ return solid_color_brush;
+ }
+
+ void InitThemes(AnyMap* resource_map)
+ {
+ resource_map->SetValue(key_border_property_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)));
+
+ BorderProperty button_normal_border{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::RoyalBlue))};
+ button_normal_border.SetStrokeWidth(2);
+ button_normal_border.SetRadiusX(6);
+ button_normal_border.SetRadiusY(6);
+ resource_map->SetValue(key_button_normal_border, std::move(button_normal_border));
+
+ BorderProperty button_press_border{CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Blue))};
+ button_press_border.SetStrokeWidth(2);
+ button_press_border.SetRadiusX(6);
+ button_press_border.SetRadiusY(6);
+ resource_map->SetValue(key_button_press_border, std::move(button_press_border));
+
+
+ const auto dwrite_factory = graph::GraphManager::GetInstance()->GetDWriteFactory();
+ Microsoft::WRL::ComPtr<IDWriteTextFormat> text_format;
+
+ ThrowIfFailed(dwrite_factory->CreateTextFormat(
+ L"等线", nullptr,
+ DWRITE_FONT_WEIGHT_NORMAL,
+ DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL,
+ 24.0, L"zh-cn",
+ &text_format
+ ));
+
+ ThrowIfFailed(text_format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
+ ThrowIfFailed(text_format->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER));
+
+ resource_map->SetValue(key_text_block_text_format, text_format);
+ resource_map->SetValue(key_text_box_text_format, text_format);
+
+ auto text_brush = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black));
+ resource_map->SetValue(key_text_block_text_brush, text_brush);
+ resource_map->SetValue(key_text_box_text_brush, text_brush);
+
+ auto text_selection_brush = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightSkyBlue));
+ resource_map->SetValue(key_text_control_selection_brush, text_selection_brush);
+
+ BorderProperty text_box_border;
+ resource_map->SetValue(key_text_box_border, text_box_border);
+
+ resource_map->SetValue(key_text_box_caret_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black)));
+
+ resource_map->SetValue(key_toggle_button_on_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::DeepSkyBlue)));
+ resource_map->SetValue(key_toggle_button_off_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightGray)));
+
+#ifdef CRU_DEBUG_LAYOUT
+ resource_map->SetValue(key_debug_layout_out_border_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Crimson)));
+ resource_map->SetValue(key_debug_layout_margin_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightCoral, 0.25f)));
+ resource_map->SetValue(key_debug_layout_padding_brush, CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::SkyBlue, 0.25f)));
+#endif
+ }
+}
diff --git a/src/ui/predefine.hpp b/src/ui/predefine.hpp
new file mode 100644
index 00000000..03e98a98
--- /dev/null
+++ b/src/ui/predefine.hpp
@@ -0,0 +1,59 @@
+#pragma once
+
+#include "system_headers.hpp"
+
+#include "any_map.h"
+#include "application.hpp"
+
+namespace cru::ui::predefine
+{
+#define CRU_DEFINE_KEY(name, key) \
+ constexpr const wchar_t* key_##name = L#key;
+
+ //region BorderProperty
+ CRU_DEFINE_KEY(border_property_brush, BorderProperty_Brush)
+
+ //region Button
+ CRU_DEFINE_KEY(button_normal_border, Button_Normal_Border)
+ CRU_DEFINE_KEY(button_press_border, Button_Press_Border)
+
+ //region TextControl
+ CRU_DEFINE_KEY(text_control_selection_brush, TextControl_SelectionBrush)
+
+ //region TextBox
+ CRU_DEFINE_KEY(text_box_border, TextBox_Border)
+ CRU_DEFINE_KEY(text_box_text_brush, TextBox_TextBrush)
+ CRU_DEFINE_KEY(text_box_text_format, TextBox_TextFormat)
+ CRU_DEFINE_KEY(text_box_caret_brush, TextBox_CaretBrush)
+
+ //region TextBlock
+ CRU_DEFINE_KEY(text_block_text_brush, TextBlock_TextBrush)
+ CRU_DEFINE_KEY(text_block_text_format, TextBlock_TextFormat)
+
+ //region ToggleButton
+ CRU_DEFINE_KEY(toggle_button_on_brush, ToggleButton_On_Brush)
+ CRU_DEFINE_KEY(toggle_button_off_brush, ToggleButton_Off_Brush)
+
+#ifdef CRU_DEBUG_LAYOUT
+ //region debug
+ CRU_DEFINE_KEY(debug_layout_out_border_brush, Debug_Layout_Out_Border_Brush)
+ CRU_DEFINE_KEY(debug_layout_margin_brush, Debug_Layout_Margin_Brush)
+ CRU_DEFINE_KEY(debug_layout_padding_brush, Debug_Layout_Padding_Brush)
+#endif
+
+#undef CRU_DEFINE_KEY
+
+ void InitThemes(AnyMap* resource_map);
+
+ template<typename T>
+ T GetPredefineResource(const String& key)
+ {
+ return Application::GetInstance()->GetPredefineResourceMap()->GetValue<T>(key);
+ }
+
+ template<typename T>
+ Microsoft::WRL::ComPtr<T> GetPredefineResourceComPtr(const String& key)
+ {
+ return GetPredefineResource<Microsoft::WRL::ComPtr<T>>(key);
+ }
+}
diff --git a/src/ui/theme.cpp b/src/ui/theme.cpp
deleted file mode 100644
index eb0f3df6..00000000
--- a/src/ui/theme.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "theme.hpp"
-
-namespace cru::ui::theme
-{
-
-}
diff --git a/src/ui/theme.hpp b/src/ui/theme.hpp
deleted file mode 100644
index 571a05fe..00000000
--- a/src/ui/theme.hpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-
-#include "any_map.h"
-
-namespace cru::ui::theme
-{
-
-}