First commit with working display

This commit is contained in:
Ricardo LAP
2026-09-13 20:50:51 +00:00
parent a83af259b3
commit c54c68c899
6690 changed files with 1093387 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
Line wrap, recoloring and scrolling
-----------------------------------
.. lv_example:: widgets/label/lv_example_label_1
:language: c
Text shadow
------------
.. lv_example:: widgets/label/lv_example_label_2
:language: c
Show LTR, RTL and Chinese texts
-------------------------------
.. lv_example:: widgets/label/lv_example_label_3
:language: c
Draw label with gradient color
------------------------------
.. lv_example:: widgets/label/lv_example_label_4
:language: c
Customize circular scrolling animation
--------------------------------------
.. lv_example:: widgets/label/lv_example_label_5
:language: c
Monospace font
--------------
.. lv_example:: widgets/label/lv_example_label_6
:language: c
Assign a translation tag to a label
-----------------------------------
.. lv_example:: widgets/label/lv_example_label_7
:language: c

View File

@@ -0,0 +1,25 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES
/**
* Show line wrap, re-color, line align and text scrolling.
*/
void lv_example_label_1(void)
{
lv_obj_t * label1 = lv_label_create(lv_screen_active());
lv_label_set_long_mode(label1, LV_LABEL_LONG_MODE_WRAP); /*Break the long lines*/
lv_label_set_recolor(label1, true); /*Enable re-coloring by commands in the text*/
lv_label_set_text(label1, "#0000ff Re-color# #ff00ff words# #ff0000 of a# label, align the lines to the center "
"and wrap long text automatically.");
lv_obj_set_width(label1, 150); /*Set smaller width to make the lines wrap*/
lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(label1, LV_ALIGN_CENTER, 0, -40);
lv_obj_t * label2 = lv_label_create(lv_screen_active());
lv_label_set_long_mode(label2, LV_LABEL_LONG_MODE_SCROLL_CIRCULAR); /*Circular scroll*/
lv_obj_set_width(label2, 150);
lv_label_set_text(label2, "It is a circularly scrolling text. ");
lv_obj_align(label2, LV_ALIGN_CENTER, 0, 40);
}
#endif

View File

@@ -0,0 +1,36 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES
/**
* Create a fake text shadow
*/
void lv_example_label_2(void)
{
/*Create a style for the shadow*/
static lv_style_t style_shadow;
lv_style_init(&style_shadow);
lv_style_set_text_opa(&style_shadow, LV_OPA_30);
lv_style_set_text_color(&style_shadow, lv_color_black());
/*Create a label for the shadow first (it's in the background)*/
lv_obj_t * shadow_label = lv_label_create(lv_screen_active());
lv_obj_add_style(shadow_label, &style_shadow, 0);
/*Create the main label*/
lv_obj_t * main_label = lv_label_create(lv_screen_active());
lv_label_set_text(main_label, "A simple method to create\n"
"shadows on a text.\n"
"It even works with\n\n"
"newlines and spaces.");
/*Set the same text for the shadow label*/
lv_label_set_text(shadow_label, lv_label_get_text(main_label));
/*Position the main label*/
lv_obj_align(main_label, LV_ALIGN_CENTER, 0, 0);
/*Shift the second label down and to the right by 2 pixel*/
lv_obj_align_to(shadow_label, main_label, LV_ALIGN_TOP_LEFT, 2, 2);
}
#endif

View File

