aboutsummaryrefslogtreecommitdiff
path: root/CruUI/ui/controls
diff options
context:
space:
mode:
Diffstat (limited to 'CruUI/ui/controls')
-rw-r--r--CruUI/ui/controls/linear_layout.cpp8
-rw-r--r--CruUI/ui/controls/linear_layout.h6
-rw-r--r--CruUI/ui/controls/text_block.cpp15
-rw-r--r--CruUI/ui/controls/text_block.h11
4 files changed, 37 insertions, 3 deletions
diff --git a/CruUI/ui/controls/linear_layout.cpp b/CruUI/ui/controls/linear_layout.cpp
index f639720d..1d88a4e1 100644
--- a/CruUI/ui/controls/linear_layout.cpp
+++ b/CruUI/ui/controls/linear_layout.cpp
@@ -44,9 +44,17 @@ namespace cru::ui::controls
{
control->Measure(rest_available_size_for_children);
if (orientation_ == Orientation::Horizontal)
+ {
rest_available_size_for_children.width -= control->GetDesiredSize().width;
+ if (rest_available_size_for_children.width < 0)
+ rest_available_size_for_children.width = 0;
+ }
else
+ {
rest_available_size_for_children.height -= control->GetDesiredSize().height;
+ if (rest_available_size_for_children.height < 0)
+ rest_available_size_for_children.height = 0;
+ }
});
auto actual_size_for_children = total_available_size_for_children - rest_available_size_for_children;
diff --git a/CruUI/ui/controls/linear_layout.h b/CruUI/ui/controls/linear_layout.h
index b8722b6f..74c504cb 100644
--- a/CruUI/ui/controls/linear_layout.h
+++ b/CruUI/ui/controls/linear_layout.h
@@ -13,6 +13,12 @@ namespace cru::ui::controls
Vertical
};
+ static LinearLayout* Create(const Orientation orientation = Orientation::Vertical)
+ {
+ return new LinearLayout(orientation);
+ }
+
+ private:
explicit LinearLayout(Orientation orientation = Orientation::Vertical);
protected:
diff --git a/CruUI/ui/controls/text_block.cpp b/CruUI/ui/controls/text_block.cpp
index 3649aea6..d15bd681 100644
--- a/CruUI/ui/controls/text_block.cpp
+++ b/CruUI/ui/controls/text_block.cpp
@@ -1,5 +1,7 @@
#include "text_block.h"
+#include <chrono>
+
#include "ui/window.h"
#include "graph/graph.h"
#include "exception.h"
@@ -27,9 +29,12 @@ namespace cru
void TextBlock::SetText(const String& text)
{
- const auto old_text = text_;
- text_ = text;
- OnTextChangedCore(old_text, text);
+ if (text_ != text)
+ {
+ const auto old_text = text_;
+ text_ = text;
+ OnTextChangedCore(old_text, text);
+ }
}
void TextBlock::SetBrush(const Microsoft::WRL::ComPtr<ID2D1Brush>& brush)
@@ -47,8 +52,12 @@ namespace cru
void TextBlock::OnSizeChangedCore(events::SizeChangedEventArgs& args)
{
+ auto before = std::chrono::steady_clock::now();
RecreateTextLayout();
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());
+
}
void TextBlock::OnDraw(ID2D1DeviceContext* device_context)
diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h
index abf77112..04347a0c 100644
--- a/CruUI/ui/controls/text_block.h
+++ b/CruUI/ui/controls/text_block.h
@@ -15,11 +15,22 @@ namespace cru
public:
using TextLayoutHandler = Action<Microsoft::WRL::ComPtr<IDWriteTextLayout>>;
+ static TextBlock* Create(
+ const String& text = L"",
+ const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format = nullptr,
+ const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr)
+ {
+ const auto text_block = new TextBlock(init_text_format, init_brush);
+ text_block->SetText(text);
+ return text_block;
+ }
+ private:
explicit TextBlock(
const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format = nullptr,
const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr
);
+ public:
TextBlock(const TextBlock& other) = delete;
TextBlock(TextBlock&& other) = delete;
TextBlock& operator=(const TextBlock& other) = delete;