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:
parent
93c9a3d35d
commit
604e46a1b8
25
boot/lib/lvgui/lvgui/clock.rb
Normal file
25
boot/lib/lvgui/lvgui/clock.rb
Normal 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
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user