diff options
author | crupest <crupest@outlook.com> | 2020-03-03 23:36:45 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-03 23:36:45 +0800 |
commit | 0dcf8e686b93cca54a424affe0455d0a97d6c2ef (patch) | |
tree | 744897a3b6a29f6142f1943dab5d9957e670919b | |
parent | 47053829c322c43032244937cb63f9da178b852d (diff) | |
download | cru-0dcf8e686b93cca54a424affe0455d0a97d6c2ef.tar.gz cru-0dcf8e686b93cca54a424affe0455d0a97d6c2ef.tar.bz2 cru-0dcf8e686b93cca54a424affe0455d0a97d6c2ef.zip |
...
-rw-r--r-- | include/cru/platform/graph/font.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/controls/text_block.hpp | 23 | ||||
-rw-r--r-- | include/cru/ui/controls/text_box.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/controls/text_common.hpp | 66 | ||||
-rw-r--r-- | include/cru/ui/render/layout_utility.hpp | 7 | ||||
-rw-r--r-- | include/cru/ui/render/render_object.hpp | 9 | ||||
-rw-r--r-- | include/cru/ui/render/text_render_object.hpp | 7 | ||||
-rw-r--r-- | include/cru/ui/ui_event.hpp | 3 | ||||
-rw-r--r-- | include/cru/ui/ui_manager.hpp | 1 | ||||
-rw-r--r-- | include/cru/win/graph/direct/font.hpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/ui/controls/text_block.cpp | 44 | ||||
-rw-r--r-- | src/ui/controls/text_box.cpp | 8 | ||||
-rw-r--r-- | src/ui/controls/text_common.cpp | 113 | ||||
-rw-r--r-- | src/ui/render/render_object.cpp | 21 | ||||
-rw-r--r-- | src/ui/render/text_render_object.cpp | 13 | ||||
-rw-r--r-- | src/ui/ui_manager.cpp | 5 | ||||
-rw-r--r-- | src/win/graph/direct/font.cpp | 2 | ||||
-rw-r--r-- | src/win/graph/direct/text_layout.cpp | 6 |
20 files changed, 318 insertions, 24 deletions
diff --git a/include/cru/platform/graph/font.hpp b/include/cru/platform/graph/font.hpp index 98ce80e7..d0aa2d28 100644 --- a/include/cru/platform/graph/font.hpp +++ b/include/cru/platform/graph/font.hpp @@ -2,5 +2,7 @@ #include "resource.hpp" namespace cru::platform::graph { -struct IFont : virtual IGraphResource {}; +struct IFont : virtual IGraphResource { + virtual float GetFontSize() = 0; +}; } // namespace cru::platform::graph diff --git a/include/cru/ui/controls/text_block.hpp b/include/cru/ui/controls/text_block.hpp index 708b62f1..02e0eb2b 100644 --- a/include/cru/ui/controls/text_block.hpp +++ b/include/cru/ui/controls/text_block.hpp @@ -1,14 +1,18 @@ #pragma once #include "../no_child_control.hpp" +#include "text_common.hpp" + #include <memory> namespace cru::ui::render { +class StackLayoutRenderObject; class TextRenderObject; -} +class CanvasRenderObject; +} // namespace cru::ui::render namespace cru::ui::controls { -class TextBlock : public NoChildControl { +class TextBlock : public NoChildControl, public virtual ITextControl { public: static constexpr std::string_view control_type = "TextBlock"; @@ -24,16 +28,23 @@ class TextBlock : public NoChildControl { TextBlock& operator=(TextBlock&& other) = delete; ~TextBlock() override; - std::string_view GetControlType() const final { - return control_type; - } + std::string_view GetControlType() const final { return control_type; } render::RenderObject* GetRenderObject() const override; std::string GetText() const; void SetText(std::string text); + render::TextRenderObject* GetTextRenderObject() override; + render::CanvasRenderObject* GetCaretRenderObject() override; + platform::graph::IBrush* GetCaretBrush() override; + private: - std::unique_ptr<render::TextRenderObject> render_object_; + std::unique_ptr<render::StackLayoutRenderObject> root_render_object_; + std::unique_ptr<render::TextRenderObject> text_render_object_; + std::unique_ptr<render::CanvasRenderObject> caret_render_object_; + std::shared_ptr<platform::graph::IBrush> caret_brush_; + + std::unique_ptr<TextControlService> service_; }; } // namespace cru::ui::controls diff --git a/include/cru/ui/controls/text_box.hpp b/include/cru/ui/controls/text_box.hpp index 76a6299e..888a9527 100644 --- a/include/cru/ui/controls/text_box.hpp +++ b/include/cru/ui/controls/text_box.hpp @@ -5,6 +5,7 @@ namespace cru::ui::render { class BorderRenderObject; +class StackLayoutRenderObject; class TextRenderObject; class CanvasRenderObject; } // namespace cru::ui::render @@ -27,6 +28,7 @@ class TextBox : public NoChildControl { private: std::unique_ptr<render::BorderRenderObject> border_render_object_; + std::unique_ptr<render::StackLayoutRenderObject> stack_layout_render_object_; std::unique_ptr<render::TextRenderObject> text_render_object_; std::unique_ptr<render::CanvasRenderObject> caret_render_object_; }; diff --git a/include/cru/ui/controls/text_common.hpp b/include/cru/ui/controls/text_common.hpp new file mode 100644 index 00000000..7398764f --- /dev/null +++ b/include/cru/ui/controls/text_common.hpp @@ -0,0 +1,66 @@ +#pragma once +#include "../base.hpp" + +#include "cru/ui/ui_event.hpp" + +#include <functional> +#include <optional> + +namespace cru::platform::graph { +struct IBrush; +} + +namespace cru::ui::render { +class TextRenderObject; +class CanvasRenderObject; +} // namespace cru::ui::render + +namespace cru::ui::controls { + +struct ITextControl : virtual Interface { + virtual render::TextRenderObject* GetTextRenderObject() = 0; + virtual render::CanvasRenderObject* GetCaretRenderObject() = 0; + virtual platform::graph::IBrush* GetCaretBrush() = 0; +}; + +class TextControlService : public Object { + public: + TextControlService(Control* control, ITextControl* text_control); + + CRU_DELETE_COPY(TextControlService) + CRU_DELETE_MOVE(TextControlService) + + ~TextControlService(); + + public: + int GetCaretPosition() { return caret_position_; } + void SetCaretPosition(int position) { caret_position_ = position; } + + bool IsCaretVisible() { return caret_visible_; } + void SetCaretVisible(bool visible); + + // please set correct offset before calling this + void DrawCaret(platform::graph::IPainter* painter); + + private: + void SetupCaretTimer(); + void TearDownCaretTimer(); + + private: + Control* control_; + ITextControl* text_control_; + std::vector<EventRevokerGuard> event_revoker_guards_; + + bool caret_visible_ = false; + int caret_position_ = 0; + unsigned long caret_timer_tag_; + // this is used for blinking of caret + bool caret_show_ = true; + + // nullopt means not selecting + std::optional<MouseButton> select_down_button_; + + // before the char + int select_start_position_; +}; +} // namespace cru::ui::controls diff --git a/include/cru/ui/render/layout_utility.hpp b/include/cru/ui/render/layout_utility.hpp index 38191ad5..5cf74e71 100644 --- a/include/cru/ui/render/layout_utility.hpp +++ b/include/cru/ui/render/layout_utility.hpp @@ -1,6 +1,7 @@ +#pragma once #include "../base.hpp" namespace cru::ui::render { - Size Min(const Size& left, const Size& right); - Size Max(const Size& left, const Size& right); -} +Size Min(const Size& left, const Size& right); +Size Max(const Size& left, const Size& right); +} // namespace cru::ui::render diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index 0f0cb8df..d9851757 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -70,6 +70,8 @@ class RenderObject : public Object { Point GetOffset() const { return offset_; } void SetOffset(const Point& offset) { offset_ = offset; } + Point GetTotalOffset() const; + Point FromRootToContent(const Point& point) const; Size GetSize() const { return size_; } void SetSize(const Size& size) { size_ = size; } @@ -91,9 +93,7 @@ class RenderObject : public Object { virtual RenderObject* HitTest(const Point& point) = 0; - protected: - void SetChildMode(ChildMode mode) { child_mode_ = mode; } - + public: void InvalidateLayout() const { if (render_host_ != nullptr) render_host_->InvalidateLayout(); } @@ -103,6 +103,9 @@ class RenderObject : public Object { } protected: + void SetChildMode(ChildMode mode) { child_mode_ = mode; } + + protected: virtual void OnParentChanged(RenderObject* old_parent, RenderObject* new_parent); diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index 5394ee0a..33d34f78 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -1,6 +1,8 @@ #pragma once #include "render_object.hpp" +#include "cru/platform/graph/text_layout.hpp" + #include <memory> #include <string> @@ -8,7 +10,6 @@ namespace cru::platform::graph { struct IBrush; struct IFont; -struct ITextLayout; } // namespace cru::platform::graph namespace cru::ui::render { @@ -34,6 +35,10 @@ class TextRenderObject : public RenderObject { std::shared_ptr<platform::graph::IFont> GetFont() const; void SetFont(std::shared_ptr<platform::graph::IFont> font); + std::vector<Rect> TextRangeRect(const TextRange& text_range); + Point TextSingleRect(int position, bool trailing); + platform::graph::TextHitTestResult TextHitTest(const Point& point); + std::optional<TextRange> GetSelectionRange() const { return selection_range_; } diff --git a/include/cru/ui/ui_event.hpp b/include/cru/ui/ui_event.hpp index 147d3da6..c5af2b61 100644 --- a/include/cru/ui/ui_event.hpp +++ b/include/cru/ui/ui_event.hpp @@ -1,6 +1,8 @@ #pragma once #include "base.hpp" +#include "cru/common/event.hpp" + #include <memory> #include <optional> #include <type_traits> @@ -80,6 +82,7 @@ class MouseEventArgs : public UiEventArgs { MouseEventArgs& operator=(MouseEventArgs&& other) = default; ~MouseEventArgs() override = default; + // This point is relative to window client lefttop. Point GetPoint() const { return point_.value_or(Point{}); } private: diff --git a/include/cru/ui/ui_manager.hpp b/include/cru/ui/ui_manager.hpp index f196444c..8e5c7075 100644 --- a/include/cru/ui/ui_manager.hpp +++ b/include/cru/ui/ui_manager.hpp @@ -15,6 +15,7 @@ struct ThemeResources { std::shared_ptr<platform::graph::IFont> default_font; std::shared_ptr<platform::graph::IBrush> text_brush; std::shared_ptr<platform::graph::IBrush> text_selection_brush; + std::shared_ptr<platform::graph::IBrush> caret_brush; controls::ButtonStyle button_style; }; diff --git a/include/cru/win/graph/direct/font.hpp b/include/cru/win/graph/direct/font.hpp index 08213ca5..ee2e319b 100644 --- a/include/cru/win/graph/direct/font.hpp +++ b/include/cru/win/graph/direct/font.hpp @@ -24,6 +24,8 @@ class DWriteFont : public DirectGraphResource, return text_format_.Get(); } + float GetFontSize() override; + private: Microsoft::WRL::ComPtr<IDWriteTextFormat> text_format_; }; diff --git a/src/main.cpp b/src/main.cpp index e2a766dc..fb2222d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,10 @@ int main() { stack_layout->AddChild(text_block3, 1); flex_layout->AddChild(stack_layout, 1); + const auto text_block4 = TextBlock::Create(); + text_block4->SetText("Hello World!!!"); + flex_layout->AddChild(text_block4, 2); + window->ResolveNativeWindow()->SetVisible(true); return application->Run(); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 2220740e..dbd42d38 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -18,6 +18,7 @@ add_library(cru_ui STATIC controls/stack_layout.cpp controls/text_block.cpp controls/text_box.cpp + controls/text_common.cpp render/border_render_object.cpp render/canvas_render_object.cpp render/flex_layout_render_object.cpp @@ -43,6 +44,7 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/controls/stack_layout.hpp ${CRU_UI_INCLUDE_DIR}/controls/text_box.hpp ${CRU_UI_INCLUDE_DIR}/controls/text_block.hpp + ${CRU_UI_INCLUDE_DIR}/controls/text_common.hpp ${CRU_UI_INCLUDE_DIR}/render/border_render_object.hpp ${CRU_UI_INCLUDE_DIR}/render/canvas_render_object.hpp ${CRU_UI_INCLUDE_DIR}/render/flex_layout_render_object.hpp diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp index 9d01dee9..be064ea0 100644 --- a/src/ui/controls/text_block.cpp +++ b/src/ui/controls/text_block.cpp @@ -1,28 +1,60 @@ #include "cru/ui/controls/text_block.hpp" +#include "cru/ui/render/canvas_render_object.hpp" +#include "cru/ui/render/stack_layout_render_object.hpp" #include "cru/ui/render/text_render_object.hpp" #include "cru/ui/ui_manager.hpp" namespace cru::ui::controls { +using render::CanvasRenderObject; +using render::StackLayoutRenderObject; using render::TextRenderObject; -TextBlock::TextBlock() { +TextBlock::TextBlock() + : root_render_object_(new StackLayoutRenderObject()), + text_render_object_(), + caret_render_object_(new CanvasRenderObject()) { const auto theme_resources = UiManager::GetInstance()->GetThemeResources(); - render_object_ = std::make_unique<TextRenderObject>( + + text_render_object_ = std::make_unique<TextRenderObject>( theme_resources->text_brush, theme_resources->default_font, theme_resources->text_selection_brush); - render_object_->SetAttachedControl(this); + + root_render_object_->AddChild(text_render_object_.get(), 0); + root_render_object_->AddChild(caret_render_object_.get(), 1); + + root_render_object_->SetAttachedControl(this); + text_render_object_->SetAttachedControl(this); + caret_render_object_->SetAttachedControl(this); + + caret_brush_ = theme_resources->caret_brush; + + service_ = std::make_unique<TextControlService>(this, this); } TextBlock::~TextBlock() = default; render::RenderObject* TextBlock::GetRenderObject() const { - return render_object_.get(); + return root_render_object_.get(); } -std::string TextBlock::GetText() const { return render_object_->GetText(); } +std::string TextBlock::GetText() const { + return text_render_object_->GetText(); +} void TextBlock::SetText(std::string text) { - render_object_->SetText(std::move(text)); + text_render_object_->SetText(std::move(text)); +} + +render::TextRenderObject* TextBlock::GetTextRenderObject() { + return text_render_object_.get(); +} + +render::CanvasRenderObject* TextBlock::GetCaretRenderObject() { + return caret_render_object_.get(); +} + +platform::graph::IBrush* TextBlock::GetCaretBrush() { + return caret_brush_.get(); } } // namespace cru::ui::controls diff --git a/src/ui/controls/text_box.cpp b/src/ui/controls/text_box.cpp index 07b70b94..9c6fcbe5 100644 --- a/src/ui/controls/text_box.cpp +++ b/src/ui/controls/text_box.cpp @@ -2,16 +2,19 @@ #include "cru/ui/render/border_render_object.hpp" #include "cru/ui/render/canvas_render_object.hpp" +#include "cru/ui/render/stack_layout_render_object.hpp" #include "cru/ui/render/text_render_object.hpp" #include "cru/ui/ui_manager.hpp" namespace cru::ui::controls { using render::BorderRenderObject; using render::CanvasRenderObject; +using render::StackLayoutRenderObject; using render::TextRenderObject; TextBox::TextBox() : border_render_object_(new BorderRenderObject()), + stack_layout_render_object_(new StackLayoutRenderObject()), text_render_object_(), caret_render_object_(new CanvasRenderObject()) { const auto theme_resources = UiManager::GetInstance()->GetThemeResources(); @@ -20,7 +23,12 @@ TextBox::TextBox() theme_resources->text_brush, theme_resources->default_font, theme_resources->text_selection_brush); + border_render_object_->AddChild(stack_layout_render_object_.get(), 0); + stack_layout_render_object_->AddChild(text_render_object_.get(), 0); + stack_layout_render_object_->AddChild(caret_render_object_.get(), 1); + border_render_object_->SetAttachedControl(this); + stack_layout_render_object_->SetAttachedControl(this); text_render_object_->SetAttachedControl(this); caret_render_object_->SetAttachedControl(this); } diff --git a/src/ui/controls/text_common.cpp b/src/ui/controls/text_common.cpp new file mode 100644 index 00000000..d6bcdd03 --- /dev/null +++ b/src/ui/controls/text_common.cpp @@ -0,0 +1,113 @@ +#include "cru/ui/controls/text_common.hpp" + +#include "cru/common/logger.hpp" +#include "cru/platform/graph/font.hpp" +#include "cru/platform/graph/painter.hpp" +#include "cru/platform/native/ui_application.hpp" +#include "cru/ui/control.hpp" +#include "cru/ui/render/canvas_render_object.hpp" +#include "cru/ui/render/text_render_object.hpp" + +#include <cassert> + +namespace cru::ui::controls { +using platform::graph::ITextLayout; + +constexpr float caret_width = 2; +constexpr long long caret_blink_duration = 500; + +TextControlService::TextControlService(Control* control, + ITextControl* text_control) + : control_(control), text_control_(text_control) { + event_revoker_guards_.push_back( + EventRevokerGuard{control->MouseDownEvent()->Direct()->AddHandler( + [this](event::MouseButtonEventArgs& args) { + if (this->select_down_button_.has_value()) { + return; + } else { + if (!this->control_->CaptureMouse()) return; + const auto text_render_object = + this->text_control_->GetTextRenderObject(); + this->select_down_button_ = args.GetButton(); + const auto result = text_render_object->TextHitTest( + text_render_object->FromRootToContent(args.GetPoint())); + const auto position = result.position + (result.trailing ? 1 : 0); + this->select_start_position_ = position; + log::Debug("Begin to select text. Position: {}", position); + } + })}); + + event_revoker_guards_.push_back( + EventRevokerGuard{control->MouseMoveEvent()->Direct()->AddHandler( + [this](event::MouseEventArgs& args) { + if (this->select_down_button_.has_value()) { + const auto text_render_object = + this->text_control_->GetTextRenderObject(); + const auto result = text_render_object->TextHitTest( + text_render_object->FromRootToContent(args.GetPoint())); + const auto position = result.position + (result.trailing ? 1 : 0); + this->caret_position_ = position; + log::Debug("Text select range: {} : {}.", position, + this->select_start_position_); + this->text_control_->GetTextRenderObject()->SetSelectionRange( + TextRange::FromTwoSides( + static_cast<unsigned>(position), + static_cast<unsigned>(this->select_start_position_))); + this->text_control_->GetTextRenderObject()->InvalidatePaint(); + this->text_control_->GetCaretRenderObject()->InvalidatePaint(); + } + })}); + + event_revoker_guards_.push_back( + EventRevokerGuard{control->MouseUpEvent()->Direct()->AddHandler( + [this](event::MouseButtonEventArgs& args) { + if (this->select_down_button_.has_value() && + this->select_down_button_.value() == args.GetButton()) { + this->control_->ReleaseMouse(); + this->select_down_button_ = std::nullopt; + log::Debug("End selecting text."); + } + })}); +} + +TextControlService::~TextControlService() { TearDownCaretTimer(); } + +void TextControlService::SetCaretVisible(bool visible) { + if (visible) { + SetupCaretTimer(); + } else { + TearDownCaretTimer(); + } +} + +void TextControlService::DrawCaret(platform::graph::IPainter* painter) { + if (caret_show_) { + const auto text_render_object = text_control_->GetTextRenderObject(); + const auto point = text_render_object->TextSingleRect( + caret_position_, false); // Maybe cache the result??? + painter->FillRectangle( + Rect{point, + Size{caret_width, text_render_object->GetFont()->GetFontSize()}}, + text_control_->GetCaretBrush()); + } +} + +void TextControlService::SetupCaretTimer() { + if (caret_visible_) return; + + caret_visible_ = true; + caret_timer_tag_ = + platform::native::IUiApplication::GetInstance()->SetInterval( + std::chrono::milliseconds(caret_blink_duration), [this] { + this->caret_show_ = !this->caret_show_; + this->text_control_->GetCaretRenderObject()->InvalidatePaint(); + }); +} + +void TextControlService::TearDownCaretTimer() { + if (!caret_visible_) return; + caret_visible_ = false; + platform::native::IUiApplication::GetInstance()->CancelTimer( + caret_timer_tag_); +} +} // namespace cru::ui::controls diff --git a/src/ui/render/render_object.cpp b/src/ui/render/render_object.cpp index 54c2d1b4..5cce6d0d 100644 --- a/src/ui/render/render_object.cpp +++ b/src/ui/render/render_object.cpp @@ -35,6 +35,27 @@ void RenderObject::RemoveChild(const int position) { OnRemoveChild(removed_child, position); } +Point RenderObject::GetTotalOffset() const { + Point result{}; + const RenderObject* render_object = this; + + while (render_object != nullptr) { + const auto o = render_object->GetOffset(); + result.x += o.x; + result.y += o.y; + render_object = render_object->GetParent(); + } + + return result; +} + +Point RenderObject::FromRootToContent(const Point& point) const { + const auto offset = GetTotalOffset(); + const auto rect = GetContentRect(); + return Point{point.x - (offset.x + rect.left), + point.y - (offset.y + rect.top)}; +} + void RenderObject::Measure(const Size& available_size) { OnMeasureCore(available_size); } diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp index 6048f731..d14a46e2 100644 --- a/src/ui/render/text_render_object.cpp +++ b/src/ui/render/text_render_object.cpp @@ -47,6 +47,19 @@ void TextRenderObject::SetFont(std::shared_ptr<platform::graph::IFont> font) { text_layout_->SetFont(std::move(font)); } +std::vector<Rect> TextRenderObject::TextRangeRect(const TextRange& text_range) { + return text_layout_->TextRangeRect(text_range); +} + +Point TextRenderObject::TextSingleRect(int position, bool trailing) { + return text_layout_->TextSingleRect(position, trailing); +} + +platform::graph::TextHitTestResult TextRenderObject::TextHitTest( + const Point& point) { + return text_layout_->HitTest(point); +} + void TextRenderObject::Draw(platform::graph::IPainter* painter) { platform::graph::util::WithTransform( painter, diff --git a/src/ui/ui_manager.cpp b/src/ui/ui_manager.cpp index f71f900f..2a6d6e5b 100644 --- a/src/ui/ui_manager.cpp +++ b/src/ui/ui_manager.cpp @@ -32,9 +32,12 @@ UiManager::UiManager() { theme_resource_.default_font = factory->CreateFont("等线", 24.0f); - theme_resource_.text_brush = CreateSolidColorBrush(factory, colors::black); + const auto black_brush = std::shared_ptr<platform::graph::ISolidColorBrush>( + CreateSolidColorBrush(factory, colors::black)); + theme_resource_.text_brush = black_brush; theme_resource_.text_selection_brush = CreateSolidColorBrush(factory, colors::skyblue); + theme_resource_.caret_brush = black_brush; theme_resource_.button_style.normal.border_brush = CreateSolidColorBrush(factory, Color::FromHex(0x00bfff)); diff --git a/src/win/graph/direct/font.cpp b/src/win/graph/direct/font.cpp index 8e881f84..6bd43078 100644 --- a/src/win/graph/direct/font.cpp +++ b/src/win/graph/direct/font.cpp @@ -29,4 +29,6 @@ DWriteFont::DWriteFont(DirectGraphFactory* factory, ThrowIfFailed( text_format_->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER)); } + +float DWriteFont::GetFontSize() { return text_format_->GetFontSize(); } } // namespace cru::platform::graph::win::direct diff --git a/src/win/graph/direct/text_layout.cpp b/src/win/graph/direct/text_layout.cpp index ecee1727..59101163 100644 --- a/src/win/graph/direct/text_layout.cpp +++ b/src/win/graph/direct/text_layout.cpp @@ -1,5 +1,6 @@ #include "cru/win/graph/direct/text_layout.hpp" +#include "cru/common/logger.hpp" #include "cru/platform/check.hpp" #include "cru/win/graph/direct/exception.hpp" #include "cru/win/graph/direct/factory.hpp" @@ -92,9 +93,8 @@ std::vector<Rect> DWriteTextLayout::TextRangeRect(const TextRange& text_range) { result.reserve(actual_count); for (const auto& metrics : hit_test_metrics) { - result.push_back(Rect{metrics.left, metrics.top, - metrics.left + metrics.width, - metrics.top + metrics.height}); + result.push_back( + Rect{metrics.left, metrics.top, metrics.width, metrics.height}); } return result; |