Use bbx prefix for shared code

This commit is contained in:
Johannes Marbach
2024-03-30 20:52:01 +01:00
parent 6cea4e60d6
commit 1578617560
29 changed files with 224 additions and 354 deletions

View File

@@ -17,11 +17,11 @@
#define LV_ATTRIBUTE_MEM_ALIGN
#endif
#ifndef LV_ATTRIBUTE_IMG_BB_CURSOR_IMG_DSC
#define LV_ATTRIBUTE_IMG_BB_CURSOR_IMG_DSC
#ifndef LV_ATTRIBUTE_IMG_BBX_CURSOR_IMG_DSC
#define LV_ATTRIBUTE_IMG_BBX_CURSOR_IMG_DSC
#endif
const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BB_CURSOR_IMG_DSC uint8_t bb_cursor_img_dsc_map[] = {
const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BBX_CURSOR_IMG_DSC uint8_t bbx_cursor_img_dsc_map[] = {
#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8
/*Pixel format: Alpha 8 bit, Red: 3 bit, Green: 3 bit, Blue: 2 bit*/
0xff, 0xf7, 0xff, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -107,9 +107,9 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BB_CURSOR
#endif
};
const lv_img_dsc_t bb_cursor_img_dsc = {
const lv_img_dsc_t bbx_cursor_img_dsc = {
.header.cf = LV_COLOR_FORMAT_NATIVE_WITH_ALPHA,
.header.w = 12,
.header.h = 18,
.data = bb_cursor_img_dsc_map,
.data = bbx_cursor_img_dsc_map,
};

View File

@@ -4,12 +4,12 @@
*/
#ifndef BB_CURSOR_H
#define BB_CURSOR_H
#ifndef BBX_CURSOR_H
#define BBX_CURSOR_H
#include "lvgl/lvgl.h"
/* Image description of the mouse cursor */
extern const lv_img_dsc_t bb_cursor_img_dsc;
extern const lv_img_dsc_t bbx_cursor_img_dsc;
#endif /* BB_CURSOR_H */
#endif /* BBX_CURSOR_H */

View File

@@ -1,5 +1,5 @@
{
"name": "shared",
"name": "cursor",
"lockfileVersion": 3,
"requires": true,
"packages": {

View File

@@ -7,7 +7,7 @@
npm i
./node_modules/lv_img_conv/lv_img_conv.js -f \
-i bb_cursor_img_dsc \
-i bbx_cursor_img_dsc \
-c CF_TRUE_COLOR_ALPHA \
-o cursor.c \
cursor.png

View File

@@ -15499,9 +15499,9 @@ static lv_font_fmt_txt_dsc_t font_dsc = {
/*Initialize a public general font descriptor*/
#if LV_VERSION_CHECK(8, 0, 0)
const lv_font_t bb_font_32 = {
const lv_font_t bbx_font_32 = {
#else
const lv_font_t bb_font_32 = {
const lv_font_t bbx_font_32 = {
#endif
.get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/
.get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/

View File

@@ -20,6 +20,6 @@ npx lv_font_conv --bpp 4 --size 32 --no-compress -o font_32.c --format lvgl \
# Fix type qualifier for compatibility with LV_FONT_DECLARE and add prefix
sed 's/^lv_font_t /const lv_font_t /g' font_32.c \
| sed 's/lv_font_t font_32/lv_font_t bb_font_32/g' \
| sed 's/lv_font_t font_32/lv_font_t bbx_font_32/g' \
> font_32.c.tmp
mv font_32.c.tmp font_32.c

View File

@@ -169,7 +169,7 @@ static void connect_udev_device(struct udev_device *device) {
/* Obtain and verify device node */
const char *node = udev_device_get_devnode(device);
if (!node || strncmp(node, INPUT_DEVICE_NODE_PREFIX, strlen(INPUT_DEVICE_NODE_PREFIX)) != 0) {
bb_log(BB_LOG_LEVEL_VERBOSE, "Ignoring unsupported input device %s", udev_device_get_syspath(device));
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Ignoring unsupported input device %s", udev_device_get_syspath(device));
return;
}
@@ -181,7 +181,7 @@ static void connect_devnode(const char *node) {
/* Check if the device is already connected */
for (int i = 0; i < num_connected_devices; ++i) {
if (strcmp(devices[i]->node, node) == 0) {
bb_log(BB_LOG_LEVEL_WARNING, "Ignoring already connected input device %s", node);
bbx_log(BBX_LOG_LEVEL_WARNING, "Ignoring already connected input device %s", node);
return;
}
}
@@ -191,7 +191,7 @@ static void connect_devnode(const char *node) {
/* Re-allocate array */
struct input_device **tmp = realloc(devices, (2 * num_devices + 1) * sizeof(struct input_device *));
if (!tmp) {
bb_log(BB_LOG_LEVEL_ERROR, "Could not reallocate memory for input device array");
bbx_log(BBX_LOG_LEVEL_ERROR, "Could not reallocate memory for input device array");
return;
}
devices = tmp;
@@ -214,14 +214,14 @@ static void connect_devnode(const char *node) {
/* Initialise the indev and obtain the libinput device */
device->indev = lv_libinput_create(LV_INDEV_TYPE_NONE, device->node);
if (!device->indev) {
bb_log(BB_LOG_LEVEL_WARNING, "Aborting connection of input device %s because libinput failed to connect it", node);
bbx_log(BBX_LOG_LEVEL_WARNING, "Aborting connection of input device %s because libinput failed to connect it", node);
disconnect_idx(num_connected_devices);
return;
}
lv_libinput_t *dsc = lv_indev_get_driver_data(device->indev);
struct libinput_device *device_libinput = dsc->libinput_device;
if (!device_libinput) {
bb_log(BB_LOG_LEVEL_WARNING, "Aborting connection of input device %s because libinput failed to connect it", node);
bbx_log(BBX_LOG_LEVEL_WARNING, "Aborting connection of input device %s because libinput failed to connect it", node);
disconnect_idx(num_connected_devices);
return;
}
@@ -231,7 +231,7 @@ static void connect_devnode(const char *node) {
/* If the device doesn't have any supported capabilities, exit */
if ((device->capability & allowed_capability) == LV_LIBINPUT_CAPABILITY_NONE) {
bb_log(BB_LOG_LEVEL_WARNING, "Aborting connection of input device %s because it has no allowed capabilities", node);
bbx_log(BBX_LOG_LEVEL_WARNING, "Aborting connection of input device %s because it has no allowed capabilities", node);
disconnect_idx(num_connected_devices);
return;
}
@@ -269,14 +269,14 @@ static void connect_devnode(const char *node) {
/* Increment connected device count */
num_connected_devices++;
bb_log(BB_LOG_LEVEL_VERBOSE, "Connected input device %s (%s)", node, capability_to_str(device->capability));
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Connected input device %s (%s)", node, capability_to_str(device->capability));
}
static void disconnect_udev_device(struct udev_device *device) {
/* Obtain and verify device node */
const char *node = udev_device_get_devnode(device);
if (!node || strncmp(node, INPUT_DEVICE_NODE_PREFIX, strlen(INPUT_DEVICE_NODE_PREFIX)) != 0) {
bb_log(BB_LOG_LEVEL_VERBOSE, "Ignoring unsupported input device %s", udev_device_get_syspath(device));
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Ignoring unsupported input device %s", udev_device_get_syspath(device));
return;
}
@@ -296,7 +296,7 @@ static void disconnect_devnode(const char *node) {
/* If no matching device was found, exit */
if (idx < 0) {
bb_log(BB_LOG_LEVEL_WARNING, "Ignoring already disconnected input device %s", node);
bbx_log(BBX_LOG_LEVEL_WARNING, "Ignoring already disconnected input device %s", node);
return;
}
@@ -316,7 +316,7 @@ static void disconnect_devnode(const char *node) {
/* Decrement connected device count */
--num_connected_devices;
bb_log(BB_LOG_LEVEL_VERBOSE, "Disconnected input device %s", node);
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Disconnected input device %s", node);
}
static void disconnect_idx(int idx) {
@@ -354,7 +354,7 @@ static void set_mouse_cursor(struct input_device *device) {
/* Initialise cursor image if needed */
if (!cursor_obj) {
cursor_obj = lv_img_create(lv_scr_act());
lv_img_set_src(cursor_obj, &bb_cursor_img_dsc);
lv_img_set_src(cursor_obj, &bbx_cursor_img_dsc);
}
/* Apply the cursor image */
@@ -363,7 +363,7 @@ static void set_mouse_cursor(struct input_device *device) {
static void query_device_monitor(lv_timer_t *timer) {
LV_UNUSED(timer);
bb_indev_query_monitor();
bbx_indev_query_monitor();
}
@@ -371,7 +371,7 @@ static void query_device_monitor(lv_timer_t *timer) {
* Public functions
*/
void bb_indev_set_allowed_device_capability(bool keyboard, bool pointer, bool touchscreen) {
void bbx_indev_set_allowed_device_capability(bool keyboard, bool pointer, bool touchscreen) {
allowed_capability = LV_LIBINPUT_CAPABILITY_NONE;
if (keyboard) {
allowed_capability |= LV_LIBINPUT_CAPABILITY_KEYBOARD;
@@ -384,7 +384,7 @@ void bb_indev_set_allowed_device_capability(bool keyboard, bool pointer, bool to
}
}
void bb_indev_set_keyboard_input_group(lv_group_t *group) {
void bbx_indev_set_keyboard_input_group(lv_group_t *group) {
/* Store the group */
keyboard_input_group = group;
@@ -396,21 +396,21 @@ void bb_indev_set_keyboard_input_group(lv_group_t *group) {
}
}
void bb_indev_start_monitor_and_autoconnect(bool keyboard, bool pointer, bool touchscreen) {
bb_indev_set_allowed_device_capability(keyboard, pointer, touchscreen);
bb_indev_start_monitor();
void bbx_indev_start_monitor_and_autoconnect(bool keyboard, bool pointer, bool touchscreen) {
bbx_indev_set_allowed_device_capability(keyboard, pointer, touchscreen);
bbx_indev_start_monitor();
lv_timer_create(query_device_monitor, 1000, NULL);
bb_indev_auto_connect();
bbx_indev_auto_connect();
}
void bb_indev_auto_connect() {
bb_log(BB_LOG_LEVEL_VERBOSE, "Auto-connecting supported input devices");
void bbx_indev_auto_connect() {
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Auto-connecting supported input devices");
/* Make sure udev context is initialised */
if (!context) {
context = udev_new();
if (!context) {
bb_log(BB_LOG_LEVEL_WARNING, "Could not create udev context");
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not create udev context");
return;
}
}
@@ -431,7 +431,7 @@ void bb_indev_auto_connect() {
/* Create udev device */
struct udev_device *device = udev_device_new_from_syspath(context, path);
if (!device) {
bb_log(BB_LOG_LEVEL_WARNING, "Could not create udev device for %s", path);
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not create udev device for %s", path);
continue;
}
@@ -446,51 +446,51 @@ void bb_indev_auto_connect() {
udev_enumerate_unref(enumerate);
}
void bb_indev_start_monitor() {
void bbx_indev_start_monitor() {
/* Make sure udev context is initialised */
if (!context) {
context = udev_new();
if (!context) {
bb_log(BB_LOG_LEVEL_WARNING, "Could not create udev context");
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not create udev context");
return;
}
}
/* Check if monitor is already running */
if (monitor) {
bb_log(BB_LOG_LEVEL_WARNING, "Not starting udev monitor because it is already running");
bbx_log(BBX_LOG_LEVEL_WARNING, "Not starting udev monitor because it is already running");
return;
}
/* Create new monitor */
monitor = udev_monitor_new_from_netlink(context, "udev");
if (!monitor) {
bb_log(BB_LOG_LEVEL_WARNING, "Could not create udev monitor");
bb_indev_stop_monitor();
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not create udev monitor");
bbx_indev_stop_monitor();
return;
}
/* Apply input subsystem filter */
if (udev_monitor_filter_add_match_subsystem_devtype(monitor, "input", NULL) < 0) {
bb_log(BB_LOG_LEVEL_WARNING, "Could not add input subsystem filter for udev monitor");
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not add input subsystem filter for udev monitor");
}
/* Start monitor */
if (udev_monitor_enable_receiving(monitor) < 0) {
bb_log(BB_LOG_LEVEL_WARNING, "Could not enable udev monitor");
bb_indev_stop_monitor();
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not enable udev monitor");
bbx_indev_stop_monitor();
return;
}
/* Obtain monitor file descriptor */
if ((monitor_fd = udev_monitor_get_fd(monitor)) < 0) {
bb_log(BB_LOG_LEVEL_WARNING, "Could not acquire file descriptor for udev monitor");
bb_indev_stop_monitor();
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not acquire file descriptor for udev monitor");
bbx_indev_stop_monitor();
return;
}
}
void bb_indev_stop_monitor() {
void bbx_indev_stop_monitor() {
/* Unreference monitor */
if (monitor) {
udev_monitor_unref(monitor);
@@ -509,10 +509,10 @@ void bb_indev_stop_monitor() {
}
}
void bb_indev_query_monitor() {
void bbx_indev_query_monitor() {
/* Make sure the monitor is running */
if (!monitor) {
bb_log(BB_LOG_LEVEL_ERROR, "Cannot query udev monitor because it is not running");
bbx_log(BBX_LOG_LEVEL_ERROR, "Cannot query udev monitor because it is not running");
return;
}
@@ -547,7 +547,7 @@ void bb_indev_query_monitor() {
}
}
bool bb_indev_is_keyboard_connected() {
bool bbx_indev_is_keyboard_connected() {
for (int i = 0; i < num_connected_devices; ++i) {
if (is_keyboard_device(devices[i])) {
return true;

View File

@@ -4,8 +4,8 @@
*/
#ifndef BB_INDEV_H
#define BB_INDEV_H
#ifndef BBX_INDEV_H
#define BBX_INDEV_H
#include "lvgl/lvgl.h"
@@ -18,14 +18,14 @@
* @param pointer if true, allow connection of pointer devices
* @param touchscreen if true, allow connection of touchscreen devices
*/
void bb_indev_set_allowed_device_capability(bool keyboard, bool pointer, bool touchscreen);
void bbx_indev_set_allowed_device_capability(bool keyboard, bool pointer, bool touchscreen);
/**
* Set the group for receiving input from keyboard devices.
*
* @param group group that should receive input
*/
void bb_indev_set_keyboard_input_group(lv_group_t *group);
void bbx_indev_set_keyboard_input_group(lv_group_t *group);
/**
* Start the udev device monitor and auto-connect currently available devices.
@@ -34,33 +34,33 @@ void bb_indev_set_keyboard_input_group(lv_group_t *group);
* @param pointer if true, allow connection of pointer devices
* @param touchscreen if true, allow connection of touchscreen devices
*/
void bb_indev_start_monitor_and_autoconnect(bool keyboard, bool pointer, bool touchscreen);
void bbx_indev_start_monitor_and_autoconnect(bool keyboard, bool pointer, bool touchscreen);
/**
* Auto-connect currently available keyboard, pointer and touchscreen input devices.
*/
void bb_indev_auto_connect();
void bbx_indev_auto_connect();
/**
* Start the udev device monitor.
*/
void bb_indev_start_monitor();
void bbx_indev_start_monitor();
/**
* Stop the udev device monitor.
*/
void bb_indev_stop_monitor();
void bbx_indev_stop_monitor();
/**
* Query the udev device monitor and (dis)connect added or removed devices
*/
void bb_indev_query_monitor();
void bbx_indev_query_monitor();
/**
* Check if any keyboard devices are connected.
*
* @return true if at least one keyboard device is connected, false otherwise
*/
bool bb_indev_is_keyboard_connected();
bool bbx_indev_is_keyboard_connected();
#endif /* BB_INDEV_H */
#endif /* BBX_INDEV_H */

View File

@@ -15,18 +15,18 @@
* Static variables
*/
static bb_log_level log_level = BB_LOG_LEVEL_ERROR;
static bbx_log_level log_level = BBX_LOG_LEVEL_ERROR;
/**
* Public functions
*/
void bb_log_set_level(bb_log_level level) {
void bbx_log_set_level(bbx_log_level level) {
log_level = level;
}
void bb_log(bb_log_level level, const char *format, ...) {
void bbx_log(bbx_log_level level, const char *format, ...) {
if (level > log_level) {
return;
}
@@ -42,7 +42,7 @@ void bb_log(bb_log_level level, const char *format, ...) {
}
}
void bb_log_print_cb(lv_log_level_t level, const char *msg) {
void bbx_log_print_cb(lv_log_level_t level, const char *msg) {
LV_UNUSED(level);
bb_log(BB_LOG_LEVEL_VERBOSE, msg);
bbx_log(BBX_LOG_LEVEL_VERBOSE, msg);
}

View File

@@ -4,8 +4,8 @@
*/
#ifndef BB_LOG_H
#define BB_LOG_H
#ifndef BBX_LOG_H
#define BBX_LOG_H
#include "lvgl/lvgl.h"
@@ -14,19 +14,19 @@
*/
typedef enum {
/* Errors only */
BB_LOG_LEVEL_ERROR = 0,
BBX_LOG_LEVEL_ERROR = 0,
/* Warnings and errors */
BB_LOG_LEVEL_WARNING = 1,
BBX_LOG_LEVEL_WARNING = 1,
/* Include non-errors in log */
BB_LOG_LEVEL_VERBOSE = 2
} bb_log_level;
BBX_LOG_LEVEL_VERBOSE = 2
} bbx_log_level;
/**
* Set the log level.
*
* @param level new log level value
*/
void bb_log_set_level(bb_log_level level);
void bbx_log_set_level(bbx_log_level level);
/**
* Log a message. A newline character is appended unless the message ends in one.
@@ -35,7 +35,7 @@ void bb_log_set_level(bb_log_level level);
* @param format message format string
* @param ... parameters to fill into the format string
*/
void bb_log(bb_log_level level, const char *format, ...);
void bbx_log(bbx_log_level level, const char *format, ...);
/**
* Handle an LVGL log message.
@@ -43,6 +43,6 @@ void bb_log(bb_log_level level, const char *format, ...);
* @param level LVGL log level
* @param msg message to print
*/
void bb_log_print_cb(lv_log_level_t level, const char *msg);
void bbx_log_print_cb(lv_log_level_t level, const char *msg);
#endif /* BB_LOG_H */
#endif /* BBX_LOG_H */

View File

@@ -16,7 +16,7 @@
* Static variables
*/
static bb_theme current_theme;
static bbx_theme current_theme;
static lv_theme_t lv_theme;
static struct {
@@ -55,7 +55,7 @@ static bool are_styles_initialised = false;
*
* @param theme theme to derive the styles from
*/
static void init_styles(const bb_theme *theme);
static void init_styles(const bbx_theme *theme);
/**
* Initialise or reset a style.
@@ -84,9 +84,9 @@ static void keyboard_draw_task_added_cb(lv_event_t *event);
* Static functions
*/
static void init_styles(const bb_theme *theme) {
static void init_styles(const bbx_theme *theme) {
reset_style(&(styles.widget));
lv_style_set_text_font(&(styles.widget), &bb_font_32);
lv_style_set_text_font(&(styles.widget), &bbx_font_32);
reset_style(&(styles.window));
lv_style_set_bg_opa(&(styles.window), LV_OPA_COVER);
@@ -236,7 +236,7 @@ static void apply_theme_cb(lv_theme_t *theme, lv_obj_t *obj) {
return;
}
if (lv_obj_has_flag(obj, BB_WIDGET_HEADER)) {
if (lv_obj_has_flag(obj, BBX_WIDGET_HEADER)) {
lv_obj_add_style(obj, &(styles.header), 0);
return;
}
@@ -329,7 +329,7 @@ static void keyboard_draw_task_added_cb(lv_event_t *event) {
return;
}
bb_theme_key *key = NULL;
bbx_theme_key *key = NULL;
if ((btnm->ctrl_bits[dsc->id1] & SQ2LV_CTRL_MOD_INACTIVE) == SQ2LV_CTRL_MOD_INACTIVE) {
key = &(current_theme.keyboard.keys.key_mod_inact);
@@ -364,21 +364,21 @@ static void keyboard_draw_task_added_cb(lv_event_t *event) {
* Public functions
*/
void bb_theme_prepare_keyboard(lv_obj_t *keyboard) {
void bbx_theme_prepare_keyboard(lv_obj_t *keyboard) {
lv_obj_add_event_cb(keyboard, keyboard_draw_task_added_cb, LV_EVENT_DRAW_TASK_ADDED, NULL);
lv_obj_add_flag(keyboard, LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS);
}
void bb_theme_apply(const bb_theme *theme) {
void bbx_theme_apply(const bbx_theme *theme) {
if (!theme) {
bb_log(BB_LOG_LEVEL_ERROR, "Could not apply theme from NULL pointer");
bbx_log(BBX_LOG_LEVEL_ERROR, "Could not apply theme from NULL pointer");
return;
}
lv_theme.disp = NULL;
lv_theme.font_small = &bb_font_32;
lv_theme.font_normal = &bb_font_32;
lv_theme.font_large = &bb_font_32;
lv_theme.font_small = &bbx_font_32;
lv_theme.font_normal = &bbx_font_32;
lv_theme.font_large = &bbx_font_32;
lv_theme.apply_cb = apply_theme_cb;
current_theme = *theme;

View File

@@ -4,15 +4,15 @@
*/
#ifndef BB_THEME_H
#define BB_THEME_H
#ifndef BBX_THEME_H
#define BBX_THEME_H
#include "lvgl/lvgl.h"
#include <stdbool.h>
#include <stdint.h>
#define BB_WIDGET_HEADER LV_OBJ_FLAG_USER_1
#define BBX_WIDGET_HEADER LV_OBJ_FLAG_USER_1
/**
* Theming structs
@@ -21,7 +21,7 @@
/* Window theme */
typedef struct {
uint32_t bg_color;
} bb_theme_window;
} bbx_theme_window;
/* Header theme */
typedef struct {
@@ -30,30 +30,30 @@ typedef struct {
uint32_t border_color;
lv_coord_t pad;
lv_coord_t gap;
} bb_theme_header;
} bbx_theme_header;
/* Key theme for one specific key type and state */
typedef struct {
uint32_t fg_color;
uint32_t bg_color;
uint32_t border_color;
} bb_theme_key_state;
} bbx_theme_key_state;
/* Key theme for one specific key type and all states */
typedef struct {
bb_theme_key_state normal;
bb_theme_key_state pressed;
} bb_theme_key;
bbx_theme_key_state normal;
bbx_theme_key_state pressed;
} bbx_theme_key;
/* Key theme */
typedef struct {
lv_coord_t border_width;
lv_coord_t corner_radius;
bb_theme_key key_char;
bb_theme_key key_non_char;
bb_theme_key key_mod_act;
bb_theme_key key_mod_inact;
} bb_theme_keys;
bbx_theme_key key_char;
bbx_theme_key key_non_char;
bbx_theme_key key_mod_act;
bbx_theme_key key_mod_inact;
} bbx_theme_keys;
/* Keyboard theme */
typedef struct {
@@ -62,31 +62,31 @@ typedef struct {
uint32_t border_color;
lv_coord_t pad;
lv_coord_t gap;
bb_theme_keys keys;
} bb_theme_keyboard;
bbx_theme_keys keys;
} bbx_theme_keyboard;
/* Button theme for one specific button state */
typedef struct {
uint32_t fg_color;
uint32_t bg_color;
uint32_t border_color;
} bb_theme_button_state;
} bbx_theme_button_state;
/* Button theme */
typedef struct {
lv_coord_t border_width;
lv_coord_t corner_radius;
lv_coord_t pad;
bb_theme_button_state normal;
bb_theme_button_state pressed;
} bb_theme_button;
bbx_theme_button_state normal;
bbx_theme_button_state pressed;
} bbx_theme_button;
/* Text area cursor theme */
typedef struct {
lv_coord_t width;
uint32_t color;
int period;
} bb_theme_textarea_cursor;
} bbx_theme_textarea_cursor;
/* Text area theme */
typedef struct {
@@ -97,8 +97,8 @@ typedef struct {
lv_coord_t corner_radius;
lv_coord_t pad;
uint32_t placeholder_color;
bb_theme_textarea_cursor cursor;
} bb_theme_textarea;
bbx_theme_textarea_cursor cursor;
} bbx_theme_textarea;
/* Dropdown list theme */
typedef struct {
@@ -110,29 +110,29 @@ typedef struct {
uint32_t border_color;
lv_coord_t corner_radius;
lv_coord_t pad;
} bb_theme_dropdown_list;
} bbx_theme_dropdown_list;
/* Dropdown theme */
typedef struct {
bb_theme_button button;
bb_theme_dropdown_list list;
} bb_theme_dropdown;
bbx_theme_button button;
bbx_theme_dropdown_list list;
} bbx_theme_dropdown;
/* Label */
typedef struct {
uint32_t fg_color;
} bb_theme_label;
} bbx_theme_label;
/* Message box buttons theme */
typedef struct {
lv_coord_t gap;
} bb_theme_msgbox_buttons;
} bbx_theme_msgbox_buttons;
/* Message box dimming theme */
typedef struct {
uint32_t color;
short opacity;
} bb_theme_msgbox_dimming;
} bbx_theme_msgbox_dimming;
/* Message box theme */
typedef struct {
@@ -143,49 +143,49 @@ typedef struct {
lv_coord_t corner_radius;
lv_coord_t pad;
lv_coord_t gap;
bb_theme_msgbox_buttons buttons;
bb_theme_msgbox_dimming dimming;
} bb_theme_msgbox;
bbx_theme_msgbox_buttons buttons;
bbx_theme_msgbox_dimming dimming;
} bbx_theme_msgbox;
/* Progress bar indicator theme */
typedef struct {
uint32_t bg_color;
} bb_theme_bar_indicator;
} bbx_theme_bar_indicator;
/* Progress bar theme */
typedef struct {
lv_coord_t border_width;
uint32_t border_color;
lv_coord_t corner_radius;
bb_theme_bar_indicator indicator;
} bb_theme_bar;
bbx_theme_bar_indicator indicator;
} bbx_theme_bar;
/* Full theme */
typedef struct {
char *name;
bb_theme_window window;
bb_theme_header header;
bb_theme_keyboard keyboard;
bb_theme_button button;
bb_theme_textarea textarea;
bb_theme_dropdown dropdown;
bb_theme_label label;
bb_theme_msgbox msgbox;
bb_theme_bar bar;
} bb_theme;
bbx_theme_window window;
bbx_theme_header header;
bbx_theme_keyboard keyboard;
bbx_theme_button button;
bbx_theme_textarea textarea;
bbx_theme_dropdown dropdown;
bbx_theme_label label;
bbx_theme_msgbox msgbox;
bbx_theme_bar bar;
} bbx_theme;
/**
* Prepare a keyboard widget to be themed with a theme.
*
* @param keyboard keyboard widget
*/
void bb_theme_prepare_keyboard(lv_obj_t *keyboard);
void bbx_theme_prepare_keyboard(lv_obj_t *keyboard);
/**
* Apply a UI theme.
*
* @param theme the theme to apply
*/
void bb_theme_apply(const bb_theme *theme);
void bbx_theme_apply(const bbx_theme *theme);
#endif /* BB_THEME_H */
#endif /* BBX_THEME_H */

View File

@@ -16,7 +16,7 @@
*/
/* Breezy light (based on KDE Breeze color palette, see https://develop.kde.org/hig/style/color/default/) */
static const bb_theme breezy_light = {
static const bbx_theme breezy_light = {
.name = "breezy-light",
.window = {
.bg_color = 0xeff0f1
@@ -174,7 +174,7 @@ static const bb_theme breezy_light = {
/* Breezy dark (based on KDE Breeze Dark color palette, see https://develop.kde.org/hig/style/color/dark/) */
static const bb_theme breezy_dark = {
static const bbx_theme breezy_dark = {
.name = "breezy-dark",
.window = {
.bg_color = 0x31363b
@@ -331,7 +331,7 @@ static const bb_theme breezy_dark = {
};
/* pmOS light (based on palette https://coolors.co/009900-395e66-db504a-e3b505-ebf5ee) */
static const bb_theme pmos_light = {
static const bbx_theme pmos_light = {
.name = "pmos-light",
.window = {
.bg_color = 0xf2f7f8,
@@ -488,7 +488,7 @@ static const bb_theme pmos_light = {
};
/* pmOS dark (based on palette https://coolors.co/009900-395e66-db504a-e3b505-ebf5ee) */
static const bb_theme pmos_dark = {
static const bbx_theme pmos_dark = {
.name = "pmos-dark",
.window = {
.bg_color = 0x070c0d
@@ -648,21 +648,21 @@ static const bb_theme pmos_dark = {
* Public interface
*/
const int bb_themes_num_themes = 4;
const bb_theme *bb_themes_themes[] = {
const int bbx_themes_num_themes = 4;
const bbx_theme *bbx_themes_themes[] = {
&breezy_light,
&breezy_dark,
&pmos_light,
&pmos_dark
};
bb_themes_theme_id_t bb_themes_find_theme_with_name(const char *name) {
for (int i = 0; i < bb_themes_num_themes; ++i) {
if (strcmp(bb_themes_themes[i]->name, name) == 0) {
bb_log(BB_LOG_LEVEL_VERBOSE, "Found theme: %s\n", name);
bbx_themes_theme_id_t bbx_themes_find_theme_with_name(const char *name) {
for (int i = 0; i < bbx_themes_num_themes; ++i) {
if (strcmp(bbx_themes_themes[i]->name, name) == 0) {
bbx_log(BBX_LOG_LEVEL_VERBOSE, "Found theme: %s\n", name);
return i;
}
}
bb_log(BB_LOG_LEVEL_WARNING, "Theme %s not found\n", name);
return BB_THEMES_THEME_NONE;
bbx_log(BBX_LOG_LEVEL_WARNING, "Theme %s not found\n", name);
return BBX_THEMES_THEME_NONE;
}

View File

@@ -4,30 +4,30 @@
*/
#ifndef BB_THEMES_H
#define BB_THEMES_H
#ifndef BBX_THEMES_H
#define BBX_THEMES_H
#include "theme.h"
/* Theme IDs, values can be used as indexes into the bb_themes_themes array */
/* Theme IDs, values can be used as indexes into the bbx_themes_themes array */
typedef enum {
BB_THEMES_THEME_NONE = -1,
BB_THEMES_THEME_BREEZY_LIGHT = 0,
BB_THEMES_THEME_BREEZY_DARK = 1,
BB_THEMES_THEME_PMOS_LIGHT = 2,
BB_THEMES_THEME_PMOS_DARK = 3
} bb_themes_theme_id_t;
BBX_THEMES_THEME_NONE = -1,
BBX_THEMES_THEME_BREEZY_LIGHT = 0,
BBX_THEMES_THEME_BREEZY_DARK = 1,
BBX_THEMES_THEME_PMOS_LIGHT = 2,
BBX_THEMES_THEME_PMOS_DARK = 3
} bbx_themes_theme_id_t;
/* Themes */
extern const int bb_themes_num_themes;
extern const bb_theme *bb_themes_themes[];
extern const int bbx_themes_num_themes;
extern const bbx_theme *bbx_themes_themes[];
/**
* Find the first theme with a given name.
*
* @param name theme name
* @return ID of the first matching theme or BB_THEMES_THEME_NONE if no theme matched
* @return ID of the first matching theme or BBX_THEMES_THEME_NONE if no theme matched
*/
bb_themes_theme_id_t bb_themes_find_theme_with_name(const char *name);
bbx_themes_theme_id_t bbx_themes_find_theme_with_name(const char *name);
#endif /* BB_THEMES_H */
#endif /* BBX_THEMES_H */