mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-12-11 09:04:01 +03:00
lvgui: Extract battery
This commit is contained in:
parent
90f629e309
commit
ff9464c947
43
boot/lib/lvgui/lvgui/battery.rb
Normal file
43
boot/lib/lvgui/lvgui/battery.rb
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# Implements a battery widget as a wrapped LVLabel.
|
||||||
|
class LVGUI::Battery < LVGUI::Widget
|
||||||
|
def initialize(parent)
|
||||||
|
super(LVGL::LVLabel.new(parent))
|
||||||
|
set_align(LVGL::LABEL_ALIGN::RIGHT)
|
||||||
|
set_long_mode(LVGL::LABEL_LONG::CROP)
|
||||||
|
|
||||||
|
@battery = LVGUI::HAL::Battery.main_battery
|
||||||
|
|
||||||
|
# Update the text once
|
||||||
|
update_text
|
||||||
|
|
||||||
|
# Then register a task to update regularly.
|
||||||
|
@task = LVGL::Hacks::LVTask.create_task(1000 * 15, LVGL::TASK_PRIO::LOW, ->() do
|
||||||
|
update_text
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_text()
|
||||||
|
if @battery
|
||||||
|
symbol =
|
||||||
|
if @battery.charging? then
|
||||||
|
LVGL::Symbols::CHARGE
|
||||||
|
elsif @battery.percent == "unknown"
|
||||||
|
""
|
||||||
|
elsif @battery.percent > 95
|
||||||
|
LVGL::Symbols::BATTERY_FULL
|
||||||
|
elsif @battery.percent > 75
|
||||||
|
LVGL::Symbols::BATTERY_3
|
||||||
|
elsif @battery.percent > 45
|
||||||
|
LVGL::Symbols::BATTERY_2
|
||||||
|
elsif @battery.percent > 10
|
||||||
|
LVGL::Symbols::BATTERY_1
|
||||||
|
else
|
||||||
|
LVGL::Symbols::BATTERY_EMPTY
|
||||||
|
end
|
||||||
|
|
||||||
|
set_text("#{symbol} #{@battery.percent}%")
|
||||||
|
else
|
||||||
|
set_text("")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -218,50 +218,6 @@ module LVGUI
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Implements a battery widget as a wrapped LVLabel.
|
|
||||||
class Battery < Widget
|
|
||||||
def initialize(parent)
|
|
||||||
super(LVGL::LVLabel.new(parent))
|
|
||||||
set_align(LVGL::LABEL_ALIGN::RIGHT)
|
|
||||||
set_long_mode(LVGL::LABEL_LONG::CROP)
|
|
||||||
|
|
||||||
@battery = HAL::Battery.main_battery
|
|
||||||
|
|
||||||
# Update the text once
|
|
||||||
update_text
|
|
||||||
|
|
||||||
# Then register a task to update regularly.
|
|
||||||
@task = LVGL::Hacks::LVTask.create_task(1000 * 15, LVGL::TASK_PRIO::LOW, ->() do
|
|
||||||
update_text
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_text()
|
|
||||||
if @battery
|
|
||||||
symbol =
|
|
||||||
if @battery.charging? then
|
|
||||||
LVGL::Symbols::CHARGE
|
|
||||||
elsif @battery.percent == "unknown"
|
|
||||||
""
|
|
||||||
elsif @battery.percent > 95
|
|
||||||
LVGL::Symbols::BATTERY_FULL
|
|
||||||
elsif @battery.percent > 75
|
|
||||||
LVGL::Symbols::BATTERY_3
|
|
||||||
elsif @battery.percent > 45
|
|
||||||
LVGL::Symbols::BATTERY_2
|
|
||||||
elsif @battery.percent > 10
|
|
||||||
LVGL::Symbols::BATTERY_1
|
|
||||||
else
|
|
||||||
LVGL::Symbols::BATTERY_EMPTY
|
|
||||||
end
|
|
||||||
|
|
||||||
set_text("#{symbol} #{@battery.percent}%")
|
|
||||||
else
|
|
||||||
set_text("")
|
|
||||||
end
|
|
||||||
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