diff options
author | crupest <crupest@outlook.com> | 2018-09-10 23:58:34 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-09-10 23:58:34 +0800 |
commit | 9250f4d919bc800fe66a50a0874183458e6ebbbe (patch) | |
tree | 1d25285801a6d92cfa8bde6dd0d13433e05d4c04 /CruUI/ui | |
parent | aa8ba64f4f580552ba14325dd3e04f38a3c9a1de (diff) | |
download | cru-9250f4d919bc800fe66a50a0874183458e6ebbbe.tar.gz cru-9250f4d919bc800fe66a50a0874183458e6ebbbe.tar.bz2 cru-9250f4d919bc800fe66a50a0874183458e6ebbbe.zip |
...
Diffstat (limited to 'CruUI/ui')
-rw-r--r-- | CruUI/ui/control.cpp | 4 | ||||
-rw-r--r-- | CruUI/ui/controls/text_block.cpp | 23 | ||||
-rw-r--r-- | CruUI/ui/window.cpp | 1 |
3 files changed, 9 insertions, 19 deletions
diff --git a/CruUI/ui/control.cpp b/CruUI/ui/control.cpp index 507beee8..73981891 100644 --- a/CruUI/ui/control.cpp +++ b/CruUI/ui/control.cpp @@ -6,6 +6,7 @@ #include "window.h" #include "timer.h" +#include "debug_base.h" namespace cru { namespace ui { @@ -257,12 +258,9 @@ namespace cru { void Control::Layout(const Rect& rect) { - auto before = std::chrono::steady_clock::now(); SetPositionRelative(rect.GetLeftTop()); SetSize(rect.GetSize()); OnLayout(rect); - auto after = std::chrono::steady_clock::now(); - OutputDebugStringW((L"Layout time duration:" + std::to_wstring(std::chrono::duration_cast<std::chrono::milliseconds>(after - before).count()) + L"\n").c_str()); } Size Control::GetDesiredSize() const diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp index d15bd681..1201fac6 100644 --- a/CruUI/ui/controls/text_block.cpp +++ b/CruUI/ui/controls/text_block.cpp @@ -5,6 +5,7 @@ #include "ui/window.h" #include "graph/graph.h" #include "exception.h" +#include "debug_base.h" namespace cru { @@ -52,12 +53,10 @@ namespace cru void TextBlock::OnSizeChangedCore(events::SizeChangedEventArgs& args) { - auto before = std::chrono::steady_clock::now(); - RecreateTextLayout(); + text_layout_->SetMaxWidth(args.GetNewSize().width); + text_layout_->SetMaxHeight(args.GetNewSize().height); Repaint(); - auto after = std::chrono::steady_clock::now(); - OutputDebugStringW((L"TextBlock OnSizeChangedCore time duration:" + std::to_wstring(std::chrono::duration_cast<std::chrono::milliseconds>(after - before).count()) + L"\n").c_str()); - + Control::OnSizeChangedCore(args); } void TextBlock::OnDraw(ID2D1DeviceContext* device_context) @@ -73,7 +72,6 @@ namespace cru const auto layout_params = GetLayoutParams(); - if (layout_params->width.mode == MeasureMode::Stretch && layout_params->height.mode == MeasureMode::Stretch) return available_size; @@ -100,17 +98,12 @@ namespace cru measure_size.width = get_measure_length(layout_params->width, available_size.width); measure_size.height = get_measure_length(layout_params->height, available_size.height); - - Microsoft::WRL::ComPtr<IDWriteTextLayout> measure_text_layout; - - const auto dwrite_factory = GetDWriteFactory(); - - ThrowIfFailed(dwrite_factory->CreateTextLayout(text_.c_str(), text_.size(), - text_format_.Get(), measure_size.width, measure_size.height, &measure_text_layout) - ); + ThrowIfFailed(text_layout_->SetMaxWidth(measure_size.width)); + ThrowIfFailed(text_layout_->SetMaxHeight(measure_size.height)); DWRITE_TEXT_METRICS metrics{}; - measure_text_layout->GetMetrics(&metrics); + + ThrowIfFailed(text_layout_->GetMetrics(&metrics)); const Size measure_result(metrics.width, metrics.height); diff --git a/CruUI/ui/window.cpp b/CruUI/ui/window.cpp index 392bca87..3a9393ff 100644 --- a/CruUI/ui/window.cpp +++ b/CruUI/ui/window.cpp @@ -165,7 +165,6 @@ namespace cru void Window::Repaint() { if (IsWindowValid()) { InvalidateRect(hwnd_, nullptr, false); - UpdateWindow(hwnd_); } } |