diff options
author | Yuqian Yang <crupest@outlook.com> | 2018-10-04 16:52:11 +0000 |
---|---|---|
committer | Yuqian Yang <crupest@outlook.com> | 2018-10-04 16:52:11 +0000 |
commit | 7e870dd16e2f5b41fa6c6f687723aaa50c16274d (patch) | |
tree | be2b26a42dc9fde97379f98f035113e08e0bc331 /src/ui/controls/text_box.cpp | |
parent | 30ecda8bb354d5982978af97aa90b5f49d9ea195 (diff) | |
parent | c5384d496e9ed429ca2baa3ca5e586ff255235eb (diff) | |
download | cru-7e870dd16e2f5b41fa6c6f687723aaa50c16274d.tar.gz cru-7e870dd16e2f5b41fa6c6f687723aaa50c16274d.tar.bz2 cru-7e870dd16e2f5b41fa6c6f687723aaa50c16274d.zip |
Merge branch '12-layout' into 'master'
Resolve "Add padding, margin, border to Control."
Closes #12
See merge request crupest/CruUI!12
Diffstat (limited to 'src/ui/controls/text_box.cpp')
-rw-r--r-- | src/ui/controls/text_box.cpp | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp index 0d65f1ad..30b9069a 100644 --- a/src/ui/controls/text_box.cpp +++ b/src/ui/controls/text_box.cpp @@ -27,27 +27,22 @@ namespace cru::ui::controls Repaint(); }); - border_delegate_ = std::make_unique<BorderDelegate>(this); + SetBordered(true); } TextBox::~TextBox() = default; - void TextBox::OnDraw(ID2D1DeviceContext* device_context) + void TextBox::OnDrawContent(ID2D1DeviceContext* device_context) { - 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) + TextControl::OnDrawContent(device_context); + if (is_caret_show_) { - 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()); - } - }); + 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) @@ -138,11 +133,6 @@ 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; |