From fc656acc2cf3206e8ba429a00d994e7de6bc536d Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 11 Sep 2023 19:15:26 +0200 Subject: [PATCH] apps: Add about --- apps/CMakeLists.txt | 2 ++ apps/about.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++ apps/taskbar.cpp | 28 ++++++++++++++++++++------- 3 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 apps/about.cpp diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 14d4b50c..6b0e60c2 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -42,5 +42,7 @@ 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) target_link_libraries(taskbar PUBLIC ui) diff --git a/apps/about.cpp b/apps/about.cpp new file mode 100644 index 00000000..89fb9c70 --- /dev/null +++ b/apps/about.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include + +Result luna_main(int argc, char** argv) +{ + ui::App app; + TRY(app.init(argc, argv)); + + auto* window = TRY(ui::Window::create(ui::Rect { 300, 300, 400, 300 })); + app.set_main_window(window); + + window->set_title("About"); + window->set_background(ui::CYAN); + + utsname info; + uname(&info); + + ui::VerticalLayout main_layout; + window->set_main_widget(main_layout); + + ui::Label title("About Luna", ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center, + ui::Font::default_bold_font()); + main_layout.add_widget(title); + + ui::VerticalLayout version_info; + main_layout.add_widget(version_info); + + ui::Label license("Licensed under the BSD-2-Clause license."); + main_layout.add_widget(license); + + String os_release_text = TRY(String::format("OS release: %s"_sv, info.release)); + ui::Label os_release(os_release_text.view()); + version_info.add_widget(os_release); + + String kernel_version_text = TRY(String::format("Kernel version: %s"_sv, info.version)); + ui::Label kernel_version(kernel_version_text.view()); + version_info.add_widget(kernel_version); + + window->draw(); + + return app.run(); +} diff --git a/apps/taskbar.cpp b/apps/taskbar.cpp index 5d158581..81679d52 100644 --- a/apps/taskbar.cpp +++ b/apps/taskbar.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -30,18 +31,31 @@ Result luna_main(int argc, char** argv) ui::HorizontalLayout layout(ui::AdjustHeight::Yes, ui::AdjustWidth::No); window->set_main_widget(layout); - ui::Button button({ 0, 0, 50, 50 }); - layout.add_widget(button); + ui::Button start_button({ 0, 0, 50, 50 }); + layout.add_widget(start_button); - ui::Container container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center); - button.set_widget(container); - button.set_action([] { + ui::Container start_container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center); + start_button.set_widget(start_container); + start_button.set_action([] { StringView args[] = { "/usr/bin/gclient" }; os::Process::spawn("/usr/bin/gclient", Slice { args, 1 }, false); }); - auto image = TRY(ui::ImageWidget::load("/usr/share/icons/32x32/start-icon.tga")); - container.set_widget(*image); + auto start_image = TRY(ui::ImageWidget::load("/usr/share/icons/32x32/start-icon.tga")); + start_container.set_widget(*start_image); + + ui::Button about_button({ 0, 0, 50, 50 }); + layout.add_widget(about_button); + + ui::Container about_container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center); + about_button.set_widget(about_container); + about_button.set_action([] { + StringView args[] = { "/usr/bin/about" }; + os::Process::spawn("/usr/bin/about", Slice { args, 1 }, false); + }); + + auto about_image = TRY(ui::ImageWidget::load("/usr/share/icons/32x32/app-about.tga")); + about_container.set_widget(*about_image); window->draw();