/** * @file Layout.h * @author apio (cloudapio.eu) * @brief Layout widgets to organize content. * * @copyright Copyright (c) 2023, the Luna authors. * */ #pragma once #include #include namespace ui { enum class AdjustHeight { No, Yes }; enum class AdjustWidth { No, Yes }; struct Margins { int left; int right; int top; int bottom; }; class HorizontalLayout final : public Widget { public: HorizontalLayout(Margins margins = Margins { 0, 0, 0, 0 }, AdjustHeight adjust_height = AdjustHeight::Yes, AdjustWidth adjust_width = AdjustWidth::Yes); Result handle_mouse_move(Point position) override; Result handle_mouse_leave() override; Result handle_mouse_down(Point position, int buttons) override; Result handle_mouse_up(Point position, int buttons) override; Result handle_key_event(const ui::KeyEventRequest& request) override; Result draw(Canvas& canvas) override; Result add_widget(Widget& widget); private: Vector m_widgets; Margins m_margins; AdjustHeight m_adjust_height; AdjustWidth m_adjust_width; int m_used_width { 0 }; }; class VerticalLayout final : public Widget { public: VerticalLayout(Margins margins = Margins { 0, 0, 0, 0 }, AdjustHeight adjust_height = AdjustHeight::Yes, AdjustWidth adjust_width = AdjustWidth::Yes); Result handle_mouse_move(Point position) override; Result handle_mouse_leave() override; Result handle_mouse_down(Point position, int buttons) override; Result handle_mouse_up(Point position, int buttons) override; Result handle_key_event(const ui::KeyEventRequest& request) override; Result draw(Canvas& canvas) override; Result add_widget(Widget& widget); private: Vector m_widgets; Margins m_margins; AdjustHeight m_adjust_height; AdjustWidth m_adjust_width; int m_used_height { 0 }; }; }