mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
40 lines
852 B
C++
40 lines
852 B
C++
#include "Cubed/ui/column_layout.hpp"
|
|
|
|
namespace Cubed {
|
|
ColumnLayout::ColumnLayout(Widget* parent) : Widget(parent) {}
|
|
ColumnLayout::~ColumnLayout() {}
|
|
|
|
void ColumnLayout::update(float dt) {
|
|
layout();
|
|
Widget::update(dt);
|
|
}
|
|
|
|
float ColumnLayout::width() const {
|
|
if (m_parent) {
|
|
return m_parent->width();
|
|
}
|
|
return m_window_width;
|
|
}
|
|
float ColumnLayout::height() const {
|
|
if (m_parent) {
|
|
return m_parent->height();
|
|
}
|
|
return m_window_height;
|
|
}
|
|
|
|
ColumnLayout& ColumnLayout::set_spacing(int spacing) {
|
|
m_spacing = spacing;
|
|
return *this;
|
|
}
|
|
|
|
void ColumnLayout::layout() {
|
|
auto& children = Widget::children();
|
|
int y = 0;
|
|
for (auto& child : children) {
|
|
child->set_offset({0, y});
|
|
child->set_anchor(m_anchor);
|
|
y += child->height() + m_spacing;
|
|
}
|
|
}
|
|
|
|
} // namespace Cubed
|