Skip to content

Commit

Permalink
new theming part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Aug 2, 2024
1 parent b0c0b94 commit af5f06a
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 121 deletions.
20 changes: 10 additions & 10 deletions common/droidboot_theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ lv_style_t droidboot_list_button_selected_style;
void droidboot_style_init(struct global_config *global_config){
droidboot_log(DROIDBOOT_LOG_TRACE, "Current theme settings: radius: %d, bg_color: %llx, border_width: %d, border_color: %llx \n", global_config->radius, global_config->bg_color, global_config->border_width, global_config->border_color);
lv_style_init(&droidboot_list_style);
lv_style_set_radius(&droidboot_list_style, global_config->radius);
lv_style_set_bg_color(&droidboot_list_style, lv_color_hex(global_config->bg_color));
lv_style_set_border_width(&droidboot_list_style, global_config->border_width);
lv_style_set_border_color(&droidboot_list_style, lv_color_hex(global_config->border_color));
lv_style_set_radius(&droidboot_list_style, global_config->win_radius);
lv_style_set_bg_color(&droidboot_list_style, lv_color_hex(global_config->win_bg_color));
lv_style_set_border_width(&droidboot_list_style, global_config->win_border_size);
lv_style_set_border_color(&droidboot_list_style, lv_color_hex(global_config->win_border_color));

lv_style_init(&droidboot_win_style);
lv_style_set_radius(&droidboot_win_style, global_config->radius);
lv_style_set_bg_color(&droidboot_win_style, lv_color_hex(global_config->bg_color));
lv_style_set_border_width(&droidboot_win_style, global_config->border_width);
lv_style_set_border_color(&droidboot_win_style, lv_color_hex(global_config->border_color));
lv_style_set_radius(&droidboot_win_style, global_config->list_radius);
lv_style_set_bg_color(&droidboot_win_style, lv_color_hex(global_config->list_bg_color));
lv_style_set_border_width(&droidboot_win_style, global_config->list_border_size);
lv_style_set_border_color(&droidboot_win_style, lv_color_hex(global_config->list_border_color));

lv_style_init(&droidboot_list_button_style);
lv_style_set_radius(&droidboot_list_button_style, global_config->radius);
lv_style_set_radius(&droidboot_list_button_style, global_config->button_unselected_radius);
lv_style_set_text_color(&droidboot_list_button_style, lv_color_hex(global_config->button_text_color));
lv_style_set_bg_color(&droidboot_list_button_style, lv_color_hex(global_config->button_color));
lv_style_set_border_width(&droidboot_list_button_style, global_config->button_border_width);
Expand All @@ -33,7 +33,7 @@ void droidboot_style_init(struct global_config *global_config){
lv_style_set_transform_width(&droidboot_list_button_style, 100);

lv_style_init(&droidboot_list_button_selected_style);
lv_style_set_radius(&droidboot_list_button_selected_style, global_config->radius);
lv_style_set_radius(&droidboot_list_button_selected_style, global_config->button_selected_radius);
lv_style_set_border_color(&droidboot_list_button_selected_style, lv_color_hex(global_config->border_selected_color));
lv_style_set_text_color(&droidboot_list_button_selected_style, lv_color_hex(global_config->button_selected_text_color));
lv_style_set_bg_color(&droidboot_list_button_selected_style, lv_color_hex(global_config->button_selected_color));
Expand Down
216 changes: 121 additions & 95 deletions config_parser/droidboot_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,13 @@
#include <droidboot_stdfunc.h>
#include <droidboot_fs_util.h>
#include <droidboot_platform_common.h>
#include <droidboot_config_parser.h>

#include <ext4.h>

#define ENTRIES_DIR "/boot/db/entries/"
#define GLOBAL_CONFIG_FILE "/boot/db/db.conf"

struct boot_entry {
char *title;
char *kernel;
char *initrd;
char *dtb;
char *dtbo;
char *options;
char *logo;
int error;
};

struct global_config {
char *default_entry_title;
struct boot_entry *default_entry;
int timeout;
uint32_t bg_color;
uint32_t button_color;
uint32_t button_text_color;
uint32_t button_selected_color;
uint32_t button_selected_text_color;
uint8_t border_width;
uint32_t border_color;
uint32_t border_selected_color;
uint8_t button_border_width;
uint32_t button_border_color;
uint32_t button_border_selected_color;
uint8_t radius;
bool button_grow_default;
};

int config_parse_option(char **_dest, const char *option, const char *buffer) {
char *option_whitespace = malloc(strlen(option)+strlen(" ")+1);
Expand Down Expand Up @@ -234,43 +206,64 @@ int parse_global_config(struct global_config *global_config) {
global_config->timeout = 20;
droidboot_log(DROIDBOOT_LOG_WARNING, "config_parser: no global config found\n");
// Background color
global_config->bg_color = 0x000000;
global_config->win_bg_color = 0x000000;

// Radius
global_config->win_radius = 0;

// Border width
global_config->win_border_size = 0;

// Border color
global_config->win_border_color = 0xffffff;

// List background color
global_config->list_bg_color = 0x000000;

// List radius
global_config->list_radius = 0;

// List border width
global_config->list_border_size = 0;

// List border color
global_config->list_border_color = 0xffffff;

// Button color
global_config->button_color = 0x000000;
global_config->button_unselected_color = 0x000000;

// Button text color
global_config->button_text_color = 0xffffff;
global_config->button_unselected_text_color = 0xffffff;

// Button selected color
global_config->button_selected_color = 0xff9800;

// Button selected text color
global_config->button_selected_text_color = 0x000000;

// Border width
global_config->border_width = 0;

// Border color
global_config->border_color = 0xffffff;

// Border selected color
global_config->border_selected_color = 0xffffff;

// Button border width
global_config->button_border_width = 1;
global_config->button_border_unselected_size = 1;

// Button border color
global_config->button_border_color = 0xffffff;
global_config->button_border_unselected_color = 0xffffff;

// Button border selected width
global_config->button_border_selected_size = 1;

// Button border selected color
global_config->button_border_selected_color = 0xffffff;

// Radius
global_config->radius = 0;
// Button grow by default
global_config->button_grow_default = true;

// Button grow by default
global_config->button_grow_default = true;
// Button radius
global_config->button_radius = 0;

// Global font size
global_config->global_font_size = 0;

// Global font name
global_config->global_font_name = NULL;

return 0;

Expand Down Expand Up @@ -302,76 +295,88 @@ int parse_global_config(struct global_config *global_config) {
// Theme parsing

// Background color
char *bg_color = NULL;
ret = config_parse_option(&bg_color, "bg_color", (const char *)buf);
if(ret<0) global_config->bg_color = 0x000000;
else global_config->bg_color = droidboot_strtol(bg_color, NULL, 16);

// Button color
char *button_color = NULL;
ret = config_parse_option(&button_color, "button_color", (const char *)buf);
if(ret<0) global_config->button_color = 0x000000;
else global_config->button_color = droidboot_strtol(button_color, NULL, 16);

// Button text color
char *button_text_color = NULL;
ret = config_parse_option(&button_text_color, "button_text_color", (const char *)buf);
if(ret<0) global_config->button_text_color = 0xffffff;
else global_config->button_text_color = droidboot_strtol(button_text_color, NULL, 16);
char *win_bg_color = NULL;
ret = config_parse_option(&win_bg_color, "win_bg_color", (const char *)buf);
if(ret<0) global_config->win_bg_color = 0x000000;
else global_config->win_bg_color = droidboot_strtol(win_bg_color, NULL, 16);
free(win_bg_color);

// Radius
char *win_radius = NULL;
ret = config_parse_option(&win_radius, "win_radius", (const char *)buf);
if(ret<0) global_config->win_radius = 0;
else global_config->win_radius = droidboot_atoi(win_radius);
free(win_radius);

// Border width
char *win_border_size = NULL;
ret = config_parse_option(&win_border_size, "win_border_size", (const char *)buf);
if(ret<0) global_config->win_border_size = 0;
else global_config->win_border_size = droidboot_atoi(win_border_size);
free(win_border_size);

// Border color
char *win_border_color = NULL;
ret = config_parse_option(&win_border_color, "win_border_color", (const char *)buf);
if(ret<0) global_config->win_border_color = 0xffffff;
else global_config->win_border_color = droidboot_strtol(win_border_color, NULL, 16);
free(win_border_color);

// Button unselected color
char *button_unselected_color = NULL;
ret = config_parse_option(&button_unselected_color, "button_unselected_color", (const char *)buf);
if(ret<0) global_config->button_unselected_color = 0x000000;
else global_config->button_unselected_color = droidboot_strtol(button_unselected_color, NULL, 16);
free(button_unselected_color);

// Button unselected text color
char *button_unselected_text_color = NULL;
ret = config_parse_option(&button_unselected_text_color, "button_unselected_text_color", (const char *)buf);
if(ret<0) global_config->button_unselected_text_color = 0xffffff;
else global_config->button_unselected_text_color = droidboot_strtol(button_unselected_text_color, NULL, 16);
free(button_unselected_text_color);

// Button selected color
char *button_selected_color = NULL;
ret = config_parse_option(&button_selected_color, "button_selected_color", (const char *)buf);
if(ret<0) global_config->button_selected_color = 0xff9800;
else global_config->button_selected_color = droidboot_strtol(button_selected_color, NULL, 16);
free(button_selected_color);

// Button selected text color
char *button_selected_text_color = NULL;
ret = config_parse_option(&button_selected_text_color, "button_selected_text_color", (const char *)buf);
if(ret<0) global_config->button_selected_text_color = 0x000000;
else global_config->button_selected_text_color = droidboot_strtol(button_selected_text_color, NULL, 16);
free(button_selected_text_color);

// Border width
char *border_width = NULL;
ret = config_parse_option(&border_width, "border_width", (const char *)buf);
if(ret<0) global_config->border_width = 0;
else global_config->border_width = droidboot_atoi(border_width);

// Border color
char *border_color = NULL;
ret = config_parse_option(&border_color, "border_color", (const char *)buf);
if(ret<0) global_config->border_color = 0xffffff;
else global_config->border_color = droidboot_strtol(border_color, NULL, 16);

// Border selected color
char *border_selected_color = NULL;
ret = config_parse_option(&border_selected_color, "border_selected_color", (const char *)buf);
if(ret<0) global_config->border_selected_color = 0xffffff;
else global_config->border_selected_color = droidboot_strtol(border_selected_color, NULL, 16);

// Button border width
char *button_border_width = NULL;
ret = config_parse_option(&button_border_width, "button_border_width", (const char *)buf);
if(ret<0) global_config->button_border_width = 1;
else global_config->button_border_width = droidboot_atoi(button_border_width);
// Button border size
char *button_border_unselected_size = NULL;
ret = config_parse_option(&button_border_unselected_size, "button_border_unselected_size", (const char *)buf);
if(ret<0) global_config->button_border_unselected_size = 1;
else global_config->button_border_unselected_size = droidboot_atoi(button_border_unselected_size);
free(button_border_unselected_size);

// Button border color
char *button_border_color = NULL;
ret = config_parse_option(&button_border_color, "button_border_color", (const char *)buf);
if(ret<0) global_config->button_border_color = 0xffffff;
else global_config->button_border_color = droidboot_strtol(button_border_color, NULL, 16);
char *button_border_unselected_color = NULL;
ret = config_parse_option(&button_border_unselected_color, "button_border_unselected_color", (const char *)buf);
if(ret<0) global_config->button_border_unselected_color = 0xffffff;
else global_config->button_border_unselected_color = droidboot_strtol(button_border_unselected_color, NULL, 16);
free(button_border_unselected_color);

// Button border selected color
char *button_border_selected_color = NULL;
ret = config_parse_option(&button_border_selected_color, "button_border_selected_color", (const char *)buf);
if(ret<0) global_config->button_border_selected_color = 0xffffff;
else global_config->button_border_selected_color = droidboot_strtol(button_border_selected_color, NULL, 16);
free(button_border_selected_color);

// Radius
char *radius = NULL;
ret = config_parse_option(&radius, "radius", (const char *)buf);
if(ret<0) global_config->radius = 0;
else global_config->radius = droidboot_atoi(radius);
// Button border selected size
char *button_border_selected_size = NULL;
ret = config_parse_option(&button_border_selected_size, "button_border_selected_size", (const char *)buf);
if(ret<0) global_config->button_border_selected_size = 1;
else global_config->button_border_selected_size = droidboot_atoi(button_border_selected_size);
free(button_border_selected_size);

// Button grow by default
char *button_grow_default = NULL;
Expand All @@ -380,6 +385,27 @@ int parse_global_config(struct global_config *global_config) {
global_config->button_grow_default = true;
else
global_config->button_grow_default = false;
free(button_grow_default);

// Button radius
char *button_radius = NULL;
ret = config_parse_option(&button_radius, "button_radius", (const char *)buf);
if(ret<0) global_config->button_radius = 0;
else global_config->button_radius = droidboot_atoi(button_radius);
free(button_radius);

// Global font size
char *global_font_size = NULL;
ret = config_parse_option(&global_font_size, "global_font_size", (const char *)buf);
if(ret<0) global_config->global_font_size = 0;
else global_config->global_font_size = droidboot_atoi(global_font_size);
free(global_font_size);

// Global font name
char *global_font_name = NULL;
ret = config_parse_option(&global_font_name, "global_font_name", (const char *)buf);
if(ret<0) global_config->global_font_name = NULL;
else global_config->global_font_name = global_font_name;

return 0;
}
40 changes: 24 additions & 16 deletions include/droidboot_config_parser.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#pragma once

struct global_config {
char *default_entry_title;
struct boot_entry *default_entry;
int timeout;
uint32_t bg_color;
uint32_t button_color;
uint32_t button_text_color;
uint32_t button_selected_color;
uint32_t button_selected_text_color;
uint8_t border_width;
uint32_t border_color;
uint32_t border_selected_color;
uint8_t button_border_width;
uint32_t button_border_color;
uint32_t button_border_selected_color;
uint8_t radius;
bool button_grow_default;
char *default_entry_title;
struct boot_entry *default_entry;
int timeout;
uint32_t win_bg_color;
uint8_t win_radius;
uint8_t win_border_size;
uint32_t win_border_color;
uint32_t list_bg_color;
uint8_t list_radius;
uint8_t list_border_size;
uint32_t list_border_color;
uint32_t global_font_size;
char* global_font_name;
uint32_t button_unselected_color;
uint32_t button_unselected_text_color;
uint32_t button_selected_color;
uint32_t button_selected_text_color;
uint8_t button_radius;
bool button_grow_default;
uint8_t button_border_unselected_size;
uint32_t button_border_unselected_color;
uint8_t button_border_selected_size;
uint32_t button_border_selected_color;
};


Expand Down

0 comments on commit af5f06a

Please sign in to comment.