fix(tiny_ttf): re-initialize cache contents when cleared (#4426)

This commit is contained in:
sirius506
2023-08-03 22:55:58 +09:00
committed by GitHub
parent 5d056ed2b9
commit af8c55724d
6 changed files with 93 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
Open a front with Tiny TTF from data array
Open a font with Tiny TTF from data array
------------------------------------------
.. lv_example:: libs/tiny_ttf/lv_example_tiny_ttf_1
@@ -11,3 +11,8 @@ Load a font with Tiny_TTF from file
.. lv_example:: libs/tiny_ttf/lv_example_tiny_ttf_2
:language: c
Change font size with Tiny_TTF
------------------------------
.. lv_example:: libs/tiny_ttf/lv_example_tiny_ttf_3
:language: c

View File

@@ -27,6 +27,7 @@ extern "C" {
**********************/
void lv_example_tiny_ttf_1(void);
void lv_example_tiny_ttf_2(void);
void lv_example_tiny_ttf_3(void);
/**********************
* MACROS

View File

@@ -1,17 +1,18 @@
#include "../../lv_examples.h"
#if LV_USE_TINY_TTF && LV_BUILD_EXAMPLES
#include "ubuntu_font.h"
/**
* Load a font with Tiny_TTF
*/
void lv_example_tiny_ttf_1(void)
{
extern const uint8_t ubuntu_font[];
extern const int ubuntu_font_size;
/*Create style with the new font*/
static lv_style_t style;
lv_style_init(&style);
lv_font_t * font = lv_tiny_ttf_create_data(ubuntu_font, sizeof(ubuntu_font), 30);
lv_font_t * font = lv_tiny_ttf_create_data(ubuntu_font, ubuntu_font_size, 30);
lv_style_set_text_font(&style, font);
lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);

View File

@@ -0,0 +1,73 @@
#include "../../lv_examples.h"
#if LV_USE_TINY_TTF && LV_BUILD_EXAMPLES && LV_USE_MSG
#define DISPLAY_TEXT "Hello World!"
#define MSG_NEW_SIZE 1
static void slider_event_cb(lv_event_t * e);
static void label_event_cb(lv_event_t * e);
/**
* Change font size with Tiny_TTF
*/
void lv_example_tiny_ttf_3(void)
{
extern const uint8_t ubuntu_font[];
extern const int ubuntu_font_size;
int lsize = 25;
/*Create style with the new font*/
static lv_style_t style;
lv_style_init(&style);
lv_font_t * font = lv_tiny_ttf_create_data(ubuntu_font, ubuntu_font_size, lsize);
lv_style_set_text_font(&style, font);
lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);
lv_obj_t * slider = lv_slider_create(lv_scr_act());
lv_obj_center(slider);
lv_slider_set_range(slider, 5, 50);
lv_slider_set_value(slider, lsize, LV_ANIM_OFF);
lv_obj_align(slider, LV_ALIGN_BOTTOM_MID, 0, -50);
lv_obj_t * slider_label = lv_label_create(lv_scr_act());
lv_label_set_text_fmt(slider_label, "%d", lsize);
lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_add_event(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, slider_label);
/*Create a label with the new style*/
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_obj_add_style(label, &style, 0);
lv_obj_add_event(label, label_event_cb, LV_EVENT_MSG_RECEIVED, font);
lv_obj_set_size(label, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_center(label);
lv_msg_subscribe_obj(MSG_NEW_SIZE, label, NULL);
lv_msg_send(MSG_NEW_SIZE, &lsize);
}
static void slider_event_cb(lv_event_t * e)
{
lv_obj_t * slider = lv_event_get_target(e);
lv_obj_t * label = lv_event_get_user_data(e);
int lsize;
lsize = (int)lv_slider_get_value(slider);
lv_label_set_text_fmt(label, "%d", lsize);
lv_msg_send(MSG_NEW_SIZE, &lsize);
}
static void label_event_cb(lv_event_t * e)
{
lv_obj_t * label = lv_event_get_target(e);
lv_font_t * font = lv_event_get_user_data(e);
lv_msg_t * m = lv_event_get_msg(e);
const int32_t * v = lv_msg_get_payload(m);
lv_tiny_ttf_set_size(font, *v);
lv_label_set_text(label, DISPLAY_TEXT);
}
#endif

View File

@@ -1,5 +1,6 @@
#ifndef UBUNTU_FONT_H
#define UBUNTU_FONT_H
#include "../../lv_examples.h"
#if LV_USE_TINY_TTF && LV_BUILD_EXAMPLES
const uint8_t ubuntu_font[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x10, 0x44, 0x53, 0x49, 0x47,
0x1b, 0x79, 0x61, 0x63, 0x00, 0x02, 0xd2, 0x78, 0x00, 0x00, 0x19, 0x30, 0x47, 0x53, 0x55, 0x42,
@@ -11965,4 +11966,6 @@ const uint8_t ubuntu_font[] = {
0x98, 0x63, 0x66, 0xc6, 0xac, 0xfa, 0xf6, 0x69, 0x22, 0x0c, 0x37, 0xe6, 0xa0, 0x60, 0xb8, 0xee,
0xbc, 0xe5, 0x4e, 0xcb, 0xb3, 0x5a, 0x00, 0x00
};
#endif
const int ubuntu_font_size = sizeof(ubuntu_font);
#endif