-
-
Notifications
You must be signed in to change notification settings - Fork 81
Add custom icon fonts to lvgl-module #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
67c6515
Add custom icon fonts to lvgl-module
KenVanHoeylandt b6f49c5
Launcher using font icon
KenVanHoeylandt ae6aef9
Cleanup filenames
KenVanHoeylandt 6f3c0f6
Icon updates
KenVanHoeylandt bd573a6
Update code generation script to download font
KenVanHoeylandt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *.ttf | ||
| *.codepoints |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| import os | ||
| import urllib.request | ||
|
|
||
| def download_file(url: str, filename: str): | ||
| if not os.path.exists(filename): | ||
| print(f"Downloading {filename} from {url}") | ||
| urllib.request.urlretrieve(url, filename) | ||
| else: | ||
| print(f"{filename} already exists, skipping download.") | ||
|
|
||
| def generate(bpp, size, font_file: str, symbols: list, output: str): | ||
| output_file_name = f"{output}_{size}.c" | ||
| output_path = os.path.join("..", "Source", "fonts", output_file_name) | ||
| print(f"Generating {output_file_name}") | ||
| cmd = "lv_font_conv --no-compress --no-prefilter --bpp {} --size {} --font {} -r {} --format lvgl -o {} --force-fast-kern-format".format(bpp, size, font_file, ",".join(symbols), output_path) | ||
| os.system(cmd) | ||
|
|
||
| def read_code_points_map(file_path: str): | ||
| codepoints = {} | ||
| with open(file_path, 'r') as f: | ||
| for line in f: | ||
| parts = line.strip().split() | ||
| if len(parts) >= 2: | ||
| name, cp = parts[0].lower(), parts[1] | ||
| codepoints[name] = cp | ||
| if len(codepoints) == 0: | ||
| raise ValueError(f"Code points map is empty or wasn't found at {file_path}") | ||
| return codepoints | ||
|
|
||
|
|
||
| def get_code_points(codepoints, names: list) -> list: | ||
| result = [] | ||
| for name in names: | ||
| safe_name = name.lower() | ||
| if not safe_name in codepoints: | ||
| raise ValueError(f"Code point '{safe_name}' not found in map") | ||
| result.append(f"0x{codepoints[safe_name].upper()}") | ||
| return result | ||
|
|
||
| def generate_icon_fonts(font_file, font_sizes, symbols, output): | ||
| for size in font_sizes: | ||
| generate(2, size, font_file, symbols, output) | ||
|
|
||
| def generate_icon_names(codepoint_map: dict, codepoint_names: list, filename: str): | ||
| print(f"Generating {filename}") | ||
| output_path = os.path.join("..", "Include", "tactility", filename) | ||
| with open(output_path, 'w') as f: | ||
| f.write("#pragma once\n\n") | ||
| for name in codepoint_names: | ||
| safe_name = name.lower() | ||
| if safe_name in codepoint_map: | ||
| hex_val = codepoint_map[safe_name] | ||
| # Convert hex to int | ||
| val = int(hex_val, 16) | ||
| # Convert to UTF-8 escaped string | ||
| utf8_bytes = chr(val).encode('utf-8') | ||
| escaped_str = "".join(f"\\x{b:02X}" for b in utf8_bytes) | ||
|
|
||
| f.write(f'#define LVGL_SYMBOL_{safe_name.upper()} "{escaped_str}"\n') | ||
| else: | ||
| print(f"Warning: {safe_name} not found in codepoint map") | ||
KenVanHoeylandt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # --------------- Symbol Fonts --------------- | ||
|
|
||
| shared_symbol_code_point_names = [ | ||
| "add", | ||
| "apps", | ||
| "area_chart", # System Info | ||
| "app_registration", # App Settings app | ||
| "calendar_month", | ||
| "cable", | ||
| "circle", | ||
| "close", | ||
| "cloud", # Web server | ||
| "check", | ||
| "delete", | ||
| "devices", # Developer app | ||
| "display_settings", # Display Settings app | ||
| "edit_note", | ||
| "electric_bolt", # Power (settings) app | ||
| "folder", | ||
| "deployed_code", # 3D cube | ||
| "download", | ||
| "forum", # Chat app | ||
| "gamepad", | ||
| "help", # Diceware help | ||
| "hub", # App Hub | ||
| "image", # Screenshot app | ||
| "keyboard_arrow_up", | ||
| "lightbulb", | ||
| "language", # Globe | ||
| "lists", # Chat app toolbar | ||
| "mail", | ||
| "menu", | ||
| "mop", | ||
| "more_vert", | ||
| "music_note", | ||
| "note_add", | ||
| "power_settings_new", # Power off for T-Lora Pager | ||
| "refresh", # e.g. App Hub reload button | ||
| "search", | ||
| "settings", | ||
| "toolbar", # Apps without custom icon | ||
| "navigation", # GPS (settings) app | ||
| "keyboard_alt", # Keyboard (settings) app | ||
| "usb", # Power (settings) app | ||
| "wifi", # WiFi (settings) app | ||
| ] | ||
|
|
||
| statusbar_symbol_code_point_names = [ | ||
| # Location tracking | ||
| "location_on", | ||
| # Development server | ||
| "cloud", | ||
| # SD Card | ||
| "sd_card", | ||
| "sd_card_alert", | ||
| # Wi-Fi | ||
| "signal_wifi_0_bar", | ||
| "network_wifi_1_bar", | ||
| "network_wifi_2_bar", | ||
| "network_wifi_3_bar", | ||
| "signal_wifi_4_bar", | ||
| "signal_wifi_off", | ||
| # Battery | ||
| "battery_android_frame_1", | ||
| "battery_android_frame_2", | ||
| "battery_android_frame_3", | ||
| "battery_android_frame_4", | ||
| "battery_android_frame_5", | ||
| "battery_android_frame_6", | ||
| "battery_android_frame_bolt" | ||
| ] | ||
|
|
||
| launcher_symbol_code_point_names = [ | ||
| "apps", | ||
| "folder", | ||
| "settings" | ||
| ] | ||
| shared_symbol_font_sizes = [ | ||
| 16 # Fits with montserrat 14 in lv_list as icon with text | ||
| ] | ||
|
|
||
| # Resolve file path relative to this script so it can be executed from any CWD | ||
| base_dir = os.path.dirname(__file__) | ||
| if base_dir: | ||
| os.chdir(base_dir) | ||
|
|
||
| codepoints_url = "https://github.com/google/material-design-icons/raw/refs/heads/master/variablefont/MaterialSymbolsRounded%5BFILL,GRAD,opsz,wght%5D.codepoints" | ||
| ttf_url = "https://github.com/google/material-design-icons/raw/refs/heads/master/variablefont/MaterialSymbolsRounded%5BFILL,GRAD,opsz,wght%5D.ttf" | ||
|
|
||
| codepoints_filename = "MaterialSymbolsRounded.codepoints" | ||
| ttf_filename = "MaterialSymbolsRounded.ttf" | ||
|
|
||
| download_file(codepoints_url, codepoints_filename) | ||
| download_file(ttf_url, ttf_filename) | ||
|
|
||
| codepoints_map_path = codepoints_filename | ||
| codepoints_map = read_code_points_map(codepoints_map_path) | ||
|
|
||
| # Shared symbols | ||
| shared_symbol_code_points = get_code_points(codepoints_map, shared_symbol_code_point_names) | ||
| generate_icon_fonts(ttf_filename, shared_symbol_font_sizes, shared_symbol_code_points, "material_symbols_shared") | ||
| generate_icon_names(codepoints_map, shared_symbol_code_point_names, "lvgl_symbols_shared.h") | ||
|
|
||
| # Statusbar symbols | ||
| statusbar_symbol_code_points = get_code_points(codepoints_map, statusbar_symbol_code_point_names) | ||
| generate_icon_fonts(ttf_filename, [20], statusbar_symbol_code_points, "material_symbols_statusbar") | ||
| generate_icon_names(codepoints_map, statusbar_symbol_code_point_names, "lvgl_symbols_statusbar.h") | ||
|
|
||
| # Launcher symbols | ||
| launcher_symbol_code_points = get_code_points(codepoints_map, launcher_symbol_code_point_names) | ||
| generate_icon_fonts(ttf_filename, [36], launcher_symbol_code_points, "material_symbols_launcher") | ||
| generate_icon_names(codepoints_map, launcher_symbol_code_point_names, "lvgl_symbols_launcher.h") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
|
|
||
| #include <lvgl.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| extern const lv_font_t material_symbols_statusbar_20; | ||
|
|
||
| extern const lv_font_t material_symbols_shared_16; | ||
|
|
||
| extern const lv_font_t material_symbols_launcher_36; | ||
|
|
||
| //#define lvgl_get_text_font_smaller() &lv_font_montserrat_12 | ||
| // TODO: Make function so it's easier to use this cross-platform | ||
| #define LVGL_TEXT_FONT_DEFAULT &lv_font_montserrat_14 | ||
| #define LVGL_TEXT_FONT_LARGER &lv_font_montserrat_18 | ||
|
|
||
| // TODO: Make function so it's easier to use this cross-platform | ||
| #define LVGL_SYMBOL_FONT_DEFAULT &material_symbols_shared_16 | ||
|
|
||
| #define LVGL_SYMBOL_FONT_LAUNCHER &material_symbols_launcher_36 | ||
|
|
||
| // TODO: Make function so it's easier to use this cross-platform | ||
| #define LVGL_TOPBAR_FONT &material_symbols_statusbar_20 | ||
| #define LVGL_TOPBAR_ICON_HEIGHT 20 | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Modules/lvgl-module/Include/tactility/lvgl_symbols_launcher.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #define LVGL_SYMBOL_APPS "\xEE\x97\x83" | ||
| #define LVGL_SYMBOL_FOLDER "\xEE\x8B\x87" | ||
| #define LVGL_SYMBOL_SETTINGS "\xEE\xA2\xB8" |
44 changes: 44 additions & 0 deletions
44
Modules/lvgl-module/Include/tactility/lvgl_symbols_shared.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #pragma once | ||
|
|
||
| #define LVGL_SYMBOL_ADD "\xEE\x85\x85" | ||
| #define LVGL_SYMBOL_APPS "\xEE\x97\x83" | ||
| #define LVGL_SYMBOL_AREA_CHART "\xEE\x9D\xB0" | ||
| #define LVGL_SYMBOL_APP_REGISTRATION "\xEE\xBD\x80" | ||
| #define LVGL_SYMBOL_CALENDAR_MONTH "\xEE\xAF\x8C" | ||
| #define LVGL_SYMBOL_CABLE "\xEE\xBF\xA6" | ||
| #define LVGL_SYMBOL_CIRCLE "\xEE\xBD\x8A" | ||
| #define LVGL_SYMBOL_CLOSE "\xEE\x97\x8D" | ||
| #define LVGL_SYMBOL_CLOUD "\xEF\x85\x9C" | ||
| #define LVGL_SYMBOL_CHECK "\xEE\x97\x8A" | ||
| #define LVGL_SYMBOL_DELETE "\xEE\xA4\xAE" | ||
| #define LVGL_SYMBOL_DEVICES "\xEE\x8C\xA6" | ||
| #define LVGL_SYMBOL_DISPLAY_SETTINGS "\xEE\xAE\x97" | ||
| #define LVGL_SYMBOL_EDIT_NOTE "\xEE\x9D\x85" | ||
| #define LVGL_SYMBOL_ELECTRIC_BOLT "\xEE\xB0\x9C" | ||
| #define LVGL_SYMBOL_FOLDER "\xEE\x8B\x87" | ||
| #define LVGL_SYMBOL_DEPLOYED_CODE "\xEF\x9C\xA0" | ||
| #define LVGL_SYMBOL_DOWNLOAD "\xEF\x82\x90" | ||
| #define LVGL_SYMBOL_FORUM "\xEE\xA2\xAF" | ||
| #define LVGL_SYMBOL_GAMEPAD "\xEE\x8C\x8F" | ||
| #define LVGL_SYMBOL_HELP "\xEE\xA3\xBD" | ||
| #define LVGL_SYMBOL_HUB "\xEE\xA7\xB4" | ||
| #define LVGL_SYMBOL_IMAGE "\xEE\x8F\xB4" | ||
| #define LVGL_SYMBOL_KEYBOARD_ARROW_UP "\xEE\x8C\x96" | ||
| #define LVGL_SYMBOL_LIGHTBULB "\xEE\xA4\x8F" | ||
| #define LVGL_SYMBOL_LANGUAGE "\xEE\xA2\x94" | ||
| #define LVGL_SYMBOL_LISTS "\xEE\xA6\xB9" | ||
| #define LVGL_SYMBOL_MAIL "\xEE\x85\x99" | ||
| #define LVGL_SYMBOL_MENU "\xEE\x97\x92" | ||
| #define LVGL_SYMBOL_MOP "\xEE\x8A\x8D" | ||
| #define LVGL_SYMBOL_MORE_VERT "\xEE\x97\x94" | ||
| #define LVGL_SYMBOL_MUSIC_NOTE "\xEE\x90\x85" | ||
| #define LVGL_SYMBOL_NOTE_ADD "\xEE\xA2\x9C" | ||
| #define LVGL_SYMBOL_POWER_SETTINGS_NEW "\xEF\xA3\x87" | ||
| #define LVGL_SYMBOL_REFRESH "\xEE\x97\x95" | ||
| #define LVGL_SYMBOL_SEARCH "\xEE\xA2\xB6" | ||
| #define LVGL_SYMBOL_SETTINGS "\xEE\xA2\xB8" | ||
| #define LVGL_SYMBOL_TOOLBAR "\xEE\xA7\xB7" | ||
| #define LVGL_SYMBOL_NAVIGATION "\xEE\x95\x9D" | ||
| #define LVGL_SYMBOL_KEYBOARD_ALT "\xEF\x80\xA8" | ||
| #define LVGL_SYMBOL_USB "\xEE\x87\xA0" | ||
| #define LVGL_SYMBOL_WIFI "\xEE\x98\xBE" |
19 changes: 19 additions & 0 deletions
19
Modules/lvgl-module/Include/tactility/lvgl_symbols_statusbar.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #pragma once | ||
|
|
||
| #define LVGL_SYMBOL_LOCATION_ON "\xEF\x87\x9B" | ||
| #define LVGL_SYMBOL_CLOUD "\xEF\x85\x9C" | ||
KenVanHoeylandt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #define LVGL_SYMBOL_SD_CARD "\xEE\x98\xA3" | ||
| #define LVGL_SYMBOL_SD_CARD_ALERT "\xEF\x81\x97" | ||
| #define LVGL_SYMBOL_SIGNAL_WIFI_0_BAR "\xEF\x82\xB0" | ||
| #define LVGL_SYMBOL_NETWORK_WIFI_1_BAR "\xEE\xAF\xA4" | ||
| #define LVGL_SYMBOL_NETWORK_WIFI_2_BAR "\xEE\xAF\x96" | ||
| #define LVGL_SYMBOL_NETWORK_WIFI_3_BAR "\xEE\xAF\xA1" | ||
| #define LVGL_SYMBOL_SIGNAL_WIFI_4_BAR "\xEF\x81\xA5" | ||
| #define LVGL_SYMBOL_SIGNAL_WIFI_OFF "\xEE\x87\x9A" | ||
| #define LVGL_SYMBOL_BATTERY_ANDROID_FRAME_1 "\xEF\x89\x97" | ||
| #define LVGL_SYMBOL_BATTERY_ANDROID_FRAME_2 "\xEF\x89\x96" | ||
| #define LVGL_SYMBOL_BATTERY_ANDROID_FRAME_3 "\xEF\x89\x95" | ||
| #define LVGL_SYMBOL_BATTERY_ANDROID_FRAME_4 "\xEF\x89\x94" | ||
| #define LVGL_SYMBOL_BATTERY_ANDROID_FRAME_5 "\xEF\x89\x93" | ||
| #define LVGL_SYMBOL_BATTERY_ANDROID_FRAME_6 "\xEF\x89\x92" | ||
| #define LVGL_SYMBOL_BATTERY_ANDROID_FRAME_BOLT "\xEF\x89\x90" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.