feat(xml): add test for a complex view
This commit is contained in:
@@ -15,6 +15,8 @@ void lv_example_xml_2(void)
|
||||
lv_xml_component_register_from_file("A:lvgl/examples/others/xml/my_button.xml");
|
||||
lv_xml_component_register_from_file("A:lvgl/examples/others/xml/view.xml");
|
||||
|
||||
lv_xml_register_font("lv_montserrat_18", &lv_font_montserrat_18);
|
||||
|
||||
lv_obj_t * obj = lv_xml_create(lv_screen_active(), "view", NULL);
|
||||
lv_obj_set_pos(obj, 10, 10);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ static void timer_cb(lv_timer_t * timer)
|
||||
lv_draw_letter_dsc_t letter_dsc;
|
||||
lv_draw_letter_dsc_init(&letter_dsc);
|
||||
letter_dsc.color = lv_color_hex(0xff0000);
|
||||
letter_dsc.font = lv_font_default();
|
||||
letter_dsc.font = lv_font_get_default();
|
||||
|
||||
{
|
||||
#define CURVE2_X(t) ((t) * 2 + lv_trigo_cos((t) * 5) * 40 / 32767 - 10)
|
||||
|
||||
@@ -19,7 +19,7 @@ static void timer_cb(lv_timer_t * timer)
|
||||
lv_draw_letter_dsc_t letter_dsc;
|
||||
lv_draw_letter_dsc_init(&letter_dsc);
|
||||
letter_dsc.color = lv_color_hex(0xff0000);
|
||||
letter_dsc.font = lv_font_default();
|
||||
letter_dsc.font = lv_font_get_default();
|
||||
|
||||
{
|
||||
#define CURVE2_X(t) (t * 2 + 10)
|
||||
|
||||
@@ -146,9 +146,10 @@ int32_t lv_font_get_line_height(const lv_font_t * font)
|
||||
return font->line_height;
|
||||
}
|
||||
|
||||
const lv_font_t * lv_font_default(void)
|
||||
|
||||
const lv_font_t * lv_font_get_default(void)
|
||||
{
|
||||
return LV_FONT_DEFAULT;
|
||||
return lv_font_default;
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -174,6 +174,12 @@ int32_t lv_font_get_line_height(const lv_font_t * font);
|
||||
*/
|
||||
void lv_font_set_kerning(lv_font_t * font, lv_font_kerning_t kerning);
|
||||
|
||||
/**
|
||||
* Get the default font, defined by LV_FONT_DEFAULT
|
||||
* @return return pointer to the default font
|
||||
*/
|
||||
const lv_font_t * lv_font_get_default(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -119,7 +119,7 @@ void lv_xml_table_cell_apply(lv_xml_parser_state_t * state, const char ** attrs)
|
||||
lv_strncpy(buf, value, sizeof(buf));
|
||||
char * buf_p = buf;
|
||||
const char * str;
|
||||
while((str = lv_xml_split_str(&buf_p, ' ')) != NULL) {
|
||||
while((str = lv_xml_split_str(&buf_p, '|')) != NULL) {
|
||||
ctrl |= table_ctrl_to_enum(str);
|
||||
}
|
||||
|
||||
|
||||
BIN
tests/ref_imgs/xml/view2.png
Normal file
BIN
tests/ref_imgs/xml/view2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
BIN
tests/ref_imgs_vg_lite/xml/view2.png
Normal file
BIN
tests/ref_imgs_vg_lite/xml/view2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
35
tests/src/test_assets/xml/view2.xml
Normal file
35
tests/src/test_assets/xml/view2.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<component>
|
||||
<consts>
|
||||
<color name="light_blue" value="0xbbbbff"/>
|
||||
<color name="dark_blue" value="0x000080"/>
|
||||
</consts>
|
||||
|
||||
<styles>
|
||||
<style name="red" text_color="0xff0000" text_opa="150"/>
|
||||
<style name="blue" text_color="#dark_blue" text_font="lv_montserrat_30"/>
|
||||
<style name="scale_main" bg_opa="50%" pad_all="32" radius="8"/>
|
||||
<style name="scale_indic" length="20" />
|
||||
<style name="scale_sectoion_indic" text_color="#00ff00" line_width="6"/>
|
||||
</styles>
|
||||
|
||||
<view width="700" height="470" style_bg_color="#light_blue" flex_flow="column_wrap">
|
||||
<lv_buttonmatrix map="'1' '2' '\n' '3'" ctrl_map="checked|width_3 none disabled" width="200"/>
|
||||
<lv_spangroup>
|
||||
<lv_spangroup-span text="hello" style="red"/>
|
||||
<lv_spangroup-span text="world" style="blue"/>
|
||||
</lv_spangroup>
|
||||
|
||||
<lv_scale total_tick_count="31" show_label="true" major_tick_every="6"
|
||||
range="10 110" width="300"
|
||||
styles="scale_main scale_indic:indicator">
|
||||
<lv_scale-section range="30 60" style_indicator="scale_sectoion_indic"/>
|
||||
</lv_scale>
|
||||
|
||||
<lv_table column_conunt="4" style_border_side:items="full">
|
||||
<lv_table-column column="1" width="30px"/>
|
||||
<lv_table-column column="3" width="20px"/>
|
||||
<lv_table-cell row="2" column="1" value="hello hello hello hello" ctrl="text_crop|merge_right"/>
|
||||
<lv_table-cell row="3" column="0" value="world"/>
|
||||
</lv_table>
|
||||
</view>
|
||||
</component>
|
||||
@@ -271,6 +271,9 @@ void test_xml_image_and_font(void)
|
||||
lv_xml_register_image("test_img1", &img_render_lvgl_logo_l8);
|
||||
lv_xml_register_image("test_img2", &img_render_lvgl_logo_rgb565);
|
||||
|
||||
lv_xml_register_font("lv_montserrat_16", &lv_font_montserrat_16);
|
||||
lv_xml_register_font("lv_montserrat_18", &lv_font_montserrat_18);
|
||||
|
||||
lv_xml_component_register_from_data("btn", btn_xml);
|
||||
|
||||
lv_obj_t * btn;
|
||||
|
||||
@@ -47,7 +47,7 @@ void test_xml_table_with_attrs(void)
|
||||
"row", "2",
|
||||
"column", "0",
|
||||
"value", "hello this a long text which should be cropped",
|
||||
"ctrl", "text_crop merge_right",
|
||||
"ctrl", "text_crop|merge_right",
|
||||
NULL, NULL,
|
||||
};
|
||||
|
||||
|
||||
113
tests/src/test_cases/xml/test_xml_view2.c
Normal file
113
tests/src/test_cases/xml/test_xml_view2.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#if LV_BUILD_TEST || 1
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
/* Function run before every test */
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
/* Function run after every test */
|
||||
lv_obj_clean(lv_screen_active());
|
||||
}
|
||||
|
||||
void test_xml_view2_from_xml(void)
|
||||
{
|
||||
lv_xml_register_font("lv_montserrat_30", &lv_font_montserrat_30);
|
||||
lv_xml_component_register_from_file("A:src/test_assets/xml/view2.xml");
|
||||
|
||||
lv_xml_create(lv_screen_active(), "view2", NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("xml/view2.png");
|
||||
}
|
||||
|
||||
#define LIGHT_BLUE lv_color_hex(0xbbbbff)
|
||||
#define DARK_BLUE lv_color_hex(0x000080)
|
||||
|
||||
void test_xml_view2_from_c(void)
|
||||
{
|
||||
static lv_style_t style_red;
|
||||
static lv_style_t style_blue;
|
||||
static lv_style_t style_scale_main;
|
||||
static lv_style_t style_scale_indic;
|
||||
static lv_style_t style_scale_section_indic;
|
||||
static bool style_inited = false;
|
||||
if(!style_inited) {
|
||||
|
||||
lv_style_init(&style_red);
|
||||
lv_style_set_text_color(&style_red, lv_color_hex(0xff0000));
|
||||
lv_style_set_text_opa(&style_red, 150);
|
||||
|
||||
lv_style_init(&style_blue);
|
||||
lv_style_set_text_color(&style_blue, DARK_BLUE);
|
||||
lv_style_set_text_font(&style_blue, &lv_font_montserrat_30);
|
||||
|
||||
lv_style_init(&style_scale_main);
|
||||
lv_style_set_bg_opa(&style_scale_main, 127); /*128 is alculated from bg_opa=50%*/
|
||||
lv_style_set_pad_all(&style_scale_main, 32);
|
||||
lv_style_set_radius(&style_scale_main, 8);
|
||||
|
||||
lv_style_init(&style_scale_indic);
|
||||
lv_style_set_length(&style_scale_indic, 20);
|
||||
|
||||
lv_style_init(&style_scale_section_indic);
|
||||
lv_style_set_text_color(&style_scale_section_indic, lv_color_hex(0x00ff00));
|
||||
lv_style_set_line_width(&style_scale_section_indic, 6);
|
||||
|
||||
style_inited = true;
|
||||
}
|
||||
|
||||
lv_obj_t * lv_obj_1 = lv_obj_create(lv_screen_active());
|
||||
lv_obj_set_width(lv_obj_1, 700);
|
||||
lv_obj_set_height(lv_obj_1, 470);
|
||||
lv_obj_set_style_bg_color(lv_obj_1, LIGHT_BLUE, 0);
|
||||
lv_obj_set_flex_flow(lv_obj_1, LV_FLEX_FLOW_COLUMN_WRAP);
|
||||
|
||||
lv_obj_t * lv_buttonmatrix_1 = lv_buttonmatrix_create(lv_obj_1);
|
||||
|
||||
static const char * lv_buttonmatrix_1_map[] = {"1", "2", "\n", "3", NULL};
|
||||
lv_buttonmatrix_set_map(lv_buttonmatrix_1, lv_buttonmatrix_1_map);
|
||||
|
||||
static const lv_buttonmatrix_ctrl_t lv_buttonmatrix_1_ctrl_map[] = {LV_BUTTONMATRIX_CTRL_CHECKED | LV_BUTTONMATRIX_CTRL_WIDTH_3, LV_BUTTONMATRIX_CTRL_NONE, LV_BUTTONMATRIX_CTRL_DISABLED};
|
||||
lv_buttonmatrix_set_ctrl_map(lv_buttonmatrix_1, lv_buttonmatrix_1_ctrl_map);
|
||||
|
||||
lv_obj_set_width(lv_buttonmatrix_1, 200);
|
||||
|
||||
lv_obj_t * lv_spangroup_1 = lv_spangroup_create(lv_obj_1);
|
||||
lv_span_t * lv_spangroup_1_span_1 = lv_spangroup_add_span(lv_spangroup_1);
|
||||
lv_spangroup_set_span_text(lv_spangroup_1, lv_spangroup_1_span_1, "hello");
|
||||
lv_spangroup_set_span_style(lv_spangroup_1, lv_spangroup_1_span_1, &style_red);
|
||||
|
||||
lv_span_t * lv_spangroup_1_span_2 = lv_spangroup_add_span(lv_spangroup_1);
|
||||
lv_spangroup_set_span_text(lv_spangroup_1, lv_spangroup_1_span_2, "world");
|
||||
lv_spangroup_set_span_style(lv_spangroup_1, lv_spangroup_1_span_2, &style_blue);
|
||||
|
||||
lv_obj_t * lv_scale_1 = lv_scale_create(lv_obj_1);
|
||||
lv_scale_set_total_tick_count(lv_scale_1, 31);
|
||||
lv_scale_set_label_show(lv_scale_1, true);
|
||||
lv_scale_set_major_tick_every(lv_scale_1, 6);
|
||||
lv_scale_set_range(lv_scale_1, 10, 110);
|
||||
lv_obj_set_width(lv_scale_1, 300);
|
||||
lv_obj_add_style(lv_scale_1, &style_scale_main, 0);
|
||||
lv_obj_add_style(lv_scale_1, &style_scale_indic, LV_PART_INDICATOR);
|
||||
|
||||
lv_scale_section_t * lv_scale_1_section_1 = lv_scale_add_section(lv_scale_1);
|
||||
lv_scale_set_section_range(lv_scale_1, lv_scale_1_section_1, 30, 60);
|
||||
lv_scale_set_section_style_indicator(lv_scale_1, lv_scale_1_section_1, &style_scale_section_indic);
|
||||
|
||||
lv_obj_t * lv_table_1 = lv_table_create(lv_obj_1);
|
||||
lv_table_set_column_count(lv_table_1, 4);
|
||||
lv_obj_set_style_border_side(lv_table_1, LV_BORDER_SIDE_FULL, LV_PART_ITEMS);
|
||||
lv_table_set_column_width(lv_table_1, 1, 30);
|
||||
lv_table_set_column_width(lv_table_1, 3, 20);
|
||||
lv_table_set_cell_value(lv_table_1, 2, 1, "hello hello hello hello");
|
||||
lv_table_set_cell_ctrl(lv_table_1, 2, 1, LV_TABLE_CELL_CTRL_TEXT_CROP | LV_TABLE_CELL_CTRL_MERGE_RIGHT);
|
||||
lv_table_set_cell_value(lv_table_1, 3, 0, "world");
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("xml/view2.png");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
<!--
|
||||
<lv_scale total_tick_count="30">
|
||||
<lv_scale-section column="2" range="30 40" style="indicator style1"/>
|
||||
<lv_scale-section column="2" range="30 40" style_indicator="scale_style"/>
|
||||
</lv_scale>
|
||||
-->
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!--
|
||||
<lv_table col_cnt="4">
|
||||
<lv_table column_conunt="4">
|
||||
<lv_table-column column="2" width="30px"/>
|
||||
<lv_table-cell row="2" column="1" value="hello" ctrl="text_crop merge_right"/>
|
||||
<lv_table-cell row="3" column="0" value="world"/>
|
||||
|
||||
Reference in New Issue
Block a user