1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-11 09:04:01 +03:00

lvgui: extract clock

This commit is contained in:
Samuel Dionne-Riel 2021-06-08 21:41:39 -04:00
parent 93c9a3d35d
commit 604e46a1b8
2 changed files with 25 additions and 26 deletions

View File

@ -0,0 +1,25 @@
# Implements a clock as a wrapped LVLabel.
class LVGUI::Clock < LVGUI::Widget
def initialize(parent)
super(LVGL::LVLabel.new(parent))
set_align(LVGL::LABEL_ALIGN::LEFT)
set_long_mode(LVGL::LABEL_LONG::CROP)
# Update the text once
update_clock
# Then register a task to update regularly.
@task = LVGL::Hacks::LVTask.create_task(250, LVGL::TASK_PRIO::MID, ->() do
update_clock
end)
end
def update_clock()
now = Time.now
set_text([
:hour,
:min,
:sec,
].map{|fn| now.send(fn).to_s.rjust(2, "0") }.join(":"))
end
end

View File

@ -128,32 +128,6 @@ module LVGUI
end end
end end
# Implements a clock as a wrapped LVLabel.
class Clock < Widget
def initialize(parent)
super(LVGL::LVLabel.new(parent))
set_align(LVGL::LABEL_ALIGN::LEFT)
set_long_mode(LVGL::LABEL_LONG::CROP)
# Update the text once
update_clock
# Then register a task to update regularly.
@task = LVGL::Hacks::LVTask.create_task(250, LVGL::TASK_PRIO::MID, ->() do
update_clock
end)
end
def update_clock()
now = Time.now
set_text([
:hour,
:min,
:sec,
].map{|fn| now.send(fn).to_s.rjust(2, "0") }.join(":"))
end
end
# Widget implementing the topmost status bar # Widget implementing the topmost status bar
class StatusBar < Widget class StatusBar < Widget
def initialize(parent) def initialize(parent)