This commit is contained in:
parent
0824ba7e23
commit
3e5bdc8c80
@ -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)
|
||||
|
40
apps/clock.cpp
Normal file
40
apps/clock.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#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 });
|
||||
|
||||
os::EventLoop::the().register_timer(1, update_time);
|
||||
|
||||
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);
|
||||
|
||||
g_label = TRY(make<ui::Label>("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();
|
||||
}
|
@ -62,6 +62,9 @@ Result<int> 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();
|
||||
|
BIN
base/usr/share/icons/32x32/app-clock.tga
Normal file
BIN
base/usr/share/icons/32x32/app-clock.tga
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
Loading…
Reference in New Issue
Block a user