2023-10-09 20:05:30 +00:00
|
|
|
#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 });
|
|
|
|
|
2023-11-16 20:58:45 +00:00
|
|
|
os::EventLoop::the().register_timer(1000, update_time);
|
2023-10-09 20:05:30 +00:00
|
|
|
|
|
|
|
ui::App::the().main_window()->draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<int> 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);
|
|
|
|
|
2023-10-11 20:56:14 +00:00
|
|
|
g_label = TRY(make<ui::Label>("00:00:00"));
|
|
|
|
g_label->set_font(ui::Font::default_bold_font());
|
|
|
|
g_label->set_color(ui::BLACK);
|
|
|
|
|
2023-10-09 20:05:30 +00:00
|
|
|
window->set_main_widget(*g_label);
|
|
|
|
|
|
|
|
update_time();
|
|
|
|
|
|
|
|
return app.run();
|
|
|
|
}
|