aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/controls/LayoutControl.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/ui/controls/LayoutControl.h')
-rw-r--r--include/cru/ui/controls/LayoutControl.h35
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