From 91a3ed6a87af89d7345dc9f761f178ea6a9d53af Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 15 Jun 2022 04:44:55 +0300 Subject: [PATCH] add unfinished vertical box layout --- src/VerticalBoxLayout.cpp | 28 ++++++++++++++++++++++++++++ src/VerticalBoxLayout.hpp | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/VerticalBoxLayout.cpp create mode 100644 src/VerticalBoxLayout.hpp 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() {} +}; + +} +