diff --git a/src/VerticalBoxLayout.cpp b/src/VerticalBoxLayout.cpp new file mode 100644 index 0000000..d7c551d --- /dev/null +++ b/src/VerticalBoxLayout.cpp @@ -0,0 +1,28 @@ +#include "VerticalBoxLayout.hpp" +#include "Point.hpp" +#include "Widget.hpp" + +namespace Raven { + +void VerticalBoxLayout::run() { + if (!m_target) { + return; + } + + Point current_point { m_target->rect().x() + m_margin, m_target->rect().y() + m_margin }; + + auto& children = m_target->children(); + for (auto child : children) { + if (child->absolute()) { + continue; + } + + child->rect().set_x(current_point.x()); + child->rect().set_y(current_point.y()); + + current_point.add(0, child->rect().height() + m_margin); + } +} + +} + diff --git a/src/VerticalBoxLayout.hpp b/src/VerticalBoxLayout.hpp new file mode 100644 index 0000000..19f87ff --- /dev/null +++ b/src/VerticalBoxLayout.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "Layout.hpp" + +namespace Raven { + +class VerticalBoxLayout : public Layout { +private: + double m_margin { 0.0 }; +public: + VerticalBoxLayout() + : Layout() {} + + VerticalBoxLayout(double margin) + : Layout() + , m_margin(margin) {} + + void run(); + + double margin() { return m_margin; } + void set_margin(double margin) { m_margin = margin; run(); } + + virtual ~VerticalBoxLayout() {} +}; + +} +