aboutsummaryrefslogtreecommitdiff
path: root/src/ui/render/TextRenderObject.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-06-28 22:17:14 +0800
committercrupest <crupest@outlook.com>2020-06-28 22:17:14 +0800
commit427bd31059fcdca5806a149238e91173667953c1 (patch)
treedec0794e8445040f8b177aaa29e0600380e5420f /src/ui/render/TextRenderObject.cpp
parent26da84f59396075118ee769654471159e1f49980 (diff)
downloadcru-427bd31059fcdca5806a149238e91173667953c1.tar.gz
cru-427bd31059fcdca5806a149238e91173667953c1.tar.bz2
cru-427bd31059fcdca5806a149238e91173667953c1.zip
...
Diffstat (limited to 'src/ui/render/TextRenderObject.cpp')
-rw-r--r--src/ui/render/TextRenderObject.cpp68
1 files changed, 31 insertions, 37 deletions
diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp
index e0c68683..7efffafb 100644
--- a/src/ui/render/TextRenderObject.cpp
+++ b/src/ui/render/TextRenderObject.cpp
@@ -118,48 +118,42 @@ void TextRenderObject::SetCaretWidth(const float width) {
}
}
-void TextRenderObject::Draw(platform::graph::IPainter* painter) {
- platform::graph::util::WithTransform(
- painter,
- platform::Matrix::Translation(GetMargin().left + GetPadding().left,
- GetMargin().top + GetPadding().top),
- [this](platform::graph::IPainter* p) {
- if (this->selection_range_.has_value()) {
- const auto&& rects =
- text_layout_->TextRangeRect(this->selection_range_.value());
- for (const auto& rect : rects)
- p->FillRectangle(rect, this->GetSelectionBrush().get());
- }
-
- p->DrawText(Point{}, text_layout_.get(), brush_.get());
-
- if (this->draw_caret_ && this->caret_width_ != 0.0f) {
- auto caret_pos = this->caret_position_;
- gsl::index text_size = this->GetText().size();
- if (caret_pos < 0) {
- caret_pos = 0;
- } else if (caret_pos > text_size) {
- caret_pos = text_size;
- }
-
- const auto caret_top_center =
- this->text_layout_->TextSinglePoint(caret_pos, false);
-
- const auto font_height = this->font_->GetFontSize();
- const auto caret_width = this->caret_width_;
-
- p->FillRectangle(Rect{caret_top_center.x - caret_width / 2.0f,
- caret_top_center.y, caret_width, font_height},
- this->caret_brush_.get());
- }
- });
-}
-
RenderObject* TextRenderObject::HitTest(const Point& point) {
const auto padding_rect = GetPaddingRect();
return padding_rect.IsPointInside(point) ? this : nullptr;
}
+void TextRenderObject::OnDrawContent(platform::graph::IPainter* painter) {
+ if (this->selection_range_.has_value()) {
+ const auto&& rects =
+ text_layout_->TextRangeRect(this->selection_range_.value());
+ for (const auto& rect : rects)
+ painter->FillRectangle(rect, this->GetSelectionBrush().get());
+ }
+
+ painter->DrawText(Point{}, text_layout_.get(), brush_.get());
+
+ if (this->draw_caret_ && this->caret_width_ != 0.0f) {
+ auto caret_pos = this->caret_position_;
+ gsl::index text_size = this->GetText().size();
+ if (caret_pos < 0) {
+ caret_pos = 0;
+ } else if (caret_pos > text_size) {
+ caret_pos = text_size;
+ }
+
+ const auto caret_top_center =
+ this->text_layout_->TextSinglePoint(caret_pos, false);
+
+ const auto font_height = this->font_->GetFontSize();
+ const auto caret_width = this->caret_width_;
+
+ painter->FillRectangle(Rect{caret_top_center.x - caret_width / 2.0f,
+ caret_top_center.y, caret_width, font_height},
+ this->caret_brush_.get());
+ }
+}
+
Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement,
const MeasureSize& preferred_size) {
float measure_width;