Add a display server and graphical user interface #38
@ -40,8 +40,6 @@ luna_app(kill.cpp kill)
|
||||
luna_app(gol.cpp gol)
|
||||
luna_app(touch.cpp touch)
|
||||
luna_app(free.cpp free)
|
||||
luna_app(gclient.cpp gclient)
|
||||
target_link_libraries(gclient PUBLIC ui)
|
||||
luna_app(about.cpp about)
|
||||
target_link_libraries(about PUBLIC ui)
|
||||
luna_app(taskbar.cpp taskbar)
|
||||
|
@ -1,67 +0,0 @@
|
||||
#include <ui/App.h>
|
||||
#include <ui/Layout.h>
|
||||
|
||||
struct ColorWidget : public ui::Widget
|
||||
{
|
||||
public:
|
||||
ColorWidget(ui::Color first, ui::Color second) : m_color(first), m_first_color(first), m_second_color(second)
|
||||
{
|
||||
}
|
||||
|
||||
Result<ui::EventResult> handle_mouse_move(ui::Point) override
|
||||
{
|
||||
auto old_color = m_color;
|
||||
m_color = m_second_color;
|
||||
return old_color.raw == m_second_color.raw ? ui::EventResult::DidNotHandle : ui::EventResult::DidHandle;
|
||||
}
|
||||
|
||||
Result<ui::EventResult> handle_mouse_leave() override
|
||||
{
|
||||
auto old_color = m_color;
|
||||
m_color = m_first_color;
|
||||
return old_color.raw == m_first_color.raw ? ui::EventResult::DidNotHandle : ui::EventResult::DidHandle;
|
||||
}
|
||||
|
||||
Result<void> draw(ui::Canvas& canvas) override
|
||||
{
|
||||
canvas.fill(m_color);
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
ui::Color m_color;
|
||||
ui::Color m_first_color;
|
||||
ui::Color m_second_color;
|
||||
};
|
||||
|
||||
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("Test Window");
|
||||
window->set_background(ui::CYAN);
|
||||
|
||||
ui::HorizontalLayout layout;
|
||||
window->set_main_widget(layout);
|
||||
|
||||
ColorWidget green(ui::GREEN, ui::WHITE);
|
||||
layout.add_widget(green);
|
||||
ColorWidget blue(ui::BLUE, ui::GRAY);
|
||||
layout.add_widget(blue);
|
||||
|
||||
ui::VerticalLayout sublayout;
|
||||
layout.add_widget(sublayout);
|
||||
|
||||
ColorWidget red(ui::RED, ui::CYAN);
|
||||
sublayout.add_widget(red);
|
||||
ColorWidget white(ui::WHITE, ui::GREEN);
|
||||
sublayout.add_widget(white);
|
||||
|
||||
window->draw();
|
||||
|
||||
return app.run();
|
||||
}
|
Loading…
Reference in New Issue
Block a user