Skip to content

Commit

Permalink
screen: Build icons from TTF
Browse files Browse the repository at this point in the history
  • Loading branch information
xingrz committed Feb 18, 2023
1 parent 9c1cbf8 commit 85184dc
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 143 deletions.
8 changes: 7 additions & 1 deletion config/boards/arm/hw75_dynamic/app/screen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ zephyr_library_include_directories(${APPLICATION_SOURCE_DIR}/include)

include(${ZMK_CONFIG}/cmake/ui_strings.cmake)

generate_ui_strings(icons.csv
OUTPUT_DEFS ICONS_SRC
OUTPUT_TEXT ICONS_TXT
UNICODE_HEX
)

generate_ui_strings(strings.csv
OUTPUT_DEFS STRINGS_SRC
OUTPUT_TEXT STRINGS_TXT
)

zephyr_library_sources(${STRINGS_SRC})
zephyr_library_sources(${ICONS_SRC} ${STRINGS_SRC})
zephyr_library_include_directories(${CMAKE_CURRENT_BINARY_DIR})

zephyr_library_sources(layer_status.c)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2022-2023 XiNGRZ
# SPDX-License-Identifier: MIT

add_subdirectory(mono_19)
add_subdirectory(zfull_9)

zephyr_library_sources(icons_19.c)
zephyr_compile_options(-DLV_LVGL_H_INCLUDE_SIMPLE)
128 changes: 0 additions & 128 deletions config/boards/arm/hw75_dynamic/app/screen/fonts/icons_19.c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2022-2023 XiNGRZ
# SPDX-License-Identifier: MIT

zephyr_library()

set(FONT_SRC icons.ttf)

set(FONT_NAME mono)
set(FONT_SIZE 19)

include(${ZMK_CONFIG}/cmake/font_subset.cmake)
font_subset(FONT_SUBSET_TTF ${FONT_SRC} ${ICONS_TXT})

include(${ZMK_CONFIG}/cmake/lv_font_conv.cmake)
lv_font_conv(FONT_C_SRCS ${FONT_SUBSET_TTF}
NAME ${FONT_NAME}
SIZE ${FONT_SIZE}
BPP 1
NO_PREFILTER
NO_KERNING
)

zephyr_library_sources(${FONT_C_SRCS})
zephyr_library_include_directories(${ZEPHYR_LVGL_MODULE_DIR})
zephyr_library_include_directories(${ZEPHYR_BASE}/lib/gui/lvgl)
Binary file not shown.
3 changes: 3 additions & 0 deletions config/boards/arm/hw75_dynamic/app/screen/icons.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ICON_VOL,f1ae
ICON_BRI,f198
ICON_SCR,f193
16 changes: 7 additions & 9 deletions config/boards/arm/hw75_dynamic/app/screen/layer_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/event_manager.h>
#include <zmk/events/layer_state_changed.h>

#include "icons.h"

#define DISPLAY_NODE DT_CHOSEN(zephyr_display)

#define SCREEN_W DT_PROP(DISPLAY_NODE, width)
Expand All @@ -29,17 +31,13 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#define LAYER_LABEL(node) COND_CODE_0(DT_NODE_HAS_PROP(node, label), (NULL), (DT_LABEL(node))),

LV_FONT_DECLARE(icons_19);
LV_FONT_DECLARE(mono_19);
LV_FONT_DECLARE(zfull_9);

#define UI_SYMBOL_VOLUME "\xEF\x80\xA8"
#define UI_SYMBOL_BRIGHTNESS "\xEF\x86\x85"
#define UI_SYMBOL_SCROLL "\xEF\x83\x9C"

static const char *layer_icons[KEYMAP_LAYERS_NUM] = {
UI_SYMBOL_VOLUME,
UI_SYMBOL_BRIGHTNESS,
UI_SYMBOL_SCROLL,
ICON_VOL,
ICON_BRI,
ICON_SCR,
};

static const char *layer_names[KEYMAP_LAYERS_NUM] = { DT_FOREACH_CHILD(KEYMAP_NODE, LAYER_LABEL) };
Expand Down Expand Up @@ -111,7 +109,7 @@ int layer_status_init(lv_obj_t *parent, lv_group_t *group)
lv_style_set_text_color(&st_item, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_bg_color(&st_item, LV_STATE_FOCUSED, LV_COLOR_BLACK);
lv_style_set_text_color(&st_item, LV_STATE_FOCUSED, LV_COLOR_WHITE);
lv_style_set_text_font(&st_item, LV_STATE_DEFAULT, &icons_19);
lv_style_set_text_font(&st_item, LV_STATE_DEFAULT, &mono_19);

lv_obj_t *cont = lv_cont_create(parent, NULL);
lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_MID);
Expand Down
9 changes: 8 additions & 1 deletion config/cmake/ui_strings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: MIT

function(GENERATE_UI_STRINGS INPUT)
set(options)
set(options UNICODE_HEX)
set(one_value_keywords OUTPUT_DEFS OUTPUT_TEXT)
set(multi_value_keywords)
cmake_parse_arguments(UI_STRINGS
Expand All @@ -19,12 +19,19 @@ function(GENERATE_UI_STRINGS INPUT)
set(DEFS_FILE ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h)
set(TEXT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.txt)

set(OPTS)

if(UI_STRINGS_UNICODE_HEX)
list(APPEND OPTS "--unicode-hex")
endif()

add_custom_command(
OUTPUT ${DEFS_FILE} ${TEXT_FILE}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ui_strings.py
ARGS --input ${INPUT}
--output-defs ${DEFS_FILE}
--output-text ${TEXT_FILE}
${OPTS}
DEPENDS ${INPUT}
COMMENT "Generating UI strings: ${NAME}.h, ${NAME}.txt"
)
Expand Down
12 changes: 9 additions & 3 deletions config/cmake/ui_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ def main():
parser.add_argument('--input', type=str, required=True)
parser.add_argument('--output-defs', type=str, required=True)
parser.add_argument('--output-text', type=str, required=True)
parser.add_argument('--unicode-hex', action='store_true', required=False)
args = parser.parse_args()

with open(args.input, 'r') as f_in, open(args.output_defs, 'w') as f_od, open(args.output_text, 'w') as f_ot:
reader = csv.reader(f_in)
for row in reader:
key, value = row
text = value.strip().replace('\\n', '')
f_od.write(f'#define {key} "{value}"\n')
f_ot.write(f'{text}\n')
if args.unicode_hex:
text = chr(int(value, 16))
f_od.write(f'#define {key} "\\u{value}"\n')
f_ot.write(f'{text}\n')
else:
text = value.strip().replace('\\n', '')
f_od.write(f'#define {key} "{value}"\n')
f_ot.write(f'{text}\n')

if __name__ == '__main__':
main()

0 comments on commit 85184dc

Please sign in to comment.