mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
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:
24
src/ui/column_layout.cpp
Normal file
24
src/ui/column_layout.cpp
Normal 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
|
||||
Reference in New Issue
Block a user