aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/text_box.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-10-02 01:09:35 +0800
committercrupest <crupest@outlook.com>2018-10-02 01:09:35 +0800
commit040a6c18f18100b825a56443a73aa1de64e4518c (patch)
treea271bddb244fa2041f14f8d46d249457cee09e5f /src/ui/controls/text_box.cpp
parenta3b78397f71c35e51681104b572de06a1780e4ee (diff)
downloadcru-040a6c18f18100b825a56443a73aa1de64e4518c.tar.gz
cru-040a6c18f18100b825a56443a73aa1de64e4518c.tar.bz2
cru-040a6c18f18100b825a56443a73aa1de64e4518c.zip
Make text box use border delegate. Fix layout bug in margin container.
Diffstat (limited to 'src/ui/controls/text_box.cpp')
-rw-r--r--src/ui/controls/text_box.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp
index 4a4114ab..0d65f1ad 100644
--- a/src/ui/controls/text_box.cpp
+++ b/src/ui/controls/text_box.cpp
@@ -26,21 +26,28 @@ namespace cru::ui::controls
is_caret_show_ = !is_caret_show_;
Repaint();
});
+
+ border_delegate_ = std::make_unique<BorderDelegate>(this);
}
TextBox::~TextBox() = default;
void TextBox::OnDraw(ID2D1DeviceContext* device_context)
{
- TextControl::OnDraw(device_context);
- if (is_caret_show_)
+ border_delegate_->Draw(device_context, GetSize());
+ const auto border_thickness = border_delegate_->GetBorderThickness();
+ graph::WithTransform(device_context, D2D1::Matrix3x2F::Translation(border_thickness.left, border_thickness.top), [this](ID2D1DeviceContext* device_context)
{
- const auto caret_half_width = Application::GetInstance()->GetCaretInfo().half_caret_width;
- FLOAT x, y;
- DWRITE_HIT_TEST_METRICS metrics{};
- ThrowIfFailed(text_layout_->HitTestTextPosition(caret_position_, FALSE, &x, &y, &metrics));
- device_context->FillRectangle(D2D1::RectF(metrics.left - caret_half_width, metrics.top, metrics.left + caret_half_width, metrics.top + metrics.height), caret_brush_.Get());
- }
+ TextControl::OnDraw(device_context);
+ if (is_caret_show_)
+ {
+ const auto caret_half_width = Application::GetInstance()->GetCaretInfo().half_caret_width;
+ FLOAT x, y;
+ DWRITE_HIT_TEST_METRICS metrics{};
+ ThrowIfFailed(text_layout_->HitTestTextPosition(caret_position_, FALSE, &x, &y, &metrics));
+ device_context->FillRectangle(D2D1::RectF(metrics.left - caret_half_width, metrics.top, metrics.left + caret_half_width, metrics.top + metrics.height), caret_brush_.Get());
+ }
+ });
}
void TextBox::OnGetFocusCore(events::FocusChangeEventArgs& args)
@@ -131,6 +138,11 @@ namespace cru::ui::controls
}
}
+ Size TextBox::OnMeasure(const Size& available_size)
+ {
+ return TextMeasureWithPadding(available_size, border_delegate_->GetBorderThickness());
+ }
+
void TextBox::RequestChangeCaretPosition(const unsigned position)
{
caret_position_ = position;