diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 1aa3f138..f2a98141 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -47,3 +47,5 @@ luna_app(taskbar.cpp taskbar) target_link_libraries(taskbar PUBLIC ui) luna_app(2048.cpp 2048) target_link_libraries(2048 PUBLIC ui) +luna_app(clock.cpp clock) +target_link_libraries(clock PUBLIC ui) diff --git a/apps/clock.cpp b/apps/clock.cpp new file mode 100644 index 00000000..296683cc --- /dev/null +++ b/apps/clock.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +ui::Label* g_label; + +void update_time() +{ + time_t t = time(NULL); + struct tm* tp = localtime(&t); + + static char buf[2048]; + strftime(buf, sizeof(buf), "%H:%M:%S", tp); + + g_label->set_text(StringView { buf }); + + os::EventLoop::the().register_timer(1, update_time); + + ui::App::the().main_window()->draw(); +} + +Result luna_main(int argc, char** argv) +{ + ui::App app; + TRY(app.init(argc, argv)); + + auto* window = TRY(ui::Window::create(ui::Rect { 500, 400, 100, 50 })); + app.set_main_window(window); + + window->set_title("Clock"); + window->set_background(ui::GRAY); + + g_label = TRY(make("00:00:00", ui::BLACK, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center, + ui::Font::default_bold_font())); + window->set_main_widget(*g_label); + + update_time(); + + return app.run(); +} diff --git a/apps/taskbar.cpp b/apps/taskbar.cpp index 2e894c33..6d9c1d92 100644 --- a/apps/taskbar.cpp +++ b/apps/taskbar.cpp @@ -62,6 +62,9 @@ Result luna_main(int argc, char** argv) StringView gol_command[] = { "/usr/bin/gol" }; TRY(create_widget_group_for_app(layout, { gol_command, 1 }, "/usr/share/icons/32x32/app-gol.tga")); + StringView clock_command[] = { "/usr/bin/clock" }; + TRY(create_widget_group_for_app(layout, { clock_command, 1 }, "/usr/share/icons/32x32/app-clock.tga")); + window->draw(); return app.run(); diff --git a/base/usr/share/icons/32x32/app-clock.tga b/base/usr/share/icons/32x32/app-clock.tga new file mode 100644 index 00000000..f8a0af23 Binary files /dev/null and b/base/usr/share/icons/32x32/app-clock.tga differ