Browse Source

refactor(display): Saner font selection/defaults.

* Only select fonts for the default built in status screen
* Leverage theme default fonts, instead of hardcoding theme
  details in each component.
xmkb
Peter Johanson 4 years ago committed by Pete Johanson
parent
commit
3e6a3758ed
  1. 21
      app/src/display/Kconfig
  2. 3
      app/src/display/status_screen.c
  3. 4
      app/src/display/widgets/Kconfig
  4. 18
      app/src/display/widgets/battery_status.c
  5. 18
      app/src/display/widgets/layer_status.c
  6. 19
      app/src/display/widgets/output_status.c
  7. 19
      app/src/display/widgets/wpm_status.c

21
app/src/display/Kconfig

@ -18,7 +18,6 @@ endchoice
choice ZMK_DISPLAY_STATUS_SCREEN choice ZMK_DISPLAY_STATUS_SCREEN
prompt "Default status screen for displays" prompt "Default status screen for displays"
default ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN
config ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN config ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN
bool "Built in status screen" bool "Built in status screen"
@ -52,6 +51,26 @@ config ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY
endif # ZMK_DISPLAY_WORK_QUEUE_DEDICATED endif # ZMK_DISPLAY_WORK_QUEUE_DEDICATED
if ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN
config LVGL_FONT_MONTSERRAT_16
default y
choice LVGL_THEME_DEFAULT_FONT_NORMAL
default LVGL_THEME_DEFAULT_FONT_NORMAL_MONTSERRAT_16
endchoice
config LVGL_FONT_MONTSERRAT_12
default y
choice LVGL_THEME_DEFAULT_FONT_SMALL
default LVGL_THEME_DEFAULT_FONT_SMALL_MONTSERRAT_12
endchoice
endif # ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN
rsource "widgets/Kconfig" rsource "widgets/Kconfig"
endif endif

3
app/src/display/status_screen.c

