2.4 KiB
.. include:: /header.rst
:github_url: |github_link_base|/widgets/span.md
Span (lv_span)
Overview
A spangroup is the object that is used to display rich text. Different from the label object, spangroup can automatically organize text of different fonts, colors, and sizes into the spangroup obj.
Parts and Styles
LV_PART_MAINThe spangroup has only one part.
Usage
Set text and style
The spangroup object uses span to describe text and text style. so, first we need to create span descriptor using lv_span_t * span = lv_spangroup_new_span(spangroup). Then use lv_span_set_text(span, "text") to set text.The style of the modified text is the same as the normal style used, eg:lv_style_set_text_color(&span->style, lv_palette_main(LV_PALETTE_RED)).
If spangroup object mode != LV_SPAN_MODE_FIXED you must call lv_spangroup_refr_mode() after you have modified span style(eg:set text, changed the font size, del span).
Text align
like label object, the spangroup can be set to one the following modes:
LV_TEXT_ALIGN_LEFTAlign text to left.LV_TEXT_ALIGN_CENTERAlign text to center.LV_TEXT_ALIGN_RIGHTAlign text to right.LV_TEXT_ALIGN_AUTOAlign text auto.
use function lv_spangroup_set_align(spangroup, LV_TEXT_ALIGN_CENTER) to set text align.
Modes
The spangroup can be set to one the following modes:
LV_SPAN_MODE_FIXEDfixes the object size.LV_SPAN_MODE_EXPANDExpand the object size to the text size but stay on a single line.LV_SPAN_MODE_BREAKKeep width, break the too long lines and auto expand height.
Use lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_BREAK) to set object mode.
Overflow
The spangroup can be set to one the following modes:
LV_SPAN_OVERFLOW_CLIPtruncates the text at the limit of the area.LV_SPAN_OVERFLOW_ELLIPSISwill display an ellipsis(...) when text overflows the area.
Use lv_spangroup_set_overflow(spangroup, LV_SPAN_OVERFLOW_CLIP) to set object overflow mode.
first line indent
Use lv_spangroup_set_indent(spangroup, 20) to set the indent of the first line, in pixels.
Events
No special events are sent by this widget.
Learn more about Events.
Keys
No Keys are processed by the object type.
Learn more about Keys.
Example
.. include:: ../../../examples/widgets/span/index.rst
API
.. doxygenfile:: lv_span.h
:project: lvgl