2023-08-15 12:42:21 +00:00
|
|
|
/**
|
|
|
|
* @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
|
2024-05-19 12:21:30 +00:00
|
|
|
#include <os/File.h>
|
2023-08-15 12:42:21 +00:00
|
|
|
#include <ui/Alignment.h>
|
|
|
|
#include <ui/Widget.h>
|
2024-05-19 12:21:30 +00:00
|
|
|
#include <ui/Window.h>
|
2023-08-15 12:42:21 +00:00
|
|
|
|
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
class Container : public Widget
|
|
|
|
{
|
|
|
|
public:
|
2024-05-19 12:21:30 +00:00
|
|
|
Container(ui::Window* window, ui::Widget* parent);
|
2023-08-15 12:42:21 +00:00
|
|
|
|
2024-05-19 12:21:30 +00:00
|
|
|
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 12:42:21 +00:00
|
|
|
|
2023-08-15 13:10:13 +00:00
|
|
|
Result<EventResult> handle_mouse_move(Point position) override;
|
2023-08-29 13:26:34 +00:00
|
|
|
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;
|
2023-09-16 09:45:19 +00:00
|
|
|
Result<EventResult> handle_key_event(const ui::KeyEventRequest& request) override;
|
2023-08-15 12:42:21 +00:00
|
|
|
Result<void> draw(Canvas& canvas) override;
|
|
|
|
|
2024-05-19 12:21:30 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:42:21 +00:00
|
|
|
private:
|
2024-05-19 12:21:30 +00:00
|
|
|
Widget* m_widget { nullptr };
|
|
|
|
VerticalAlignment m_valign = VerticalAlignment::Center;
|
|
|
|
HorizontalAlignment m_halign = HorizontalAlignment::Center;
|
2023-08-15 12:42:21 +00:00
|
|
|
};
|
|
|
|
}
|