lvgl / lv_binding_rust

LVGL bindings for Rust. A powerful and easy-to-use embedded GUI with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash).
MIT License
668 stars 69 forks source link

How to use custom fonts #154

Closed enelson1001 closed 10 months ago

enelson1001 commented 10 months ago

I am trying to include a font that I created from https://lvgl.io/tools/fontconverter. I placed this converted tft to c file in my project directory under a directory called custom_fonts

esp-rust-projects/year2023/rust-lvgl-hello
├── build.rs
├── Cargo.lock
├── Cargo.toml
├── custom_fonts
│   └── gotham_bold_80.c
├── logs
│   ├── log_esp_idf_hal_objdump.txt
│   ├── log_lvgl_objdump.txt
│   ├── log.txt
│   └── objdump.txt
├── lvgl-configs
│   ├── lv_conf.h
│   ├── lv_drv_conf.h
│   └── lv_drv_conf old.h
├── rust-toolchain.toml
├── sdkconfig.defaults
├── src
│   └── main.rs

I also include the ENV variable LVGL_FONTS_DIR

export LVGL_FONTS_DIR="/home/ed/esp-rust-projects/year2023/rust-lvgl-hello/custom_fonts"

I try and use the following call to set_text_font but fails because gotham_bold_80 is not found in lvgl_sys. This makes sense because gotham_bold_80 is not included in lvgl_sys/fonts.

style_time.set_text_font(unsafe { Font::new_raw(lvgl_sys::gotham_bold_80) })

and the error

error[E0425]: cannot find value `gotham_bold_80` in crate `lvgl_sys`
   --> src/main.rs:136:71
    |
136 |             style_time.set_text_font(unsafe { Font::new_raw(lvgl_sys::gotham_bold_80) });
    |                                                                       ^^^^^^^^^^^^^^ not found in `lvgl_sys`

So what is the correct way to use my custom font?

enelson1001 commented 10 months ago

Solved Needed to create a header file for gotham_bold.c Used noto_sans_numeric_80.h as an example. So now custom_fonts includes gotham_bold_80.h file