diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-21 21:43:42 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-21 22:13:54 +0800 |
| commit | fd61739197ec009d47da87a7cc66970a55f12db4 (patch) | |
| tree | bb2bc007aaf9b47fecb090df96c23b5ee6a898e3 | |
| parent | 3b875091c445b7465b9bd044914318989a94d2ad (diff) | |
| download | cru-fd61739197ec009d47da87a7cc66970a55f12db4.tar.gz cru-fd61739197ec009d47da87a7cc66970a55f12db4.tar.bz2 cru-fd61739197ec009d47da87a7cc66970a55f12db4.zip | |
Clean codes. Remove member function const in RenderObject.
25 files changed, 157 insertions, 202 deletions
diff --git a/include/cru/ui/render/BorderRenderObject.h b/include/cru/ui/render/BorderRenderObject.h index 001494a6..16f04962 100644 --- a/include/cru/ui/render/BorderRenderObject.h +++ b/include/cru/ui/render/BorderRenderObject.h @@ -6,15 +6,14 @@ namespace cru::ui::render { class CRU_UI_API BorderRenderObject : public SingleChildRenderObject { - CRU_DEFINE_CLASS_LOG_TAG("BorderRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::BorderRenderObject") public: + static constexpr auto kRenderObjectName = "BorderRenderObject"; + BorderRenderObject(); - CRU_DELETE_COPY(BorderRenderObject) - CRU_DELETE_MOVE(BorderRenderObject) - ~BorderRenderObject() override; - bool IsBorderEnabled() const { return is_border_enabled_; } + bool IsBorderEnabled() { return is_border_enabled_; } void SetBorderEnabled(bool enabled); std::shared_ptr<platform::graphics::IBrush> GetBorderBrush() { @@ -22,7 +21,7 @@ class CRU_UI_API BorderRenderObject : public SingleChildRenderObject { } void SetBorderBrush(std::shared_ptr<platform::graphics::IBrush> brush); - Thickness GetBorderThickness() const { return border_thickness_; } + Thickness GetBorderThickness() { return border_thickness_; } void SetBorderThickness(const Thickness thickness); CornerRadius GetBorderRadius() { return border_radius_; } @@ -45,12 +44,10 @@ class CRU_UI_API BorderRenderObject : public SingleChildRenderObject { RenderObject* HitTest(const Point& point) override; void Draw(platform::graphics::IPainter* painter) override; - Thickness GetTotalSpaceThickness() const override; - Thickness GetInnerSpaceThickness() const override; - Rect GetPaddingRect() const override; - Rect GetContentRect() const override; - - std::string GetName() const override; + Thickness GetTotalSpaceThickness() override; + Thickness GetInnerSpaceThickness() override; + Rect GetPaddingRect() override; + Rect GetContentRect() override; protected: Size OnMeasureContent(const MeasureRequirement& requirement, diff --git a/include/cru/ui/render/CanvasRenderObject.h b/include/cru/ui/render/CanvasRenderObject.h index dfe8f090..3471d75f 100644 --- a/include/cru/ui/render/CanvasRenderObject.h +++ b/include/cru/ui/render/CanvasRenderObject.h @@ -26,17 +26,14 @@ class CanvasPaintEventArgs { // required range. class CRU_UI_API CanvasRenderObject : public RenderObject { public: - CanvasRenderObject(); - - CRU_DELETE_COPY(CanvasRenderObject) - CRU_DELETE_MOVE(CanvasRenderObject) + static constexpr auto kRenderObjectName = "CanvasRenderObject"; - ~CanvasRenderObject(); + CanvasRenderObject(); public: RenderObject* HitTest(const Point& point) override; - Size GetDesiredSize() const { return desired_size_; } + Size GetDesiredSize() { return desired_size_; } IEvent<CanvasPaintEventArgs>* PaintEvent() { return &paint_event_; } diff --git a/include/cru/ui/render/FlexLayoutRenderObject.h b/include/cru/ui/render/FlexLayoutRenderObject.h index bf68720a..82ac6639 100644 --- a/include/cru/ui/render/FlexLayoutRenderObject.h +++ b/include/cru/ui/render/FlexLayoutRenderObject.h @@ -93,32 +93,26 @@ struct FlexChildLayoutData { // class CRU_UI_API FlexLayoutRenderObject : public LayoutRenderObject<FlexChildLayoutData> { - CRU_DEFINE_CLASS_LOG_TAG("FlexLayoutRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::FlexLayoutRenderObject") public: - FlexLayoutRenderObject() = default; - FlexLayoutRenderObject(const FlexLayoutRenderObject& other) = delete; - FlexLayoutRenderObject& operator=(const FlexLayoutRenderObject& other) = - delete; - FlexLayoutRenderObject(FlexLayoutRenderObject&& other) = delete; - FlexLayoutRenderObject& operator=(FlexLayoutRenderObject&& other) = delete; - ~FlexLayoutRenderObject() override = default; + static constexpr auto kRenderObjectName = "FlexLayoutRenderObject"; - std::string GetName() const override; + FlexLayoutRenderObject(); - FlexDirection GetFlexDirection() const { return direction_; } + FlexDirection GetFlexDirection() { return direction_; } void SetFlexDirection(FlexDirection direction) { direction_ = direction; InvalidateLayout(); } - FlexMainAlignment GetContentMainAlign() const { return content_main_align_; } + FlexMainAlignment GetContentMainAlign() { return content_main_align_; } void SetContentMainAlign(FlexMainAlignment align) { content_main_align_ = align; InvalidateLayout(); } - FlexCrossAlignment GetItemCrossAlign() const { return item_cross_align_; } + FlexCrossAlignment GetItemCrossAlign() { return item_cross_align_; } void SetItemCrossAlign(FlexCrossAlignment align) { item_cross_align_ = align; InvalidateLayout(); diff --git a/include/cru/ui/render/GeometryRenderObject.h b/include/cru/ui/render/GeometryRenderObject.h index 5d2ba1e0..1c998ef0 100644 --- a/include/cru/ui/render/GeometryRenderObject.h +++ b/include/cru/ui/render/GeometryRenderObject.h @@ -1,39 +1,37 @@ #pragma once +#include "MeasureRequirement.h" #include "RenderObject.h" -#include "cru/platform/graphics/Brush.h" -#include "cru/platform/graphics/Geometry.h" -#include "cru/ui/render/MeasureRequirement.h" + +#include <cru/platform/graphics/Brush.h> +#include <cru/platform/graphics/Geometry.h> #include <optional> namespace cru::ui::render { class GeometryRenderObject : public RenderObject { public: - GeometryRenderObject(); + static constexpr auto kRenderObjectName = "GeometryRenderObject"; - CRU_DELETE_COPY(GeometryRenderObject) - CRU_DELETE_MOVE(GeometryRenderObject) - - ~GeometryRenderObject() override; + GeometryRenderObject(); public: void Draw(platform::graphics::IPainter* painter) override; RenderObject* HitTest(const Point& point) override; - std::shared_ptr<platform::graphics::IGeometry> GetGeometry() const; + std::shared_ptr<platform::graphics::IGeometry> GetGeometry(); void SetGeometry(std::shared_ptr<platform::graphics::IGeometry> geometry, std::optional<Rect> view_port = std::nullopt); - Rect GetViewPort() const; + Rect GetViewPort(); void SetViewPort(const Rect& view_port); - std::shared_ptr<platform::graphics::IBrush> GetFillBrush() const; + std::shared_ptr<platform::graphics::IBrush> GetFillBrush(); void SetFillBrush(std::shared_ptr<platform::graphics::IBrush> brush); - std::shared_ptr<platform::graphics::IBrush> GetStrokeBrush() const; + std::shared_ptr<platform::graphics::IBrush> GetStrokeBrush(); void SetStrokeBrush(std::shared_ptr<platform::graphics::IBrush> brush); - float GetStrokeWidth() const; + float GetStrokeWidth(); void SetStrokeWidth(float width); protected: diff --git a/include/cru/ui/render/LayoutRenderObject.h b/include/cru/ui/render/LayoutRenderObject.h index 9970c16c..4010ae7c 100644 --- a/include/cru/ui/render/LayoutRenderObject.h +++ b/include/cru/ui/render/LayoutRenderObject.h @@ -20,15 +20,10 @@ class LayoutRenderObject : public RenderObject { }; protected: - LayoutRenderObject() = default; + LayoutRenderObject(std::string name) : RenderObject(std::move(name)) {} public: - CRU_DELETE_COPY(LayoutRenderObject) - CRU_DELETE_MOVE(LayoutRenderObject) - - ~LayoutRenderObject() override = default; - - Index GetChildCount() const { return static_cast<Index>(children_.size()); } + Index GetChildCount() { return static_cast<Index>(children_.size()); } RenderObject* GetChildAt(Index position) { Expects(position >= 0 && position < GetChildCount()); @@ -75,7 +70,7 @@ class LayoutRenderObject : public RenderObject { InvalidateLayout(); } - const ChildLayoutData& GetChildLayoutDataAt(Index position) const { + const ChildLayoutData& GetChildLayoutDataAt(Index position) { Expects(position >= 0 && position < GetChildCount()); return children_[position].layout_data; } diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h index c7e534a8..5569c788 100644 --- a/include/cru/ui/render/RenderObject.h +++ b/include/cru/ui/render/RenderObject.h @@ -5,6 +5,7 @@ #include <cru/base/Event.h> #include <cru/platform/graphics/Painter.h> +#include <string> namespace cru::ui::render { struct BoxConstraint { @@ -61,52 +62,52 @@ struct BoxConstraint { * content_rect) override; */ class CRU_UI_API RenderObject : public Object { - CRU_DEFINE_CLASS_LOG_TAG("RenderObject") + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::RenderObject") public: + RenderObject(std::string name); ~RenderObject() override; - controls::Control* GetAttachedControl() const { return control_; } + controls::Control* GetAttachedControl() { return control_; } void SetAttachedControl(controls::Control* new_control); - RenderObject* GetParent() const { return parent_; } + RenderObject* GetParent() { return parent_; } void SetParent(RenderObject* new_parent); // Offset from parent's lefttop to lefttop of this render object. Margin is // accounted for. - Point GetOffset() const { return offset_; } - Size GetSize() const { return size_; } + Point GetOffset() { return offset_; } + Size GetSize() { return size_; } - Point GetTotalOffset() const; - Point FromRootToContent(const Point& point) const; + Point GetTotalOffset(); + Point FromRootToContent(const Point& point); - Size GetDesiredSize() const { return desired_size_; } + Size GetDesiredSize() { return desired_size_; } - Thickness GetMargin() const { return margin_; } + Thickness GetMargin() { return margin_; } void SetMargin(const Thickness& margin); - Thickness GetPadding() const { return padding_; } + Thickness GetPadding() { return padding_; } void SetPadding(const Thickness& padding); - MeasureSize GetPreferredSize() const { return preferred_size_; } + MeasureSize GetPreferredSize() { return preferred_size_; } void SetPreferredSize(const MeasureSize& preferred_size); - MeasureSize GetMinSize() const { return custom_measure_requirement_.min; } + MeasureSize GetMinSize() { return custom_measure_requirement_.min; } void SetMinSize(const MeasureSize& min_size); - MeasureSize GetMaxSize() const { return custom_measure_requirement_.max; } + MeasureSize GetMaxSize() { return custom_measure_requirement_.max; } void SetMaxSize(const MeasureSize& max_size); - MeasureRequirement GetCustomMeasureRequirement() const { + MeasureRequirement GetCustomMeasureRequirement() { return custom_measure_requirement_; } - Size GetMinSize1() const { return min_size_; } + Size GetMinSize1() { return min_size_; } void SetMinSize1(const Size& min_size); - Size GetMaxSize1() const { return max_size_; } + Size GetMaxSize1() { return max_size_; } void SetMaxSize1(const Size& max_size); - BoxConstraint CalculateMergedConstraint( - const BoxConstraint& constraint) const; + BoxConstraint CalculateMergedConstraint(const BoxConstraint& constraint); // This method will merge requirement passed by argument and requirement of // the render object using MeasureRequirement::Merge and then call @@ -122,11 +123,11 @@ class CRU_UI_API RenderObject : public Object { Size Measure1(const BoxConstraint& constraint); - virtual Thickness GetTotalSpaceThickness() const; - virtual Thickness GetInnerSpaceThickness() const; + virtual Thickness GetTotalSpaceThickness(); + virtual Thickness GetInnerSpaceThickness(); - virtual Rect GetPaddingRect() const; - virtual Rect GetContentRect() const; + virtual Rect GetPaddingRect(); + virtual Rect GetContentRect(); virtual void Draw(platform::graphics::IPainter* painter) = 0; @@ -140,8 +141,8 @@ class CRU_UI_API RenderObject : public Object { void InvalidatePaint(); public: - virtual std::string GetName() const; - std::string GetDebugPathInTree() const; + std::string GetName(); + std::string GetDebugPathInTree(); CRU_DEFINE_EVENT(Destroy, RenderObject*) @@ -180,6 +181,7 @@ class CRU_UI_API RenderObject : public Object { virtual void OnResize(const Size& new_size) {} private: + std::string name_; controls::Control* control_ = nullptr; RenderObject* parent_ = nullptr; diff --git a/include/cru/ui/render/ScrollBar.h b/include/cru/ui/render/ScrollBar.h index 2325acd1..f3a42b66 100644 --- a/include/cru/ui/render/ScrollBar.h +++ b/include/cru/ui/render/ScrollBar.h @@ -1,13 +1,12 @@ #pragma once -#include "cru/base/Base.h" -#include "cru/base/Event.h" -#include "cru/platform/graphics/Base.h" -#include "cru/platform/graphics/Brush.h" -#include "cru/platform/graphics/Geometry.h" -#include "cru/platform/graphics/Painter.h" -#include "cru/platform/gui/UiApplication.h" -#include "cru/ui/Base.h" -#include "cru/ui/controls/Control.h" +#include "../Base.h" +#include "../controls/Control.h" + +#include <cru/platform/graphics/Base.h> +#include <cru/platform/graphics/Brush.h> +#include <cru/platform/graphics/Geometry.h> +#include <cru/platform/graphics/Painter.h> +#include <cru/platform/gui/UiApplication.h> #include <memory> #include <optional> @@ -45,12 +44,12 @@ class CRU_UI_API ScrollBar : public Object { ~ScrollBar() override; public: - Direction GetDirection() const { return direction_; } + Direction GetDirection() { return direction_; } - bool IsEnabled() const { return is_enabled_; } + bool IsEnabled() { return is_enabled_; } void SetEnabled(bool value); - bool IsExpanded() const { return is_expanded_; } + bool IsExpanded() { return is_expanded_; } void SetExpanded(bool value); void Draw(platform::graphics::IPainter* painter); @@ -209,12 +208,12 @@ class CRU_UI_API ScrollBarDelegate : public Object { ~ScrollBarDelegate() override = default; public: - bool IsHorizontalBarEnabled() const { return horizontal_bar_.IsEnabled(); } + bool IsHorizontalBarEnabled() { return horizontal_bar_.IsEnabled(); } void SetHorizontalBarEnabled(bool value) { horizontal_bar_.SetEnabled(value); } - bool IsVerticalBarEnabled() const { return horizontal_bar_.IsEnabled(); } + bool IsVerticalBarEnabled() { return horizontal_bar_.IsEnabled(); } void SetVerticalBarEnabled(bool value) { horizontal_bar_.SetEnabled(value); } IEvent<Scroll>* ScrollAttemptEvent() { return &scroll_attempt_event_; } diff --git a/include/cru/ui/render/ScrollRenderObject.h b/include/cru/ui/render/ScrollRenderObject.h index 348d7af1..b3d1a09f 100644 --- a/include/cru/ui/render/ScrollRenderObject.h +++ b/include/cru/ui/render/ScrollRenderObject.h @@ -1,9 +1,6 @@ #pragma once -#include "SingleChildRenderObject.h" - #include "ScrollBar.h" -#include "cru/base/Event.h" -#include "cru/ui/render/RenderObject.h" +#include "SingleChildRenderObject.h" #include <memory> #include <optional> @@ -19,12 +16,9 @@ namespace cru::ui::render { // Or layout by scroll state. class CRU_UI_API ScrollRenderObject : public SingleChildRenderObject { public: - ScrollRenderObject(); + static constexpr auto kRenderObjectName = "ScrollRenderObject"; - CRU_DELETE_COPY(ScrollRenderObject) - CRU_DELETE_MOVE(ScrollRenderObject) - - ~ScrollRenderObject() override = default; + ScrollRenderObject(); RenderObject* HitTest(const Point& point) override; @@ -46,7 +40,7 @@ class CRU_UI_API ScrollRenderObject : public SingleChildRenderObject { void ApplyScroll(const Scroll& scroll); - Point GetRawScrollOffset() const { return scroll_offset_; } + Point GetRawScrollOffset() { return scroll_offset_; } // Return the viewable area rect. // Lefttop is scroll offset. Size is content size. @@ -60,9 +54,7 @@ class CRU_UI_API ScrollRenderObject : public SingleChildRenderObject { // Param margin is just for convenience and it will just add to the rect. void ScrollToContain(const Rect& rect, const Thickness& margin = Thickness{}); - std::string GetName() const override { return "ScrollRenderObject"; } - - bool IsMouseWheelScrollEnabled() const { return is_mouse_wheel_enabled_; } + bool IsMouseWheelScrollEnabled() { return is_mouse_wheel_enabled_; } void SetMouseWheelScrollEnabled(bool enable); bool HorizontalCanScrollUp(); diff --git a/include/cru/ui/render/SingleChildRenderObject.h b/include/cru/ui/render/SingleChildRenderObject.h index 85442eda..4c1891c5 100644 --- a/include/cru/ui/render/SingleChildRenderObject.h +++ b/include/cru/ui/render/SingleChildRenderObject.h @@ -3,13 +3,10 @@ namespace cru::ui::render { class CRU_UI_API SingleChildRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG("SingleChildRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::SingleChildRenderObject") public: - SingleChildRenderObject() = default; - CRU_DELETE_COPY(SingleChildRenderObject) - CRU_DELETE_MOVE(SingleChildRenderObject) - ~SingleChildRenderObject() override = default; + SingleChildRenderObject(std::string name); RenderObject* GetChild() const { return child_; } void SetChild(RenderObject* new_child); diff --git a/include/cru/ui/render/StackLayoutRenderObject.h b/include/cru/ui/render/StackLayoutRenderObject.h index 0d75d032..bd08fffc 100644 --- a/include/cru/ui/render/StackLayoutRenderObject.h +++ b/include/cru/ui/render/StackLayoutRenderObject.h @@ -28,24 +28,21 @@ struct StackChildLayoutData { // to min size. class CRU_UI_API StackLayoutRenderObject : public LayoutRenderObject<StackChildLayoutData> { - CRU_DEFINE_CLASS_LOG_TAG("StackLayoutRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::StackLayoutRenderObject") public: - StackLayoutRenderObject() = default; - CRU_DELETE_COPY(StackLayoutRenderObject) - CRU_DELETE_MOVE(StackLayoutRenderObject) - ~StackLayoutRenderObject() = default; + static constexpr auto kRenderObjectName = "StackLayoutRenderObject"; - std::string GetName() const override { return "StackLayoutRenderObject"; } + StackLayoutRenderObject(); - Alignment GetDefaultHorizontalAlignment() const { + Alignment GetDefaultHorizontalAlignment() { return default_vertical_alignment_; } void SetDefaultHorizontalAlignment(Alignment alignment); Alignment GetDefaultVerticalAlignment() { return default_horizontal_alignment_; } - void SetDefaultVertialAlignment(Alignment alignment); + void SetDefaultVerticalAlignment(Alignment alignment); protected: Size OnMeasureContent(const MeasureRequirement& requirement, diff --git a/include/cru/ui/render/TextRenderObject.h b/include/cru/ui/render/TextRenderObject.h index 5b99ae98..19ff800a 100644 --- a/include/cru/ui/render/TextRenderObject.h +++ b/include/cru/ui/render/TextRenderObject.h @@ -19,9 +19,10 @@ namespace cru::ui::render { // If the result layout box is bigger than actual text box, then text is center // aligned. class CRU_UI_API TextRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG("TextRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::TextRenderObject") public: + static constexpr auto kRenderObjectName = "TextRenderObject"; constexpr static float default_caret_width = 2; public: @@ -29,19 +30,14 @@ class CRU_UI_API TextRenderObject : public RenderObject { std::shared_ptr<platform::graphics::IFont> font, std::shared_ptr<platform::graphics::IBrush> selection_brush, std::shared_ptr<platform::graphics::IBrush> caret_brush); - TextRenderObject(const TextRenderObject& other) = delete; - TextRenderObject(TextRenderObject&& other) = delete; - TextRenderObject& operator=(const TextRenderObject& other) = delete; - TextRenderObject& operator=(TextRenderObject&& other) = delete; - ~TextRenderObject() override; - std::string GetText() const; + std::string GetText(); void SetText(std::string new_text); std::shared_ptr<platform::graphics::IBrush> GetBrush() { return brush_; } void SetBrush(std::shared_ptr<platform::graphics::IBrush> new_brush); - std::shared_ptr<platform::graphics::IFont> GetFont() const; + std::shared_ptr<platform::graphics::IFont> GetFont(); void SetFont(std::shared_ptr<platform::graphics::IFont> font); bool IsEditMode(); @@ -54,23 +50,21 @@ class CRU_UI_API TextRenderObject : public RenderObject { Rect TextSinglePoint(Index position, bool trailing); platform::graphics::TextHitTestResult TextHitTest(const Point& point); - std::optional<TextRange> GetSelectionRange() const { - return selection_range_; - } + std::optional<TextRange> GetSelectionRange() { return selection_range_; } void SetSelectionRange(std::optional<TextRange> new_range); - std::shared_ptr<platform::graphics::IBrush> GetSelectionBrush() const { + std::shared_ptr<platform::graphics::IBrush> GetSelectionBrush() { return selection_brush_; } void SetSelectionBrush(std::shared_ptr<platform::graphics::IBrush> new_brush); - bool IsDrawCaret() const { return draw_caret_; } + bool IsDrawCaret() { return draw_caret_; } void SetDrawCaret(bool draw_caret); void ToggleDrawCaret() { SetDrawCaret(!IsDrawCaret()); } // Caret position can be any value. When it is negative, 0 is used. When it // exceeds the size of the string, the size of the string is used. - Index GetCaretPosition() const { return caret_position_; } + Index GetCaretPosition() { return caret_position_; } void SetCaretPosition(Index position); // Lefttop relative to content lefttop. @@ -78,23 +72,21 @@ class CRU_UI_API TextRenderObject : public RenderObject { // Lefttop relative to render object lefttop. Rect GetCaretRect(); - std::shared_ptr<platform::graphics::IBrush> GetCaretBrush() const { + std::shared_ptr<platform::graphics::IBrush> GetCaretBrush() { return caret_brush_; } void GetCaretBrush(std::shared_ptr<platform::graphics::IBrush> brush); - float GetCaretWidth() const { return caret_width_; } + float GetCaretWidth() { return caret_width_; } void SetCaretWidth(float width); - bool IsMeasureIncludingTrailingSpace() const { + bool IsMeasureIncludingTrailingSpace() { return is_measure_including_trailing_space_; } void SetMeasureIncludingTrailingSpace(bool including); RenderObject* HitTest(const Point& point) override; - std::string GetName() const override { return "TextRenderObject"; } - void Draw(platform::graphics::IPainter* painter) override; protected: diff --git a/include/cru/ui/render/TreeRenderObject.h b/include/cru/ui/render/TreeRenderObject.h index de6e6f9b..90c35747 100644 --- a/include/cru/ui/render/TreeRenderObject.h +++ b/include/cru/ui/render/TreeRenderObject.h @@ -1,6 +1,7 @@ #pragma once #include "RenderObject.h" -#include "cru/platform/graphics/Painter.h" + +#include <cru/platform/graphics/Painter.h> namespace cru::ui::render { class TreeRenderObject; @@ -18,11 +19,9 @@ class CRU_UI_API TreeRenderObjectItem : public Object { RenderObject* GetRenderObject() { return render_object_; } void SetRenderObject(RenderObject* render_object); - const std::vector<TreeRenderObjectItem*>& GetChildren() const { - return children_; - } + const std::vector<TreeRenderObjectItem*>& GetChildren() { return children_; } - Index GetChildCount() const { return children_.size(); } + Index GetChildCount() { return children_.size(); } TreeRenderObjectItem* GetChildAt(Index index) { Expects(index >= 0 && index < children_.size()); @@ -32,7 +31,7 @@ class CRU_UI_API TreeRenderObjectItem : public Object { TreeRenderObjectItem* AddItem(Index position); void RemoveItem(Index position); - void* GetUserData() const { return user_data_; } + void* GetUserData() { return user_data_; } void SetUserData(void* user_data) { user_data_ = user_data; } private: @@ -47,19 +46,17 @@ class CRU_UI_API TreeRenderObjectItem : public Object { }; class CRU_UI_API TreeRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG("TreeRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("cru::ui::render::TreeRenderObject") public: + static constexpr auto kRenderObjectName = "TreeRenderObject"; + TreeRenderObject(); - CRU_DELETE_COPY(TreeRenderObject) - CRU_DELETE_MOVE(TreeRenderObject) ~TreeRenderObject() override; - std::string GetName() const override { return "TreeRenderObject"; } - TreeRenderObjectItem* GetRootItem() { return root_item_; } - float GetTabWidth() const { return tab_width_; } + float GetTabWidth() { return tab_width_; } void SetTabWidth(float tab_width); RenderObject* HitTest(const Point& point) override; diff --git a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h index dd4101bf..412174a8 100644 --- a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h +++ b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h @@ -16,7 +16,7 @@ class MeasureLengthPropertyEditor : public Editor, public LabeledMixin { public: ui::controls::Control* GetRootControl() override { return &container_; } - PropertyType GetValue() const { return measure_length_; } + PropertyType GetValue() { return measure_length_; } void SetValue(const PropertyType& value, bool trigger_change = true); private: diff --git a/src/ui/controls/Window.cpp b/src/ui/controls/Window.cpp index 9722a3c6..8f06013e 100644 --- a/src/ui/controls/Window.cpp +++ b/src/ui/controls/Window.cpp @@ -12,7 +12,7 @@ Window::Window() control_host_(new ControlHost(this)), attached_control_(nullptr) { GetContainerRenderObject()->SetDefaultHorizontalAlignment(Alignment::Stretch); - GetContainerRenderObject()->SetDefaultVertialAlignment(Alignment::Stretch); + GetContainerRenderObject()->SetDefaultVerticalAlignment(Alignment::Stretch); } Window* Window::CreatePopup() { diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index 5c4bc22c..674f82b1 100644 --- a/src/ui/render/BorderRenderObject.cpp +++ b/src/ui/render/BorderRenderObject.cpp @@ -11,9 +11,10 @@ #include <algorithm> namespace cru::ui::render { -BorderRenderObject::BorderRenderObject() { RecreateGeometry(); } - -BorderRenderObject::~BorderRenderObject() {} +BorderRenderObject::BorderRenderObject() + : SingleChildRenderObject(kRenderObjectName) { + RecreateGeometry(); +} void BorderRenderObject::ApplyBorderStyle( const style::ApplyBorderStyleInfo& style) { @@ -138,19 +139,19 @@ void BorderRenderObject::OnLayoutContent(const Rect& content_rect) { void BorderRenderObject::OnResize(const Size& new_size) { RecreateGeometry(); } -Thickness BorderRenderObject::GetTotalSpaceThickness() const { +Thickness BorderRenderObject::GetTotalSpaceThickness() { return is_border_enabled_ ? RenderObject::GetTotalSpaceThickness() + GetBorderThickness() : RenderObject::GetTotalSpaceThickness(); } -Thickness BorderRenderObject::GetInnerSpaceThickness() const { +Thickness BorderRenderObject::GetInnerSpaceThickness() { return is_border_enabled_ ? RenderObject::GetInnerSpaceThickness() + GetBorderThickness() : RenderObject::GetInnerSpaceThickness(); } -Rect BorderRenderObject::GetPaddingRect() const { +Rect BorderRenderObject::GetPaddingRect() { const auto size = GetSize(); Rect rect{Point{}, size}; rect = rect.Shrink(GetMargin()); @@ -162,7 +163,7 @@ Rect BorderRenderObject::GetPaddingRect() const { return rect; } -Rect BorderRenderObject::GetContentRect() const { +Rect BorderRenderObject::GetContentRect() { const auto size = GetDesiredSize(); Rect rect{Point{}, size}; rect = rect.Shrink(GetMargin()); @@ -243,6 +244,4 @@ void BorderRenderObject::RecreateGeometry() { geometry_ = builder->Build(); builder.reset(); } - -std::string BorderRenderObject::GetName() const { return "BorderRenderObject"; } } // namespace cru::ui::render diff --git a/src/ui/render/CanvasRenderObject.cpp b/src/ui/render/CanvasRenderObject.cpp index e0f1726b..318f1ffb 100644 --- a/src/ui/render/CanvasRenderObject.cpp +++ b/src/ui/render/CanvasRenderObject.cpp @@ -1,9 +1,8 @@ #include "cru/ui/render/CanvasRenderObject.h" +#include "cru/ui/render/RenderObject.h" namespace cru::ui::render { -CanvasRenderObject::CanvasRenderObject() {} - -CanvasRenderObject::~CanvasRenderObject() = default; +CanvasRenderObject::CanvasRenderObject() : RenderObject(kRenderObjectName) {} RenderObject* CanvasRenderObject::HitTest(const Point& point) { const auto padding_rect = GetPaddingRect(); diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 53193867..8cbc0295 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -7,9 +7,8 @@ #include <type_traits> namespace cru::ui::render { -std::string FlexLayoutRenderObject::GetName() const { - return "FlexLayoutRenderObject"; -} +FlexLayoutRenderObject::FlexLayoutRenderObject() + : LayoutRenderObject<FlexChildLayoutData>(kRenderObjectName) {} struct tag_horizontal_t {}; struct tag_vertical_t {}; diff --git a/src/ui/render/GeometryRenderObject.cpp b/src/ui/render/GeometryRenderObject.cpp index 07c5b911..b311665f 100644 --- a/src/ui/render/GeometryRenderObject.cpp +++ b/src/ui/render/GeometryRenderObject.cpp @@ -5,12 +5,11 @@ #include "cru/ui/render/RenderObject.h" namespace cru::ui::render { -GeometryRenderObject::GeometryRenderObject() {} - -GeometryRenderObject::~GeometryRenderObject() {} +GeometryRenderObject::GeometryRenderObject() + : RenderObject(kRenderObjectName) {} std::shared_ptr<platform::graphics::IGeometry> -GeometryRenderObject::GetGeometry() const { +GeometryRenderObject::GetGeometry() { return geometry_; } @@ -25,15 +24,15 @@ void GeometryRenderObject::SetGeometry( } } -Rect GeometryRenderObject::GetViewPort() const { return view_port_; } +Rect GeometryRenderObject::GetViewPort() { return view_port_; } void GeometryRenderObject::SetViewPort(const Rect& view_port) { view_port_ = view_port; InvalidatePaint(); } -std::shared_ptr<platform::graphics::IBrush> GeometryRenderObject::GetFillBrush() - const { +std::shared_ptr<platform::graphics::IBrush> +GeometryRenderObject::GetFillBrush() { return fill_brush_; } @@ -44,7 +43,7 @@ void GeometryRenderObject::SetFillBrush( } std::shared_ptr<platform::graphics::IBrush> -GeometryRenderObject::GetStrokeBrush() const { +GeometryRenderObject::GetStrokeBrush() { return stroke_brush_; } @@ -54,7 +53,7 @@ void GeometryRenderObject::SetStrokeBrush( InvalidatePaint(); } -float GeometryRenderObject::GetStrokeWidth() const { return stroke_width_; } +float GeometryRenderObject::GetStrokeWidth() { return stroke_width_; } void GeometryRenderObject::SetStrokeWidth(float width) { stroke_width_ = width; diff --git a/src/ui/render/LayoutHelper.cpp b/src/ui/render/LayoutHelper.cpp index bbd3c116..c971fda2 100644 --- a/src/ui/render/LayoutHelper.cpp +++ b/src/ui/render/LayoutHelper.cpp @@ -1,7 +1,5 @@ #include "cru/ui/render/LayoutHelper.h" -#include "cru/base/log/Logger.h" - namespace cru::ui::render { float CalculateAnchorByAlignment(Alignment alignment, float start_point, float content_length, float child_length) { diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index d999be7b..8bd85784 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -9,6 +9,8 @@ namespace cru::ui::render { const BoxConstraint BoxConstraint::kNotLimit{Size::kMax, Size::kZero}; +RenderObject::RenderObject(std::string name) : name_(std::move(name)) {} + RenderObject::~RenderObject() { DestroyEvent_.Raise(this); } void RenderObject::SetParent(RenderObject* new_parent) { @@ -29,9 +31,9 @@ void RenderObject::SetAttachedControl(controls::Control* new_control) { OnAttachedControlChanged(old_control, new_control); } -Point RenderObject::GetTotalOffset() const { +Point RenderObject::GetTotalOffset() { Point result{}; - const RenderObject* render_object = this; + RenderObject* render_object = this; while (render_object != nullptr) { const auto o = render_object->GetOffset(); @@ -43,7 +45,7 @@ Point RenderObject::GetTotalOffset() const { return result; } -Point RenderObject::FromRootToContent(const Point& point) const { +Point RenderObject::FromRootToContent(const Point& point) { const auto offset = GetTotalOffset(); const auto rect = GetContentRect(); return Point{point.x - (offset.x + rect.left), @@ -86,7 +88,7 @@ void RenderObject::SetMaxSize1(const Size& max_size) { } BoxConstraint RenderObject::CalculateMergedConstraint( - const BoxConstraint& constraint) const { + const BoxConstraint& constraint) { auto result = constraint; if (max_size_.width >= constraint.min.width && max_size_.width < constraint.max.width) { @@ -157,11 +159,9 @@ void RenderObject::Layout(const Point& offset) { OnLayoutCore(); } -Thickness RenderObject::GetTotalSpaceThickness() const { - return margin_ + padding_; -} +Thickness RenderObject::GetTotalSpaceThickness() { return margin_ + padding_; } -Thickness RenderObject::GetInnerSpaceThickness() const { return padding_; } +Thickness RenderObject::GetInnerSpaceThickness() { return padding_; } Size RenderObject::OnMeasureCore(const MeasureRequirement& requirement, const MeasureSize& preferred_size) { @@ -244,7 +244,7 @@ Size RenderObject::OnMeasureContent1(const BoxConstraint& constraint) { throw Exception("Not implemented."); } -Rect RenderObject::GetPaddingRect() const { +Rect RenderObject::GetPaddingRect() { const auto size = GetDesiredSize(); Rect rect{Point{}, size}; rect = rect.Shrink(GetMargin()); @@ -255,7 +255,7 @@ Rect RenderObject::GetPaddingRect() const { return rect; } -Rect RenderObject::GetContentRect() const { +Rect RenderObject::GetContentRect() { const auto size = GetDesiredSize(); Rect rect{Point{}, size}; rect = rect.Shrink(GetMargin()); @@ -286,12 +286,11 @@ void RenderObject::InvalidatePaint() { } } -std::string kUnamedName("UNNAMED"); -std::string RenderObject::GetName() const { return kUnamedName; } +std::string RenderObject::GetName() { return name_; } -std::string RenderObject::GetDebugPathInTree() const { +std::string RenderObject::GetDebugPathInTree() { std::vector<std::string> chain; - const RenderObject* parent = this; + RenderObject* parent = this; while (parent != nullptr) { chain.push_back(parent->GetName()); parent = parent->GetParent(); diff --git a/src/ui/render/ScrollRenderObject.cpp b/src/ui/render/ScrollRenderObject.cpp index ea93dd21..49cb6bf3 100644 --- a/src/ui/render/ScrollRenderObject.cpp +++ b/src/ui/render/ScrollRenderObject.cpp @@ -37,7 +37,8 @@ Point CoerceScroll(const Point& scroll_offset, const Size& content_size, } } // namespace -ScrollRenderObject::ScrollRenderObject() { +ScrollRenderObject::ScrollRenderObject() + : SingleChildRenderObject(kRenderObjectName) { scroll_bar_delegate_ = std::make_unique<ScrollBarDelegate>(this); scroll_bar_delegate_->ScrollAttemptEvent()->AddHandler( [this](const struct Scroll& scroll) { this->ApplyScroll(scroll); }); diff --git a/src/ui/render/SingleChildRenderObject.cpp b/src/ui/render/SingleChildRenderObject.cpp index d62a233e..cb00c077 100644 --- a/src/ui/render/SingleChildRenderObject.cpp +++ b/src/ui/render/SingleChildRenderObject.cpp @@ -1,7 +1,11 @@ #include "cru/ui/render/SingleChildRenderObject.h" +#include "cru/ui/render/RenderObject.h" namespace cru::ui::render { -void SingleChildRenderObject::SetChild(RenderObject *new_child) { +SingleChildRenderObject::SingleChildRenderObject(std::string name) + : RenderObject(std::move(name)) {} + +void SingleChildRenderObject::SetChild(RenderObject* new_child) { assert(new_child == nullptr || new_child->GetParent() == nullptr); if (child_ == new_child) return; auto old_child = child_; @@ -15,8 +19,8 @@ void SingleChildRenderObject::SetChild(RenderObject *new_child) { OnChildChanged(old_child, new_child); } -void SingleChildRenderObject::OnChildChanged(RenderObject *old_child, - RenderObject *new_child) { +void SingleChildRenderObject::OnChildChanged(RenderObject* old_child, + RenderObject* new_child) { InvalidateLayout(); } } // namespace cru::ui::render diff --git a/src/ui/render/StackLayoutRenderObject.cpp b/src/ui/render/StackLayoutRenderObject.cpp index d71c5749..6d5b9a10 100644 --- a/src/ui/render/StackLayoutRenderObject.cpp +++ b/src/ui/render/StackLayoutRenderObject.cpp @@ -1,19 +1,22 @@ #include "cru/ui/render/StackLayoutRenderObject.h" -#include "cru/base/log/Logger.h" #include "cru/ui/render/LayoutHelper.h" #include "cru/ui/render/MeasureRequirement.h" #include <algorithm> namespace cru::ui::render { + +StackLayoutRenderObject::StackLayoutRenderObject() + : LayoutRenderObject<StackChildLayoutData>(kRenderObjectName) {} + void StackLayoutRenderObject::SetDefaultHorizontalAlignment( Alignment alignment) { default_horizontal_alignment_ = alignment; InvalidateLayout(); } -void StackLayoutRenderObject::SetDefaultVertialAlignment(Alignment alignment) { +void StackLayoutRenderObject::SetDefaultVerticalAlignment(Alignment alignment) { default_vertical_alignment_ = alignment; InvalidateLayout(); } diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index c7803383..217029b2 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -16,7 +16,8 @@ TextRenderObject::TextRenderObject( std::shared_ptr<platform::graphics::IBrush> brush, std::shared_ptr<platform::graphics::IFont> font, std::shared_ptr<platform::graphics::IBrush> selection_brush, - std::shared_ptr<platform::graphics::IBrush> caret_brush) { + std::shared_ptr<platform::graphics::IBrush> caret_brush) + : RenderObject(kRenderObjectName) { Expects(brush); Expects(font); Expects(selection_brush); @@ -31,11 +32,7 @@ TextRenderObject::TextRenderObject( text_layout_ = graph_factory->CreateTextLayout(font_, ""); } -TextRenderObject::~TextRenderObject() = default; - -std::string TextRenderObject::GetText() const { - return text_layout_->GetText(); -} +std::string TextRenderObject::GetText() { return text_layout_->GetText(); } void TextRenderObject::SetText(std::string new_text) { text_layout_->SetText(std::move(new_text)); @@ -49,7 +46,7 @@ void TextRenderObject::SetBrush( InvalidatePaint(); } -std::shared_ptr<platform::graphics::IFont> TextRenderObject::GetFont() const { +std::shared_ptr<platform::graphics::IFont> TextRenderObject::GetFont() { return text_layout_->GetFont(); } diff --git a/src/ui/render/TreeRenderObject.cpp b/src/ui/render/TreeRenderObject.cpp index 8bf662e4..8c13e93a 100644 --- a/src/ui/render/TreeRenderObject.cpp +++ b/src/ui/render/TreeRenderObject.cpp @@ -45,7 +45,7 @@ void TreeRenderObjectItem::RemoveItem(Index position) { tree_render_object_->InvalidateLayout(); } -TreeRenderObject::TreeRenderObject() { +TreeRenderObject::TreeRenderObject() : RenderObject(kRenderObjectName) { root_item_ = new TreeRenderObjectItem(this, nullptr); } |
