diff options
Diffstat (limited to 'include/cru/ui/render')
-rw-r--r-- | include/cru/ui/render/border_render_object.hpp | 59 | ||||
-rw-r--r-- | include/cru/ui/render/render_object.hpp | 6 | ||||
-rw-r--r-- | include/cru/ui/render/window_render_object.hpp | 4 |
3 files changed, 55 insertions, 14 deletions
diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp index 22e8ab58..18809f91 100644 --- a/include/cru/ui/render/border_render_object.hpp +++ b/include/cru/ui/render/border_render_object.hpp @@ -32,11 +32,16 @@ struct CornerRadius { Point right_bottom; }; -struct BorderStyle { - std::shared_ptr<platform::graph::Brush> brush{}; - Thickness thickness{}; - CornerRadius corner_radius{}; -}; +inline bool operator==(const CornerRadius& left, const CornerRadius& right) { + return left.left_top == right.left_top && + left.left_bottom == right.left_bottom && + left.right_top == right.right_top && + left.right_bottom == right.right_bottom; +} + +inline bool operator!=(const CornerRadius& left, const CornerRadius& right) { + return !(left == right); +} class BorderRenderObject : public RenderObject { public: @@ -50,8 +55,30 @@ class BorderRenderObject : public RenderObject { bool IsBorderEnabled() const { return is_border_enabled_; } void SetBorderEnabled(bool enabled) { is_border_enabled_ = enabled; } - BorderStyle* GetBorderStyle() { - return &border_style_; + std::shared_ptr<platform::graph::Brush> GetBorderBrush() { + return border_brush_; + } + + void SetBorderBrush(std::shared_ptr<platform::graph::Brush> brush) { + if (brush == border_brush_) return; + border_brush_ = std::move(brush); + InvalidatePaint(); + } + + platform::Thickness GetBorderThickness() { return border_thickness_; } + + void SetBorderThickness(const platform::Thickness thickness) { + if (thickness == border_thickness_) return; + border_thickness_ = thickness; + InvalidateLayout(); + } + + CornerRadius GetBorderRadius() { return border_radius_; } + + void SetBorderRadius(const CornerRadius radius) { + if (radius == border_radius_) return; + border_radius_ = radius; + RecreateGeometry(); } std::shared_ptr<platform::graph::Brush> GetForegroundBrush() { @@ -59,19 +86,21 @@ class BorderRenderObject : public RenderObject { } void SetForegroundBrush(std::shared_ptr<platform::graph::Brush> brush) { + if (brush == foreground_brush_) return; foreground_brush_ = std::move(brush); + InvalidatePaint(); } std::shared_ptr<platform::graph::Brush> GetBackgroundBrush() { - return foreground_brush_; + return background_brush_; } void SetBackgroundBrush(std::shared_ptr<platform::graph::Brush> brush) { - foreground_brush_ = std::move(brush); + if (brush == background_brush_) return; + background_brush_ = std::move(brush); + InvalidatePaint(); } - void Refresh() { RecreateGeometry(); } - void Draw(platform::graph::Painter* painter) override; RenderObject* HitTest(const Point& point) override; @@ -93,14 +122,18 @@ class BorderRenderObject : public RenderObject { private: bool is_border_enabled_ = false; - BorderStyle border_style_; + + std::shared_ptr<platform::graph::Brush> border_brush_; + platform::Thickness border_thickness_; + CornerRadius border_radius_; std::shared_ptr<platform::graph::Brush> foreground_brush_; std::shared_ptr<platform::graph::Brush> background_brush_; // The ring. Used for painting. std::unique_ptr<platform::graph::Geometry> geometry_; - // Area including inner area of the border. Used for painting foreground and background. + // Area including inner area of the border. Used for painting foreground and + // background. std::unique_ptr<platform::graph::Geometry> border_inner_geometry_; // Area including border ring and inner area. Used for hit test. std::unique_ptr<platform::graph::Geometry> border_outer_geometry_; diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index 8ea7ca79..2394bf97 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -2,6 +2,7 @@ #include "cru/common/base.hpp" #include "../base.hpp" +#include "cru/common/event.hpp" #include <vector> @@ -15,6 +16,9 @@ class Painter; } namespace cru::ui::render { + +struct AfterLayoutEventArgs {}; + struct IRenderHost : Interface { // Mark the layout as invalid, and arrange a re-layout later. // Note this method might be called more than one times in a message cycle. So @@ -25,6 +29,8 @@ struct IRenderHost : Interface { // Note this method might be called more than one times in a message cycle. So // implementation should merge multiple request into once. virtual void InvalidatePaint() = 0; + + virtual IEvent<AfterLayoutEventArgs>* AfterLayoutEvent() = 0; }; class RenderObject : public Object { diff --git a/include/cru/ui/render/window_render_object.hpp b/include/cru/ui/render/window_render_object.hpp index e73a6bfe..431f7025 100644 --- a/include/cru/ui/render/window_render_object.hpp +++ b/include/cru/ui/render/window_render_object.hpp @@ -17,7 +17,9 @@ class WindowRenderObject : public RenderObject { WindowRenderObject& operator=(WindowRenderObject&& other) = delete; ~WindowRenderObject() override = default; - void MeasureAndLayout(); + Window* GetWindow() const { return window_; } + + void Relayout(); void Draw(platform::graph::Painter* painter) override; |