@ -48,6 +48,9 @@ lv_obj_t *zmk_display_status_screen() {
#if IS_ENABLED(CONFIG_ZMK_WIDGET_LAYER_STATUS) #if IS_ENABLED(CONFIG_ZMK_WIDGET_LAYER_STATUS)
zmk_widget_layer_status_init(&layer_status_widget, screen); zmk_widget_layer_status_init(&layer_status_widget, screen);
lv_obj_set_style_local_text_font(zmk_widget_layer_status_obj(&layer_status_widget),
LV_LABEL_PART_MAIN, LV_STATE_DEFAULT,
lv_theme_get_font_small());
lv_obj_align(zmk_widget_layer_status_obj(&layer_status_widget), NULL, LV_ALIGN_IN_BOTTOM_LEFT, lv_obj_align(zmk_widget_layer_status_obj(&layer_status_widget), NULL, LV_ALIGN_IN_BOTTOM_LEFT,
0, 0); 0, 0);
#endif #endif

4
app/src/display/widgets/Kconfig

@ -8,27 +8,23 @@ config ZMK_WIDGET_LAYER_STATUS
default y default y
depends on !ZMK_SPLIT || ZMK_SPLIT_BLE_ROLE_CENTRAL depends on !ZMK_SPLIT || ZMK_SPLIT_BLE_ROLE_CENTRAL
select LVGL_USE_LABEL select LVGL_USE_LABEL
select LVGL_FONT_MONTSERRAT_12
config ZMK_WIDGET_BATTERY_STATUS config ZMK_WIDGET_BATTERY_STATUS
bool "Widget for battery charge information, using small icons" bool "Widget for battery charge information, using small icons"
depends on BT depends on BT
default y if BT default y if BT
select LVGL_USE_LABEL select LVGL_USE_LABEL
select LVGL_FONT_MONTSERRAT_16
config ZMK_WIDGET_OUTPUT_STATUS config ZMK_WIDGET_OUTPUT_STATUS
bool "Widget for keyboard output status icons" bool "Widget for keyboard output status icons"
depends on BT depends on BT
default y if BT default y if BT
select LVGL_USE_LABEL select LVGL_USE_LABEL
select LVGL_FONT_MONTSERRAT_16
config ZMK_WIDGET_WPM_STATUS config ZMK_WIDGET_WPM_STATUS
bool "Widget for displaying typed words per minute" bool "Widget for displaying typed words per minute"
depends on !ZMK_SPLIT || ZMK_SPLIT_BLE_ROLE_CENTRAL depends on !ZMK_SPLIT || ZMK_SPLIT_BLE_ROLE_CENTRAL
select LVGL_USE_LABEL select LVGL_USE_LABEL
select LVGL_FONT_MONTSERRAT_16
select ZMK_WPM select ZMK_WPM
endmenu endmenu

18
app/src/display/widgets/battery_status.c

@ -18,22 +18,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/events/battery_state_changed.h> #include <zmk/events/battery_state_changed.h>
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
static lv_style_t label_style;
static bool style_initialized = false;
void battery_status_init() {
if (style_initialized) {
return;
}
style_initialized = true;
lv_style_init(&label_style);
lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_16);
lv_style_set_text_letter_space(&label_style, LV_STATE_DEFAULT, 1);
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1);
}
struct battery_status_state { struct battery_status_state {
uint8_t level; uint8_t level;
@ -90,9 +74,7 @@ ZMK_SUBSCRIPTION(widget_battery_status, zmk_usb_conn_state_changed);
#endif /* IS_ENABLED(CONFIG_USB) */ #endif /* IS_ENABLED(CONFIG_USB) */
int zmk_widget_battery_status_init(struct zmk_widget_battery_status *widget, lv_obj_t *parent) { int zmk_widget_battery_status_init(struct zmk_widget_battery_status *widget, lv_obj_t *parent) {
battery_status_init();
widget->obj = lv_label_create(parent, NULL); widget->obj = lv_label_create(parent, NULL);
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style);
lv_obj_set_size(widget->obj, 40, 15); lv_obj_set_size(widget->obj, 40, 15);

18
app/src/display/widgets/layer_status.c

@ -16,28 +16,12 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/keymap.h> #include <zmk/keymap.h>
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
static lv_style_t label_style;
static bool style_initialized = false;
struct layer_status_state { struct layer_status_state {
uint8_t index; uint8_t index;
const char *label; const char *label;
}; };
static void layer_status_init() {
if (style_initialized) {
return;
}
style_initialized = true;
lv_style_init(&label_style);
lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_12);
lv_style_set_text_letter_space(&label_style, LV_STATE_DEFAULT, 1);
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1);
}
static void set_layer_symbol(lv_obj_t *label, struct layer_status_state state) { static void set_layer_symbol(lv_obj_t *label, struct layer_status_state state) {
if (state.label == NULL) { if (state.label == NULL) {
char text[6] = {}; char text[6] = {};
@ -70,9 +54,7 @@ ZMK_DISPLAY_WIDGET_LISTENER(widget_layer_status, struct layer_status_state, laye
ZMK_SUBSCRIPTION(widget_layer_status, zmk_layer_state_changed); ZMK_SUBSCRIPTION(widget_layer_status, zmk_layer_state_changed);
int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_t *parent) { int zmk_widget_layer_status_init(struct zmk_widget_layer_status *widget, lv_obj_t *parent) {
layer_status_init();
widget->obj = lv_label_create(parent, NULL); widget->obj = lv_label_create(parent, NULL);
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style);
lv_obj_set_size(widget->obj, 40, 15); lv_obj_set_size(widget->obj, 40, 15);

19
app/src/display/widgets/output_status.c

@ -21,9 +21,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/endpoints.h> #include <zmk/endpoints.h>
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
static lv_style_t label_style;
static bool style_initialized = false;
struct output_status_state { struct output_status_state {
enum zmk_endpoint selected_endpoint; enum zmk_endpoint selected_endpoint;
@ -32,19 +29,6 @@ struct output_status_state {
uint8_t active_profile_index; uint8_t active_profile_index;
}; };
static void output_status_init() {
if (style_initialized) {
return;
}
style_initialized = true;
lv_style_init(&label_style);
lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_16);
lv_style_set_text_letter_space(&label_style, LV_STATE_DEFAULT, 1);
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1);
}
static struct output_status_state get_state(const zmk_event_t *_eh) { static struct output_status_state get_state(const zmk_event_t *_eh) {
return (struct output_status_state){.selected_endpoint = zmk_endpoints_selected(), return (struct output_status_state){.selected_endpoint = zmk_endpoints_selected(),
.active_profile_connected = .active_profile_connected =
@ -97,10 +81,7 @@ ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed);
#endif #endif
int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent) { int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent) {
output_status_init();
widget->obj = lv_label_create(parent, NULL); widget->obj = lv_label_create(parent, NULL);
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style);
lv_obj_set_size(widget->obj, 40, 15); lv_obj_set_size(widget->obj, 40, 15);

19
app/src/display/widgets/wpm_status.c

@ -15,27 +15,11 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/wpm.h> #include <zmk/wpm.h>
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
static lv_style_t label_style;
static bool style_initialized = false;
struct wpm_status_state { struct wpm_status_state {
uint8_t wpm; uint8_t wpm;
}; };
void wpm_status_init() {
if (style_initialized) {
return;
}
style_initialized = true;
lv_style_init(&label_style);
lv_style_set_text_color(&label_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_text_font(&label_style, LV_STATE_DEFAULT, &lv_font_montserrat_12);
lv_style_set_text_letter_space(&label_style, LV_STATE_DEFAULT, 1);
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1);
}
struct wpm_status_state wpm_status_get_state(const zmk_event_t *eh) { struct wpm_status_state wpm_status_get_state(const zmk_event_t *eh) {
return (struct wpm_status_state){.wpm = zmk_wpm_get_state()}; return (struct wpm_status_state){.wpm = zmk_wpm_get_state()};
}; };
@ -59,10 +43,7 @@ ZMK_DISPLAY_WIDGET_LISTENER(widget_wpm_status, struct wpm_status_state, wpm_stat
ZMK_SUBSCRIPTION(widget_wpm_status, zmk_wpm_state_changed); ZMK_SUBSCRIPTION(widget_wpm_status, zmk_wpm_state_changed);
int zmk_widget_wpm_status_init(struct zmk_widget_wpm_status *widget, lv_obj_t *parent) { int zmk_widget_wpm_status_init(struct zmk_widget_wpm_status *widget, lv_obj_t *parent) {
wpm_status_init();
widget->obj = lv_label_create(parent, NULL); widget->obj = lv_label_create(parent, NULL);
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style);
lv_label_set_align(widget->obj, LV_LABEL_ALIGN_RIGHT); lv_label_set_align(widget->obj, LV_LABEL_ALIGN_RIGHT);
lv_obj_set_size(widget->obj, 40, 15); lv_obj_set_size(widget->obj, 40, 15);

Loading…
Cancel
Save