lvgl / lv_utils

Convert images or system fonts to C arrays. Written for LVGL embedded GUI library
https://littlevgl.com
54 stars 38 forks source link

font_conv_for_lists: List parameter specific utility #26

Closed seyyah closed 5 years ago

seyyah commented 5 years ago

This tool was created because it is difficult to do as described in "PR: Add list symbol example #25".

List parameter specific utility

Edit configs section in the font_conv_for_lists.php,

$unicodes = array(
  "THERMOMETER_EMPTY" => "f2cb",
  "TINT             " => "f043",
  "BALANCE_SCALE    " => "f24e",
  "BARS             " => "f0c9",
  "MICROCHIP        " => "f2db"
);

$height = 100;
$name = "font_symbol_extra_" . $height;
$font = "FontAwesome.ttf";
$uni_first = 61440;
$uni_last = 62190;
$bpp = 8;

$output_dir = "./output/";

Convert font to C file

php font_conv_for_lists.php

Copy the result C file (<OUTPUT_DIR>/<FILENAME>.c) into your LittlevGL project.

Usage

$ php font_conv_for_lists.php
[...]
USAGE

a. Define
#define LV_SYMBOL_THERMOMETER_EMPTY     "\xef\x8b\x8b"
#define LV_SYMBOL_TINT                  "\xef\x81\x83"
#define LV_SYMBOL_BALANCE_SCALE         "\xef\x89\x8e"
#define LV_SYMBOL_BARS                  "\xef\x83\x89"
#define LV_SYMBOL_MICROCHIP             "\xef\x8b\x9b"

b. Add font
lv_font_add(&font_symbol_extra_100, &lv_font_symbol_100);
static lv_style_t style;
lv_style_copy(&style, &lv_style_plain);
style.text.font = &lv_font_symbol_100;

c. Declare
LV_FONT_DECLARE(font_symbol_extra_100)

d. Use it;)
lv_obj_t * label = lv_label_create(scr, NULL);
lv_label_set_style(label, &style);
lv_label_set_text(label, LV_SYMBOL_THERMOMETER_EMPTY LV_SYMBOL_TINT              
  LV_SYMBOL_BALANCE_SCALE     LV_SYMBOL_BARS              LV_SYMBOL_MICROCHIP         );
kisvegabor commented 5 years ago

@seyyah If this utility was useful for you it might be useful for others too so I merged it. Thank you!

But note that we will have a new font converter in v6.0 and the current php converters will become obsolete. Although they won't be deleted because some people still might use v5.3.