feat(ui): introduce ColumnLayout widget and refactor widget parenting

- Add ColumnLayout widget that arranges children vertically with spacing.
- Refactor Widget::add_child to automatically pass `this` as parent.
- Update DebugCollector to use ColumnLayout for consistent spacing.
- Expose children() accessor in Widget for layout management.
This commit is contained in:
2026-07-13 16:01:00 +08:00
parent f5e53fd13d
commit e7082bdbe0
7 changed files with 97 additions and 61 deletions

24
src/ui/column_layout.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include "Cubed/ui/column_layout.hpp"
namespace Cubed {
ColumnLayout::ColumnLayout(Widget* parent) : Widget(parent) {}
ColumnLayout::~ColumnLayout() {}
void ColumnLayout::update(float dt) {
Widget::update(dt);
layout();
}
void ColumnLayout::set_spacing(int spacing) { m_spacing = spacing; }
void ColumnLayout::layout() {
auto& children = Widget::children();
int y = 0;
for (auto& child : children) {
child->set_offset({0, y});
child->set_anchor(Anchor::TOP_LEFT);
y += child->height() + m_spacing;
}
}
} // namespace Cubed