add some code
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
|
||||
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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,30 @@
|
||||
#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*/
|
||||
|
||||
/*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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user