@@ -0,0 +1,31 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES && LV_FONT_DEJAVU_16_PERSIAN_HEBREW && LV_FONT_SOURCE_HAN_SANS_SC_16_CJK && LV_USE_BIDI
/**
* Show mixed LTR, RTL and Chinese label
*/
void lv_example_label_3(void)
{
lv_obj_t * ltr_label = lv_label_create(lv_screen_active());
lv_label_set_text(ltr_label, "In modern terminology, a microcontroller is similar to a system on a chip (SoC).");
lv_obj_set_style_text_font(ltr_label, &lv_font_montserrat_16, 0);
lv_obj_set_width(ltr_label, 310);
lv_obj_align(ltr_label, LV_ALIGN_TOP_LEFT, 5, 5);
lv_obj_t * rtl_label = lv_label_create(lv_screen_active());
lv_label_set_text(rtl_label,
"מעבד, או בשמו המלא יחידת עיבוד מרכזית (באנגלית: CPU - Central Processing Unit).");
lv_obj_set_style_base_dir(rtl_label, LV_BASE_DIR_RTL, 0);
lv_obj_set_style_text_font(rtl_label, &lv_font_dejavu_16_persian_hebrew, 0);
lv_obj_set_width(rtl_label, 310);
lv_obj_align(rtl_label, LV_ALIGN_LEFT_MID, 5, 0);
lv_obj_t * cz_label = lv_label_create(lv_screen_active());
lv_label_set_text(cz_label,
"嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
lv_obj_set_style_text_font(cz_label, &lv_font_source_han_sans_sc_16_cjk, 0);
lv_obj_set_width(cz_label, 310);
lv_obj_align(cz_label, LV_ALIGN_BOTTOM_LEFT, 5, -5);
}
#endif

View File

@@ -0,0 +1,55 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_FONT_MONTSERRAT_24 && LV_USE_CANVAS && LV_BUILD_EXAMPLES && LV_DRAW_SW_COMPLEX
#define MASK_WIDTH 150
#define MASK_HEIGHT 60
static void generate_mask(lv_draw_buf_t * mask, int32_t w, int32_t h, const char * txt)
{
/*Create a "8 bit alpha" canvas and clear it*/
lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
lv_canvas_set_draw_buf(canvas, mask);
lv_canvas_fill_bg(canvas, lv_color_black(), LV_OPA_TRANSP);
lv_layer_t layer;
lv_canvas_init_layer(canvas, &layer);
/*Draw a label to the canvas. The result "image" will be used as mask*/
lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = lv_color_white();
label_dsc.align = LV_TEXT_ALIGN_CENTER;
label_dsc.text = txt;
label_dsc.font = &lv_font_montserrat_24;
lv_area_t a = {0, 0, w - 1, h - 1};
lv_draw_label(&layer, &label_dsc, &a);
lv_canvas_finish_layer(canvas, &layer);
lv_obj_delete(canvas);
}
/**
* Draw label with gradient color
*/
void lv_example_label_4(void)
{
/* Create the mask of a text by drawing it to a canvas*/
LV_DRAW_BUF_DEFINE_STATIC(mask, MASK_WIDTH, MASK_HEIGHT, LV_COLOR_FORMAT_L8);
LV_DRAW_BUF_INIT_STATIC(mask);
generate_mask(&mask, MASK_WIDTH, MASK_HEIGHT, "Text with gradient");
/* Create an object from where the text will be masked out.
* Now it's a rectangle with a gradient but it could be an image too*/
lv_obj_t * grad = lv_obj_create(lv_screen_active());
lv_obj_set_size(grad, MASK_WIDTH, MASK_HEIGHT);
lv_obj_center(grad);
lv_obj_set_style_bg_color(grad, lv_color_hex(0xff0000), 0);
lv_obj_set_style_bg_grad_color(grad, lv_color_hex(0x0000ff), 0);
lv_obj_set_style_bg_grad_dir(grad, LV_GRAD_DIR_HOR, 0);
lv_obj_set_style_bitmap_mask_src(grad, &mask, 0);
}
#endif

View File

@@ -0,0 +1,31 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES
/**
* Show customizing the circular scrolling animation of a label with `LV_LABEL_LONG_MODE_SCROLL_CIRCULAR`
* long mode.
*/
void lv_example_label_5(void)
{
static lv_anim_t animation_template;
static lv_style_t label_style;
lv_anim_init(&animation_template);
lv_anim_set_delay(&animation_template, 1000); /*Wait 1 second to start the first scroll*/
lv_anim_set_repeat_delay(&animation_template,
3000); /*Repeat the scroll 3 seconds after the label scrolls back to the initial position*/
lv_anim_set_repeat_count(&animation_template, LV_ANIM_REPEAT_INFINITE);
/*Initialize the label style with the animation template*/
lv_style_init(&label_style);
lv_style_set_anim(&label_style, &animation_template);
lv_obj_t * label1 = lv_label_create(lv_screen_active());
lv_label_set_long_mode(label1, LV_LABEL_LONG_MODE_SCROLL_CIRCULAR); /*Circular scroll*/
lv_obj_set_width(label1, 150);
lv_label_set_text(label1, "It is a circularly scrolling text. ");
lv_obj_align(label1, LV_ALIGN_CENTER, 0, 40);
lv_obj_add_style(label1, &label_style, LV_STATE_DEFAULT); /*Add the style to the label*/
}
#endif

View File

@@ -0,0 +1,35 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES && LV_FONT_MONTSERRAT_20
static bool fix_w_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t * dsc, uint32_t letter,
uint32_t letter_next)
{
bool ret = lv_font_get_glyph_dsc_fmt_txt(font, dsc, letter, letter_next);
if(!ret) return false;
/* Set a fixed width */
dsc->adv_w = 20;
dsc->ofs_x = (dsc->adv_w - dsc->box_w) / 2;
return true;
}
void lv_example_label_6(void)
{
/* Clone the original font and override its behavior */
static lv_font_t mono_font;
mono_font = lv_font_montserrat_20;
mono_font.get_glyph_dsc = fix_w_get_glyph_dsc;
/* Create a label with normal font */
lv_obj_t * label1 = lv_label_create(lv_screen_active());
lv_obj_set_style_text_font(label1, &lv_font_montserrat_20, 0);
lv_label_set_text(label1, "0123.Wabc");
/* Create a label with fixed-width glyph descriptor override */
lv_obj_t * label2 = lv_label_create(lv_screen_active());
lv_obj_set_y(label2, 30);
lv_obj_set_style_text_font(label2, &mono_font, 0);
lv_label_set_text(label2, "0123.Wabc");
}
#endif

