1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../../lvgl_private.h"
#include "unity/unity.h"
void setUp(void)
{
/* Function run before every test */
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_EVENLY);
}
void tearDown(void)
{
/* Function run after every test */
lv_obj_clean(lv_screen_active());
}
static lv_obj_t * label_create(const lv_font_t * font, lv_style_t * style, const char * text_base)
{
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text_fmt(label, "%s: the quick brown fox jumps over the lazy dog", text_base);
// lv_label_set_text_fmt(label, "l");
lv_obj_set_style_text_font(label, font, 0);
if(style) lv_obj_add_style(label, style, 0);
return label;
}
static void all_labels_create(const char * name, lv_style_t * style)
{
LV_FONT_DECLARE(test_font_montserrat_ascii_1bpp);
LV_FONT_DECLARE(test_font_montserrat_ascii_2bpp);
LV_FONT_DECLARE(test_font_montserrat_ascii_4bpp);
LV_FONT_DECLARE(test_font_montserrat_ascii_4bpp_compressed);
// LV_FONT_DECLARE(test_font_montserrat_ascii_4bpp_subpx);
label_create(&test_font_montserrat_ascii_1bpp, style, "1bpp font");
label_create(&test_font_montserrat_ascii_2bpp, style, "2bpp font");
label_create(&test_font_montserrat_ascii_4bpp, style, "4bpp font");
label_create(&test_font_montserrat_ascii_4bpp_compressed, style, "4bpp compressed font");
// label_create(&test_font_montserrat_ascii_4bpp_subpx, style, "4bpp subpx font");
char buf[64];
lv_snprintf(buf, sizeof(buf), "draw/label_%s.png", name);
TEST_ASSERT_EQUAL_SCREENSHOT(buf);
}
void test_draw_label_normal(void)
{
all_labels_create("normal", NULL);
}
void test_draw_label_color(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_RED));
all_labels_create("color", &style);
}
void test_draw_label_opa(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_RED));
all_labels_create("opa", &style);
}
void test_draw_label_color_and_opa(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_RED));
lv_style_set_text_opa(&style, LV_OPA_50);
all_labels_create("color_and_opa", &style);
}
static lv_obj_t * decor_label_create(lv_text_decor_t decor, lv_text_align_t align, lv_opa_t opa)
{
lv_color_t color = lv_palette_main(LV_PALETTE_BLUE);
lv_color_t sel_bg_color = lv_palette_lighten(LV_PALETTE_RED, 4);
lv_color_t sel_color = lv_palette_darken(LV_PALETTE_RED, 4);
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Hi,\nTesting the\nlabels.");
lv_obj_set_style_text_decor(label, decor, 0);
lv_obj_set_style_text_color(label, color, 0);
lv_obj_set_style_text_opa(label, opa, 0);
lv_obj_set_style_text_align(label, align, 0);
lv_obj_set_style_bg_color(label, sel_bg_color, LV_PART_SELECTED);
lv_obj_set_style_text_color(label, sel_color, LV_PART_SELECTED);
lv_label_set_text_selection_start(label, 10);
lv_label_set_text_selection_end(label, 19);
return label;
}
static void all_decor_labels_create(lv_text_decor_t decor)
{
lv_obj_t * label;
label = decor_label_create(decor, LV_TEXT_ALIGN_LEFT, LV_OPA_COVER);
lv_obj_add_flag(label, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
label = decor_label_create(decor, LV_TEXT_ALIGN_CENTER, LV_OPA_COVER);
label = decor_label_create(decor, LV_TEXT_ALIGN_RIGHT, LV_OPA_COVER);
label = decor_label_create(decor, LV_TEXT_ALIGN_LEFT, LV_OPA_50);
label = decor_label_create(decor, LV_TEXT_ALIGN_CENTER, LV_OPA_50);
label = decor_label_create(decor, LV_TEXT_ALIGN_RIGHT, LV_OPA_50);
}
void test_label_decor(void)
{
all_decor_labels_create(LV_TEXT_DECOR_NONE);
all_decor_labels_create(LV_TEXT_DECOR_UNDERLINE);
all_decor_labels_create(LV_TEXT_DECOR_STRIKETHROUGH);
all_decor_labels_create(LV_TEXT_DECOR_UNDERLINE | LV_TEXT_DECOR_STRIKETHROUGH);
TEST_ASSERT_EQUAL_SCREENSHOT("draw/label_decor.png");
}
#endif
|