#pragma once #include "pre.hpp" #include // for ComPtr #include "render_object.hpp" // forward declarations struct ID2D1Brush; struct IDWriteTextFormat; struct IDWriteTextLayout; namespace cru::ui::render { class TextRenderObject : public RenderObject { public: TextRenderObject(Microsoft::WRL::ComPtr brush, Microsoft::WRL::ComPtr format, Microsoft::WRL::ComPtr selection_brush); TextRenderObject(const TextRenderObject& other) = delete; TextRenderObject(TextRenderObject&& other) = delete; TextRenderObject& operator=(const TextRenderObject& other) = delete; TextRenderObject& operator=(TextRenderObject&& other) = delete; ~TextRenderObject() override = default; String GetText() const { return text_; } void SetText(String new_text) { text_ = std::move(new_text); RecreateTextLayout(); } Microsoft::WRL::ComPtr GetBrush() const { return brush_; } void SetBrush(Microsoft::WRL::ComPtr new_brush) { brush_ = std::move(new_brush); } Microsoft::WRL::ComPtr GetTextFormat() const { return text_format_; } void SetTextFormat( Microsoft::WRL::ComPtr new_text_format) { text_format_ = std::move(new_text_format); RecreateTextLayout(); } std::optional GetSelectionRange() const { return selection_range_; } void SetSelectionRange(std::optional new_range) { selection_range_ = std::move(new_range); } Microsoft::WRL::ComPtr GetSelectionBrush() const { return selection_brush_; } void SetSelectionBrush(Microsoft::WRL::ComPtr new_brush) { selection_brush_ = std::move(new_brush); } void Draw(ID2D1RenderTarget* render_target) override; RenderObject* HitTest(const Point& point) override; protected: void OnSizeChanged(const Size& old_size, const Size& new_size) override; Size OnMeasureContent(const Size& available_size) override; void OnLayoutContent(const Rect& content_rect) override; private: void RecreateTextLayout(); private: String text_; Microsoft::WRL::ComPtr brush_; Microsoft::WRL::ComPtr text_format_; Microsoft::WRL::ComPtr text_layout_; std::optional selection_range_ = std::nullopt; Microsoft::WRL::ComPtr selection_brush_; }; } // namespace cru::ui::render