View File

@@ -0,0 +1,60 @@
#include "../../lv_examples.h"
#if LV_USE_TRANSLATION && LV_USE_DROPDOWN && LV_USE_LABEL && LV_BUILD_EXAMPLES
/* Arrays are defined `const` to place them in program space instead of RAM. */
static const char * const tags[] = {"tiger", "lion", "rabbit", "elephant", NULL};
static const char * const languages[] = {"English", "Deutsch", "Español", NULL};
static void add_static_translations(void)
{
static const char * const translations[] = {
"The Tiger", "Der Tiger", "El Tigre",
"The Lion", "Der Löwe", "El León",
"The Rabbit", "Das Kaninchen", "El Conejo",
"The Elephant", "Der Elefant", "El Elefante",
};
lv_translation_add_static(languages, tags, translations);
}
static void language_change_cb(lv_event_t * e)
{
static char selected_lang[20];
lv_obj_t * dropdown = lv_event_get_target_obj(e);
lv_dropdown_get_selected_str(dropdown, selected_lang, sizeof(selected_lang));
lv_translation_set_language(selected_lang);
}
/**
* Use a translation tag in labels
*/
void lv_example_label_7(void)
{
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
add_static_translations();
const size_t tag_count = sizeof(tags) / sizeof(tags[0]) - 1;
const size_t lang_count = sizeof(languages) / sizeof(languages[0]) - 1;
/* Create a dropdown to be able to select the language */
lv_obj_t * language_dropdown = lv_dropdown_create(lv_screen_active());
lv_dropdown_clear_options(language_dropdown);
for(size_t i = 0; i < lang_count; ++i) {
lv_dropdown_add_option(language_dropdown, languages[i], i);
}
lv_obj_add_event_cb(language_dropdown, language_change_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_translation_set_language("English");
/* Create a label for each tag */
for(size_t i = 0; i < tag_count; ++i) {
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_translation_tag(label, tags[i]);
}
}
#endif /*LV_USE_TRANSLATION && LV_USE_DROPDOWN && LV_USE_LABEL && LV_BUILD_EXAMPLES*/