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

boot/splash: Make colours configurable

I try to convert strings to integers so the configuration is less
awkward. Nix doesn't do `0x______` integers. So since colours are never
written in base ten, let's allow strings.
This commit is contained in:
Samuel Dionne-Riel 2023-04-25 21:22:31 -04:00
parent d8a0a89d05
commit 3521834abd
3 changed files with 38 additions and 16 deletions

View File

@ -0,0 +1,12 @@
# Handles lazy-loading the configuration, and giving a value for a given key.
module Configuration
def self.[](key)
@configuration ||=
if File.exist?("/etc/boot/config")
JSON.parse(File.read("/etc/boot/config"))
else
{}
end
@configuration[key]
end
end

View File

@ -12,6 +12,7 @@ mobile-nixos.mkLVGUIApp {
enableDebugInformation = true;
src = lib.cleanSource ./.;
rubyFiles = [
"configuration.rb"
"ui.rb"
"main.rb"
];

View File

@ -11,6 +11,13 @@ module Kernel
end
class UI
FG_COLOR = Configuration["splash"] && Configuration["splash"]["foreground"]
FG_COLOR = FG_COLOR.to_i(16) if FG_COLOR.is_a?(String)
FG_COLOR ||= 0xFFFFFFFF
BG_COLOR = Configuration["splash"] && Configuration["splash"]["background"]
BG_COLOR = BG_COLOR.to_i(16) if BG_COLOR.is_a?(String)
BG_COLOR ||= 0xFF000000
attr_reader :screen
attr_reader :progress_bar
attr_reader :ask_identifier
@ -38,7 +45,7 @@ class UI
@label = LVGL::LVLabel.new(@page)
@label.get_style(LVGL::LABEL_STYLE::MAIN).dup.tap do |style|
@label.set_style(LVGL::LABEL_STYLE::MAIN, style)
style.text_color = 0xFFFFFFFF
style.text_color = FG_COLOR
end
@label.set_long_mode(LVGL::LABEL_LONG::BREAK)
@label.set_align(LVGL::LABEL_ALIGN::CENTER)
@ -71,6 +78,8 @@ class UI
@progress_bar.set_height(3 * @unit)
@progress_bar.set_width(@page.get_width * 0.7)
@progress_bar.set_pos(*center(@progress_bar))
@progress_bar.foreground_color = FG_COLOR
@progress_bar.background_color = BG_COLOR
end
def add_screen()
@ -79,8 +88,8 @@ class UI
@screen.set_style(LVGL::CONT_STYLE::MAIN, style)
# Background for the splash, assumed black.
style.body_main_color = 0xFF000000
style.body_grad_color = 0xFF000000
style.body_main_color = BG_COLOR
style.body_grad_color = BG_COLOR
end
end
@ -90,8 +99,8 @@ class UI
@page.set_height(@screen.get_height)
@page.get_style(LVGL::CONT_STYLE::MAIN).dup.tap do |style|
@page.set_style(LVGL::CONT_STYLE::MAIN, style)
style.body_main_color = 0xFF000000
style.body_grad_color = 0xFF000000
style.body_main_color = BG_COLOR
style.body_grad_color = BG_COLOR
style.body_border_width = 0
end
end
@ -102,15 +111,15 @@ class UI
@recovery_container.set_width(@page.get_width)
@recovery_container.get_style(LVGL::CONT_STYLE::MAIN).dup.tap do |style|
@recovery_container.set_style(LVGL::CONT_STYLE::MAIN, style)
style.body_main_color = 0xFF000000
style.body_grad_color = 0xFF000000
style.body_main_color = BG_COLOR
style.body_grad_color = BG_COLOR
style.body_border_width = 0
end
recovery_label = LVGL::LVLabel.new(@recovery_container)
recovery_label.get_style(LVGL::LABEL_STYLE::MAIN).dup.tap do |style|
recovery_label.set_style(LVGL::LABEL_STYLE::MAIN, style)
style.text_color = 0xFFFFFFFF
style.text_color = FG_COLOR
end
recovery_label.set_long_mode(LVGL::LABEL_LONG::BREAK)
recovery_label.set_align(LVGL::LABEL_ALIGN::CENTER)
@ -137,9 +146,9 @@ class UI
@cover.get_style().dup.tap do |style|
@cover.set_style(style)
# Background for the splash, assumed black.
style.body_main_color = 0xFF000000
style.body_grad_color = 0xFF000000
# Background for the splash
style.body_main_color = BG_COLOR
style.body_grad_color = BG_COLOR
# Some themes will add a border to LVObject.
style.body_border_width = 0
end
@ -155,17 +164,17 @@ class UI
set_pwd_mode(true)
get_style(LVGL::TA_STYLE::BG).dup.tap do |style|
set_style(LVGL::TA_STYLE::BG, style)
style.body_main_color = 0xFF000000
style.body_grad_color = 0xFF000000
style.body_main_color = BG_COLOR
style.body_grad_color = BG_COLOR
style.body_radius = 5
style.body_border_color = 0xFFFFFFFF
style.body_border_color = FG_COLOR
style.body_border_width = 3
style.body_border_opa = 255
style.text_color = 0xFFFFFFFF
style.text_color = FG_COLOR
end
get_style(LVGL::TA_STYLE::PLACEHOLDER).dup.tap do |style|
set_style(LVGL::TA_STYLE::PLACEHOLDER, style)
style.text_color = 0xFFAAAAAA
style.text_color = LVGL::LVColor.mix(FG_COLOR, BG_COLOR, 100)
end
end