/
SilovAndrey
/
easel_gui
Обзор
Документация
Войти
/
SilovAndrey
/
easel_gui
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/layout.cpp
69 строк
2 KB
Andrey HomePC
первая рабочая версия
21 июл 2026, 11:50
21 июл 2026, 11:50
38b8d4a
Код
Авторство
О чём код?
module; #include <memory> #include <vector> #include <thorvg.h> module Easel.GUI; namespace easel::gui { namespace { class ContainerWidget : public Widget { public: ContainerWidget(std::vector<std::unique_ptr<Widget>> &&children, Theme const& theme, bool horizontal) : m_children(std::move(children)), m_theme(theme), m_horizontal(horizontal) {} void render(tvg::Canvas* canvas) { for (auto& child : m_children) child->render(canvas); } bool on_event(Event const& evt) override { for (auto it = m_children.rbegin(); it != m_children.rend(); ++it) if ((*it)->on_event(evt)) return true; return false; } protected: void on_resize(rect const& bounds) override { float pos = m_horizontal ? bounds.left : bounds.top; for (auto& child : m_children) { float size = m_horizontal ? (child->bounds().width() > 0 ? child->bounds().width() : 80) : (child->bounds().height() > 0 ? child->bounds().height() : 40); rect r = m_horizontal ? rect(pos, bounds.top + m_theme.spacing, size, bounds.height() - m_theme.spacing * 2) : rect(bounds.left + m_theme.spacing, pos, bounds.width() - m_theme.spacing * 2, size); child->resize(r); pos += size + m_theme.spacing; } } private: std::vector<std::unique_ptr<Widget>> m_children; const Theme &m_theme; bool m_horizontal; }; } std::unique_ptr<Widget> vstack( std::vector<std::unique_ptr<Widget>> &&children, Theme const& theme) { return std::make_unique<ContainerWidget>(std::move(children), theme, false); } std::unique_ptr<Widget> hstack( std::vector<std::unique_ptr<Widget>> &&children, Theme const& theme) { return std::make_unique<ContainerWidget>(std::move(children), theme, true); } } // namespace easel::gui