diff options
author | Yuqian Yang <crupest@outlook.com> | 2018-10-01 17:11:11 +0000 |
---|---|---|
committer | Yuqian Yang <crupest@outlook.com> | 2018-10-01 17:11:11 +0000 |
commit | 30ecda8bb354d5982978af97aa90b5f49d9ea195 (patch) | |
tree | a271bddb244fa2041f14f8d46d249457cee09e5f /src/ui/controls/text_box.cpp | |
parent | 398b8f3ba535bb43c4b8593e3027c14894a7a211 (diff) | |
parent | 040a6c18f18100b825a56443a73aa1de64e4518c (diff) | |
download | cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.gz cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.tar.bz2 cru-30ecda8bb354d5982978af97aa90b5f49d9ea195.zip |
Merge branch '9-border' into 'master'
Resolve "Abstract out border control of button and border."
Closes #9
See merge request crupest/CruUI!11
Diffstat (limited to 'src/ui/controls/text_box.cpp')
-rw-r--r-- | src/ui/controls/text_box.cpp | 28 |
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; |