From 9110574bb51e9e2959842a7641f598d34c3cd847 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 13 Dec 2019 01:02:47 +0800 Subject: ... --- include/cru/ui/render/border_render_object.hpp | 30 ++++++++--------- .../cru/ui/render/flex_layout_render_object.hpp | 2 +- include/cru/ui/render/render_object.hpp | 7 ++-- include/cru/ui/render/text_render_object.hpp | 38 +++++++++++----------- include/cru/ui/render/window_render_object.hpp | 2 +- 5 files changed, 38 insertions(+), 41 deletions(-) (limited to 'include/cru/ui/render') diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp index 5520ab2e..726510a8 100644 --- a/include/cru/ui/render/border_render_object.hpp +++ b/include/cru/ui/render/border_render_object.hpp @@ -1,13 +1,11 @@ #pragma once -#include "cru/platform/graph/brush.hpp" -#include "cru/ui/base.hpp" #include "render_object.hpp" #include namespace cru::platform::graph { -class Brush; -class IGeometry; +struct IBrush; +struct IGeometry; } // namespace cru::platform::graph namespace cru::ui::render { @@ -55,19 +53,19 @@ class BorderRenderObject : public RenderObject { bool IsBorderEnabled() const { return is_border_enabled_; } void SetBorderEnabled(bool enabled) { is_border_enabled_ = enabled; } - std::shared_ptr GetBorderBrush() { + std::shared_ptr GetBorderBrush() { return border_brush_; } - void SetBorderBrush(std::shared_ptr brush) { + void SetBorderBrush(std::shared_ptr brush) { if (brush == border_brush_) return; border_brush_ = std::move(brush); InvalidatePaint(); } - platform::Thickness GetBorderThickness() { return border_thickness_; } + Thickness GetBorderThickness() { return border_thickness_; } - void SetBorderThickness(const platform::Thickness thickness) { + void SetBorderThickness(const Thickness thickness) { if (thickness == border_thickness_) return; border_thickness_ = thickness; InvalidateLayout(); @@ -81,27 +79,27 @@ class BorderRenderObject : public RenderObject { RecreateGeometry(); } - std::shared_ptr GetForegroundBrush() { + std::shared_ptr GetForegroundBrush() { return foreground_brush_; } - void SetForegroundBrush(std::shared_ptr brush) { + void SetForegroundBrush(std::shared_ptr brush) { if (brush == foreground_brush_) return; foreground_brush_ = std::move(brush); InvalidatePaint(); } - std::shared_ptr GetBackgroundBrush() { + std::shared_ptr GetBackgroundBrush() { return background_brush_; } - void SetBackgroundBrush(std::shared_ptr brush) { + void SetBackgroundBrush(std::shared_ptr brush) { if (brush == background_brush_) return; background_brush_ = std::move(brush); InvalidatePaint(); } - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -123,12 +121,12 @@ class BorderRenderObject : public RenderObject { private: bool is_border_enabled_ = false; - std::shared_ptr border_brush_; + std::shared_ptr border_brush_; platform::Thickness border_thickness_; CornerRadius border_radius_; - std::shared_ptr foreground_brush_; - std::shared_ptr background_brush_; + std::shared_ptr foreground_brush_; + std::shared_ptr background_brush_; // The ring. Used for painting. std::unique_ptr geometry_; diff --git a/include/cru/ui/render/flex_layout_render_object.hpp b/include/cru/ui/render/flex_layout_render_object.hpp index 7b71b96e..5a8d09ba 100644 --- a/include/cru/ui/render/flex_layout_render_object.hpp +++ b/include/cru/ui/render/flex_layout_render_object.hpp @@ -78,7 +78,7 @@ class FlexLayoutRenderObject : public RenderObject { InvalidateLayout(); } - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index befaa3ec..55b7f2da 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -1,7 +1,6 @@ #pragma once -#include "cru/common/base.hpp" - #include "../base.hpp" + #include "cru/common/event.hpp" #include @@ -12,7 +11,7 @@ class Control; } namespace cru::platform::graph { -class Painter; +struct IPainter; } namespace cru::ui::render { @@ -75,7 +74,7 @@ class RenderObject : public Object { void Measure(const Size& available_size); void Layout(const Rect& rect); - virtual void Draw(platform::graph::Painter* painter) = 0; + virtual void Draw(platform::graph::IPainter* painter) = 0; virtual RenderObject* HitTest(const Point& point) = 0; diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index a10e3b74..6c01ed93 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -6,33 +6,33 @@ // forward declarations namespace cru::platform::graph { -class Brush; -class Font; -class TextLayout; +struct IBrush; +struct IFont; +struct ITextLayout; } // namespace cru::platform::graph namespace cru::ui::render { class TextRenderObject : public RenderObject { public: - TextRenderObject(std::shared_ptr brush, - std::shared_ptr font, - std::shared_ptr selection_brush); + TextRenderObject(std::shared_ptr brush, + std::shared_ptr font, + std::shared_ptr 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; - std::wstring GetText() const; - void SetText(std::wstring new_text); + std::string GetText() const; + void SetText(std::string new_text); - std::shared_ptr GetBrush() const { return brush_; } - void SetBrush(std::shared_ptr new_brush) { + std::shared_ptr GetBrush() const { return brush_; } + void SetBrush(std::shared_ptr new_brush) { new_brush.swap(brush_); } - std::shared_ptr GetFont() const; - void SetFont(std::shared_ptr font); + std::shared_ptr GetFont() const; + void SetFont(std::shared_ptr font); std::optional GetSelectionRange() const { return selection_range_; @@ -41,14 +41,14 @@ class TextRenderObject : public RenderObject { selection_range_ = std::move(new_range); } - std::shared_ptr GetSelectionBrush() const { + std::shared_ptr GetSelectionBrush() const { return selection_brush_; } - void SetSelectionBrush(std::shared_ptr new_brush) { + void SetSelectionBrush(std::shared_ptr new_brush) { new_brush.swap(selection_brush_); } - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -59,11 +59,11 @@ class TextRenderObject : public RenderObject { void OnAfterLayout() override; private: - std::shared_ptr brush_; - std::shared_ptr font_; - std::shared_ptr text_layout_; + std::shared_ptr brush_; + std::shared_ptr font_; + std::unique_ptr text_layout_; std::optional selection_range_ = std::nullopt; - std::shared_ptr selection_brush_; + std::shared_ptr selection_brush_; }; } // namespace cru::ui::render diff --git a/include/cru/ui/render/window_render_object.hpp b/include/cru/ui/render/window_render_object.hpp index 2260c293..8f35ad80 100644 --- a/include/cru/ui/render/window_render_object.hpp +++ b/include/cru/ui/render/window_render_object.hpp @@ -21,7 +21,7 @@ class WindowRenderObject : public RenderObject { void Relayout(); - void Draw(platform::graph::Painter* painter) override; + void Draw(platform::graph::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; -- cgit v1.2.3