Luna/apps/gclient.cpp

76 lines
1.7 KiB
C++
Raw Normal View History

#include <ui/App.h>
#include <ui/Layout.h>
struct ColorWidget : public ui::Widget
{
public:
2023-08-15 13:10:13 +00:00
ColorWidget(ui::Color first, ui::Color second) : m_color(first), m_first_color(first), m_second_color(second)
{
}
2023-08-15 13:10:13 +00:00
Result<ui::EventResult> handle_mouse_move(ui::Point) override
{
m_color = m_second_color;
return ui::EventResult::DidHandle;
}
Result<ui::EventResult> handle_mouse_leave() override
2023-08-15 13:10:13 +00:00
{
m_color = m_first_color;
return ui::EventResult::DidHandle;
}
Result<ui::EventResult> handle_mouse_down(ui::Point, int) override
{
return ui::EventResult::DidNotHandle;
}
Result<ui::EventResult> handle_mouse_up(ui::Point, int) override
{
return ui::EventResult::DidNotHandle;
}
Result<void> draw(ui::Canvas& canvas) override
{
canvas.fill(m_color);
return {};
}
private:
ui::Color m_color;
2023-08-15 13:10:13 +00:00
ui::Color m_first_color;
ui::Color m_second_color;
};
2023-08-14 16:15:38 +00:00
2023-08-07 20:45:00 +00:00
Result<int> luna_main(int argc, char** argv)
{
ui::App app;
TRY(app.init(argc, argv));
auto* window = TRY(ui::Window::create(ui::Rect { 200, 200, 400, 300 }));
app.set_main_window(window);
window->set_title("Main Window");
window->set_background(ui::CYAN);
ui::HorizontalLayout layout;
window->set_main_widget(layout);
2023-08-15 13:10:13 +00:00
ColorWidget green(ui::GREEN, ui::WHITE);
layout.add_widget(green);
2023-08-15 13:10:13 +00:00
ColorWidget blue(ui::BLUE, ui::GRAY);
layout.add_widget(blue);
2023-08-15 11:01:41 +00:00
ui::VerticalLayout sublayout;
layout.add_widget(sublayout);
2023-08-15 13:10:13 +00:00
ColorWidget red(ui::RED, ui::CYAN);
sublayout.add_widget(red);
2023-08-15 13:10:13 +00:00
ColorWidget white(ui::WHITE, ui::GREEN);
sublayout.add_widget(white);
2023-08-07 20:45:00 +00:00
window->draw();
return app.run();
2023-08-07 20:45:00 +00:00
}