aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CruUI/graph/graph.cpp20
-rw-r--r--CruUI/graph/graph.h1
-rw-r--r--CruUI/ui/controls/text_block.cpp24
-rw-r--r--CruUI/ui/controls/text_block.h1
4 files changed, 26 insertions, 20 deletions
diff --git a/CruUI/graph/graph.cpp b/CruUI/graph/graph.cpp
index 94c7029e..77d7044e 100644
--- a/CruUI/graph/graph.cpp
+++ b/CruUI/graph/graph.cpp
@@ -221,5 +221,25 @@ namespace cru {
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/CruUI/graph/graph.h b/CruUI/graph/graph.h
index 01d95797..0f1d29d1 100644
--- a/CruUI/graph/graph.h
+++ b/CruUI/graph/graph.h
@@ -166,6 +166,7 @@ namespace cru
}
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, Function<void(ID2D1DeviceContext*)>&& action)
{
diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp
index 8800fd91..f0ef41d9 100644
--- a/CruUI/ui/controls/text_block.cpp
+++ b/CruUI/ui/controls/text_block.cpp
@@ -21,8 +21,11 @@ namespace cru
const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush) : Control(false)
{
text_format_ = init_text_format;
+
if (init_brush == nullptr)
brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::Black));
+ else
+ brush_ = init_brush;
selection_brush_ = CreateSolidBrush(D2D1::ColorF(D2D1::ColorF::LightSkyBlue));
}
@@ -60,7 +63,7 @@ namespace cru
void TextBlock::RemoveTextLayoutHandler(const TextLayoutHandlerPtr& handler)
{
const auto find_result = std::find(text_layout_handlers_.cbegin(), text_layout_handlers_.cend(),
- handler);
+ handler);
if (find_result != text_layout_handlers_.cend())
text_layout_handlers_.erase(find_result);
}
@@ -259,23 +262,6 @@ namespace cru
Repaint();
}
- void TextBlock::CreateDefaultTextFormat()
- {
- const auto dwrite_factory = GetDWriteFactory();
-
- 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));
- }
-
void TextBlock::RecreateTextLayout()
{
if (text_.empty())
@@ -287,7 +273,7 @@ namespace cru
const auto dwrite_factory = GetDWriteFactory();
if (text_format_ == nullptr)
- CreateDefaultTextFormat();
+ text_format_ = graph::CreateDefaultTextFormat();
const auto&& size = GetSize();
diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h
index a50f5ee9..c87ffc51 100644
--- a/CruUI/ui/controls/text_block.h
+++ b/CruUI/ui/controls/text_block.h
@@ -93,7 +93,6 @@ namespace cru
private:
void OnTextChangedCore(const String& old_text, const String& new_text);
- void CreateDefaultTextFormat();
void RecreateTextLayout();
private: