Luna/libui/include/ui/Container.h

60 lines
1.8 KiB
C
Raw Permalink Normal View History

/**
* @file Container.h
* @author apio (cloudapio.eu)
* @brief A container widget to pad and align objects inside it.
*
* @copyright Copyright (c) 2023, the Luna authors.
*
*/
#pragma once
#include <os/File.h>
#include <ui/Alignment.h>
#include <ui/Widget.h>
#include <ui/Window.h>
namespace ui
{
class Container : public Widget
{
public:
Container(ui::Window* window, ui::Widget* parent);
void set_container_settings(VerticalAlignment valign, HorizontalAlignment halign)
{
m_valign = valign;
m_halign = halign;
}
template <typename T> Result<T*> create_child_widget()
{
auto* widget = TRY(make<T>(window(), this));
m_widget = widget;
window()->recalculate_layout();
return widget;
}
2023-08-15 13:10:13 +00:00
Result<EventResult> handle_mouse_move(Point position) override;
Result<EventResult> handle_mouse_leave() override;
2023-08-15 13:10:13 +00:00
Result<EventResult> handle_mouse_down(Point position, int buttons) override;
Result<EventResult> handle_mouse_up(Point position, int buttons) override;
Result<EventResult> handle_key_event(const ui::KeyEventRequest& request) override;
Result<void> draw(Canvas& canvas) override;
void recalculate_true_rects() override;
void recalculate_pseudo_rects() override;
void show_tree(int indent) override
{
os::println("%*s- ui::Container (%d,%d,%d,%d)", indent, "", m_rect.pos.x, m_rect.pos.y, m_rect.width,
m_rect.height);
if (m_widget) m_widget->show_tree(indent + 1);
}
private:
Widget* m_widget { nullptr };
VerticalAlignment m_valign = VerticalAlignment::Center;
HorizontalAlignment m_halign = HorizontalAlignment::Center;
};
}