Label
Wrapping and circular scrolling labels
Two labels share a width, one wraps with inline recolor and one scrolls in a loop.
The top label sets LV_LABEL_LONG_MODE_WRAP, enables recolor so #RRGGBB text#
markers change color per word, fixes the width to 150 px, and center-aligns text
with LV_TEXT_ALIGN_CENTER. The bottom label uses
LV_LABEL_LONG_MODE_SCROLL_CIRCULAR with the same width so its text cycles
through continuously.
Faux text shadow from two labels
Layer two labels with the same text to fake a drop shadow.
A background label receives a style that sets text_opa to LV_OPA_30 and a
black text_color, then the same text is placed on a foreground label centered
on the screen. The shadow label is aligned to the main label's top-left with a
2 px x/y offset via lv_obj_align_to.
LTR, RTL, and CJK labels
Three labels rendered with scripts that need different fonts and base directions.
An English label at the top-left uses lv_font_montserrat_16. A Hebrew label
in the middle sets base_dir to LV_BASE_DIR_RTL and renders with
lv_font_dejavu_16_persian_hebrew. A Simplified Chinese label at the
bottom-left renders with lv_font_source_han_sans_sc_16_cjk. All three wrap at
310 px.
Gradient-filled text via bitmap mask
Render text with a gradient fill by masking a gradient rectangle.
A canvas in LV_COLOR_FORMAT_L8 is used as an alpha mask: a centered label is
drawn onto it with lv_draw_label using lv_font_montserrat_24. A plain
object sized 150x60 is created, given a horizontal red-to-blue background
gradient with LV_GRAD_DIR_HOR, and the mask is applied through
lv_obj_set_style_bitmap_mask_src so only the text shape shows through.
Customized circular scroll timing
Set delays and infinite repeats on a label's circular scroll animation.
An lv_anim_t template is configured with a 1000 ms initial delay, a 3000 ms
repeat delay, and LV_ANIM_REPEAT_INFINITE. A style stores the template via
lv_style_set_anim and is attached to a 150 px wide label running in
LV_LABEL_LONG_MODE_SCROLL_CIRCULAR, which applies the timing whenever the
scroll animation fires.
Monospace font via glyph override
Clone a proportional font and force fixed advance width on each glyph.
A copy of lv_font_montserrat_20 is made and its get_glyph_dsc callback is
replaced with a helper that sets adv_w to 20 and recenters ofs_x for every
glyph. Two labels render the string 0123.Wabc: the first with the original
proportional font, the second with the patched monospace clone so column
alignment becomes visible.
Label translation tags with dropdown
Switch label text between English, German, and Spanish from a dropdown.
A static translation table keyed by the tags tiger, lion, rabbit, and
elephant is registered with lv_translation_add_static. A dropdown lists
the three languages and its LV_EVENT_VALUE_CHANGED handler calls
lv_translation_set_language with the selected string. One label per tag is
created with lv_label_set_translation_tag, and all labels refresh to the
chosen language.
How is this guide?
Last updated on