diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-21 21:43:42 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-21 21:43:42 +0800 |
| commit | 3b875091c445b7465b9bd044914318989a94d2ad (patch) | |
| tree | a358aebb488ec1ddc86bf87b8038bacd5d7515cb /include/cru/ui/controls/LayoutControl.h | |
| parent | 3cda35dbcbbe1e3854b880169c0efa0fc7a79264 (diff) | |
| download | cru-3b875091c445b7465b9bd044914318989a94d2ad.tar.gz cru-3b875091c445b7465b9bd044914318989a94d2ad.tar.bz2 cru-3b875091c445b7465b9bd044914318989a94d2ad.zip | |
Clean codes. Remove member function const.
Diffstat (limited to 'include/cru/ui/controls/LayoutControl.h')
| -rw-r--r-- | include/cru/ui/controls/LayoutControl.h | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/include/cru/ui/controls/LayoutControl.h b/include/cru/ui/controls/LayoutControl.h index fad86530..866a8c03 100644 --- a/include/cru/ui/controls/LayoutControl.h +++ b/include/cru/ui/controls/LayoutControl.h @@ -5,8 +5,8 @@ namespace cru::ui::controls { template <typename TRenderObject> class LayoutControl : public Control { protected: - LayoutControl() : container_render_object_(new TRenderObject()) { - container_render_object_->SetAttachedControl(this); + LayoutControl(std::string name) : Control(std::move(name)) { + container_render_object_.SetAttachedControl(this); } public: @@ -14,47 +14,34 @@ class LayoutControl : public Control { using Control::InsertChildAt; using Control::RemoveChildAt; - Index GetChildCount() const { return children_.size(); } - Control* GetChildAt(Index index) const { return children_[index]; } - - Index IndexOfChild(Control* control) const { - auto it = std::find(children_.begin(), children_.end(), control); - if (it == children_.end()) { - return -1; - } - return it - children_.begin(); - } - - render::RenderObject* GetRenderObject() const override { - return container_render_object_.get(); + render::RenderObject* GetRenderObject() override { + return &container_render_object_; } - TRenderObject* GetContainerRenderObject() const { - return container_render_object_.get(); + TRenderObject* GetContainerRenderObject() { + return &container_render_object_; } const typename TRenderObject::ChildLayoutData& GetChildLayoutData( Index position) { - return container_render_object_->GetChildLayoutDataAt(position); + return container_render_object_.GetChildLayoutDataAt(position); } void SetChildLayoutData(Index position, typename TRenderObject::ChildLayoutData data) { - container_render_object_->SetChildLayoutDataAt(position, data); + container_render_object_.SetChildLayoutDataAt(position, data); } protected: void OnChildInserted(Control* control, Index index) override { - container_render_object_->AddChild(control->GetRenderObject(), index); + container_render_object_.AddChild(control->GetRenderObject(), index); } void OnChildRemoved([[maybe_unused]] Control* control, Index index) override { - container_render_object_->RemoveChild(index); + container_render_object_.RemoveChild(index); } private: - std::unique_ptr<TRenderObject> container_render_object_; - - std::vector<Control*> children_; + TRenderObject container_render_object_; }; } // namespace cru::ui::controls |
