Luna/gui/apps/clock.cpp
apio 140910763e
All checks were successful
Build and test / build (push) Successful in 1m56s
all: Reorder directory structure
Why are command-line utilities stored in "apps"?
And why are apps like "editor" or "terminal" top-level directories?
Command-line utilities now go in "utils".
GUI stuff now goes in "gui".
This includes: libui -> gui/libui, wind -> gui/wind, GUI apps -> gui/apps, editor&terminal -> gui/apps...
System services go in "system".
2024-07-21 13:24:46 +02:00

44 lines
903 B
C++

#include <os/Timer.h>
#include <time.h>
#include <ui/App.h>
#include <ui/Label.h>
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 });
ui::App::the().main_window()->draw();
}
Result<int> luna_main(int, char**)
{
ui::App app;
TRY(app.init());
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<ui::Label>("00:00:00"));
g_label->set_font(ui::Font::default_bold_font());
g_label->set_color(ui::BLACK);
window->set_main_widget(*g_label);
update_time();
auto timer = TRY(os::Timer::create_repeating(1000, update_time));
return app.run();
}