feat(xml): add support scale, span, roller and bar

Also add some backward compatible API changes
This commit is contained in:
Gabor Kiss-Vamosi
2025-01-22 05:16:00 +08:00
parent b78a9b447a
commit a535063308
56 changed files with 1328 additions and 288 deletions

View File

@@ -283,9 +283,9 @@ static void create_widget1(lv_demo_high_res_ctx_t * c, lv_obj_t * widgets)
lv_obj_t * total_spent_span = lv_spangroup_create(spent_box);
lv_obj_add_style(total_spent_span, &c->fonts[FONT_LABEL_XS], 0);
lv_obj_add_style(total_spent_span, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0);
lv_span_t * total_spent_amount = lv_spangroup_new_span(total_spent_span);
lv_span_t * total_spent_amount = lv_spangroup_add_span(total_spent_span);
anim_state->spent_span_small = total_spent_amount;
lv_span_t * total_spent_label = lv_spangroup_new_span(total_spent_span);
lv_span_t * total_spent_label = lv_spangroup_add_span(total_spent_span);
lv_span_set_text_static(total_spent_label, "Total spent");
lv_style_set_text_opa(&total_spent_label->style, LV_OPA_40);
@@ -313,9 +313,9 @@ static void create_widget1(lv_demo_high_res_ctx_t * c, lv_obj_t * widgets)
lv_obj_t * gas_equivalent_span = lv_spangroup_create(spent_box);
lv_obj_add_style(gas_equivalent_span, &c->fonts[FONT_LABEL_XS], 0);
lv_obj_add_style(gas_equivalent_span, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0);
lv_span_t * gas_equivalent_amount = lv_spangroup_new_span(gas_equivalent_span);
lv_span_t * gas_equivalent_amount = lv_spangroup_add_span(gas_equivalent_span);
lv_span_set_text_static(gas_equivalent_amount, "$340 - ");
lv_span_t * gas_equivalent_label = lv_spangroup_new_span(gas_equivalent_span);
lv_span_t * gas_equivalent_label = lv_spangroup_add_span(gas_equivalent_span);
lv_span_set_text_static(gas_equivalent_label, "Gas Equivalent");
lv_style_set_text_opa(&gas_equivalent_label->style, LV_OPA_40);
}

View File

@@ -91,16 +91,16 @@ void lv_demo_high_res_home(lv_obj_t * base_obj)
lv_obj_t * date = lv_spangroup_create(date_and_time);
lv_obj_add_style(date, &c->fonts[FONT_HEADING_MD], 0);
lv_obj_add_style(date, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0);
lv_spangroup_new_span(date);
lv_span_t * day_and_month = lv_spangroup_new_span(date);
lv_spangroup_add_span(date);
lv_span_t * day_and_month = lv_spangroup_add_span(date);
lv_subject_add_observer_obj(&c->th, theme_observer_accent_span_cb, date, day_and_month);
lv_subject_add_observer_obj(&c->subject_groups.date.group, date_observer_cb, date, c);
lv_obj_t * time = lv_spangroup_create(date_and_time);
lv_obj_add_style(time, &c->fonts[FONT_HEADING_XXL], 0);
lv_obj_add_style(time, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0);
lv_spangroup_new_span(time);
lv_span_t * minute = lv_spangroup_new_span(time);
lv_spangroup_add_span(time);
lv_span_t * minute = lv_spangroup_add_span(time);
lv_subject_add_observer_obj(&c->th, theme_observer_accent_span_cb, time, minute);
lv_subject_add_observer_obj(&c->subject_groups.time.group, time_observer_cb, time, c);

View File

@@ -829,21 +829,16 @@ static void analytics_create(lv_obj_t * parent)
lv_scale_section_t * section;
section = lv_scale_add_section(scale3);
lv_scale_section_set_range(section, 0, 20);
lv_scale_section_set_style(section, LV_PART_MAIN, &scale3_section1_main_style);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &scale3_section1_indicator_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &scale3_section1_tick_style);
section = lv_scale_add_section(scale3);
lv_scale_section_set_range(section, 20, 40);
lv_scale_section_set_style(section, LV_PART_MAIN, &scale3_section2_main_style);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &scale3_section2_indicator_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &scale3_section2_tick_style);
lv_scale_set_section_range(scale3, section, 0, 20);
lv_scale_set_section_style_main(scale3, section, &scale3_section2_main_style);
lv_scale_set_section_style_indicator(scale3, section, &scale3_section2_indicator_style);
lv_scale_set_section_style_items(scale3, section, &scale3_section2_tick_style);
section = lv_scale_add_section(scale3);
lv_scale_section_set_range(section, 40, 60);
lv_scale_section_set_style(section, LV_PART_MAIN, &scale3_section3_main_style);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &scale3_section3_indicator_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &scale3_section3_tick_style);
lv_scale_set_section_range(scale3, section, 40, 60);
lv_scale_set_section_style_main(scale3, section, &scale3_section3_main_style);
lv_scale_set_section_style_indicator(scale3, section, &scale3_section3_indicator_style);
lv_scale_set_section_style_items(scale3, section, &scale3_section3_tick_style);
LV_IMAGE_DECLARE(img_demo_widgets_needle);
scale3_needle = lv_image_create(scale3);

View File

@@ -1,24 +1,17 @@
<component>
<consts>
<color name="light_blue" value="0xbbbbff"/>
<color name="dark_blue" value="0x000080"/>
<color name="dark_blue" value="0x44F"/>
</consts>
<styles>
<style name="btn_style" bg_color="#dark_blue" bg_opa="150"/>
<style name="btn_pr_style" bg_opa="255"/>
<style name="red" bg_color="0x007" bg_opa="150"
text_color="0xf00" text_letter_space="10"/>
<style name="blue" bg_color="bbf"
text_color="0x008" text_font="lv_montserrat_48"/>
</styles>
<view extends="lv_obj" width="280" height="content" style_bg_color="#light_blue">
<my_card title="Card 1"
y="0"
btn_rel_style="btn_style"
btn_pr_style="btn_pr_style"/>
<my_card y="85"
bg_color="0xffaaaa"
action="Apply"
btn_rel_style="btn_style"
btn_pr_style="btn_pr_style"/>
<view extends="lv_obj" width="280" height="240" style_bg_color="#light_blue">
<lv_roller options="'a&0x30;b\nc\nd' infinite" selected="2 true" visible_row_count="3"/>
</view>
</component>

View File

@@ -74,10 +74,11 @@ void lv_example_scale_2(void)
/* Configure section styles */
lv_scale_section_t * section = lv_scale_add_section(scale);
lv_scale_section_set_range(section, 75, 100);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style);
lv_scale_set_section_range(scale, section, 75, 100);
lv_scale_set_section_style_indicator(scale, section, &section_label_style);
lv_scale_set_section_style_items(scale, section, &section_minor_tick_style);
lv_scale_set_section_style_main(scale, section, &section_main_line_style);
lv_obj_set_style_bg_color(scale, lv_palette_main(LV_PALETTE_BLUE_GREY), 0);
lv_obj_set_style_bg_opa(scale, LV_OPA_50, 0);

View File

@@ -74,10 +74,11 @@ void lv_example_scale_4(void)
/* Configure section styles */
lv_scale_section_t * section = lv_scale_add_section(scale);
lv_scale_section_set_range(section, 75, 100);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style);
lv_scale_set_section_range(scale, section, 75, 100);
lv_scale_set_section_style_indicator(scale, section, &section_label_style);
lv_scale_set_section_style_items(scale, section, &section_minor_tick_style);
lv_scale_set_section_style_main(scale, section, &section_main_line_style);
}
#endif

View File

@@ -70,9 +70,9 @@ void lv_example_scale_5(void)
/* Configure section styles */
lv_scale_section_t * section = lv_scale_add_section(scale);
lv_scale_section_set_range(section, 25, 30);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_set_section_range(scale, section, 25, 30);
lv_scale_set_section_style_indicator(scale, section, &section_label_style);
lv_scale_set_section_style_items(scale, section, &section_minor_tick_style);
}
#endif

View File

@@ -20,7 +20,7 @@ void lv_example_slider_3(void)
lv_slider_set_mode(slider, LV_SLIDER_MODE_RANGE);
lv_slider_set_range(slider, MIN_VALUE, MAX_VALUE);
lv_slider_set_value(slider, 70, LV_ANIM_OFF);
lv_slider_set_left_value(slider, 20, LV_ANIM_OFF);
lv_slider_set_start_value(slider, 20, LV_ANIM_OFF);
lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_ALL, NULL);
lv_obj_refresh_ext_draw_size(slider);

View File

@@ -35,24 +35,24 @@ void lv_example_span_1(void)
lv_spangroup_set_indent(spans, 20);
lv_spangroup_set_mode(spans, LV_SPAN_MODE_BREAK);
lv_span_t * span = lv_spangroup_new_span(spans);
lv_span_t * span = lv_spangroup_add_span(spans);
lv_span_set_text(span, "China is a beautiful country.");
lv_style_set_text_color(lv_span_get_style(span), lv_palette_main(LV_PALETTE_RED));
lv_style_set_text_decor(lv_span_get_style(span), LV_TEXT_DECOR_UNDERLINE);
lv_style_set_text_opa(lv_span_get_style(span), LV_OPA_50);
span = lv_spangroup_new_span(spans);
span = lv_spangroup_add_span(spans);
lv_span_set_text_static(span, "good good study, day day up.");
#if LV_FONT_MONTSERRAT_24
lv_style_set_text_font(lv_span_get_style(span), &lv_font_montserrat_24);
#endif
lv_style_set_text_color(lv_span_get_style(span), lv_palette_main(LV_PALETTE_GREEN));
span = lv_spangroup_new_span(spans);
span = lv_spangroup_add_span(spans);
lv_span_set_text_static(span, "LVGL is an open-source graphics library.");
lv_style_set_text_color(lv_span_get_style(span), lv_palette_main(LV_PALETTE_BLUE));
span = lv_spangroup_new_span(spans);
span = lv_spangroup_add_span(spans);
lv_span_set_text_static(span, "the boy no name.");
lv_style_set_text_color(lv_span_get_style(span), lv_palette_main(LV_PALETTE_GREEN));
#if LV_FONT_MONTSERRAT_20
@@ -60,11 +60,11 @@ void lv_example_span_1(void)
#endif
lv_style_set_text_decor(lv_span_get_style(span), LV_TEXT_DECOR_UNDERLINE);
span = lv_spangroup_new_span(spans);
span = lv_spangroup_add_span(spans);
lv_span_set_text(span, "I have a dream that hope to come true.");
lv_style_set_text_decor(lv_span_get_style(span), LV_TEXT_DECOR_STRIKETHROUGH);
lv_spangroup_refr_mode(spans);
lv_spangroup_refresh(spans);
lv_obj_add_event_cb(spans, click_event_cb, LV_EVENT_CLICKED, NULL);
}

View File

@@ -106,14 +106,14 @@ extern "C" {
#define lv_anim_set_playback_delay lv_anim_set_reverse_delay
#define lv_anim_set_playback_duration lv_anim_set_reverse_duration
/**********************
* DEPRECATED FUNCTIONS
**********************/
#define lv_anim_set_time lv_anim_set_duration
#define lv_anim_set_playback_time lv_anim_set_reverse_duration
#define lv_spangroup_new_span lv_spangroup_add_span
#define lv_spangroup_refr_mode lv_spangroup_refresh
#define lv_slider_set_left_value lv_slider_set_start_value
#ifdef __cplusplus
} /*extern "C"*/
#endif

View File

@@ -198,6 +198,36 @@ void lv_style_reset(lv_style_t * style)
#endif
}
void lv_style_copy(lv_style_t * dst, const lv_style_t * src)
{
if(lv_style_is_const(dst)) {
LV_LOG_WARN("The destination can not be a constant style");
return;
}
lv_style_reset(dst);
/*Source is empty*/
if(src->values_and_props == NULL) return;
if(src->prop_cnt == 0) return;
int32_t i;
if(lv_style_is_const(src)) {
lv_style_const_prop_t * props_and_values = (lv_style_const_prop_t *)src->values_and_props;
for(i = 0; props_and_values[i].prop != LV_STYLE_PROP_INV; i++) {
lv_style_set_prop(dst, props_and_values[i].prop, props_and_values[i].value);
}
}
else {
lv_style_prop_t * props = (lv_style_prop_t *)src->values_and_props + src->prop_cnt * sizeof(lv_style_value_t);
lv_style_value_t * values = (lv_style_value_t *)src->values_and_props;
for(i = 0; i < src->prop_cnt; i++) {
lv_style_set_prop(dst, props[i], values[i]);
}
}
}
lv_style_prop_t lv_style_register_prop(uint8_t flag)
{
if(lv_style_custom_prop_flag_lookup_table == NULL) {

View File

@@ -398,6 +398,20 @@ void lv_style_init(lv_style_t * style);
*/
void lv_style_reset(lv_style_t * style);
/**
* Copy all properties of a style to an other.
* It has the same affect callying the same `lv_set_style_...`
* functions on both styles.
* It means new memory will be allocated to store the properties in
* the destination style.
* After the copy the destination style is fully independent of the source
* and source can removed without affecting the destination style.
* @param dst the destination to copy into (can not the a constant style)
* @param src the source style to copy from.
*/
void lv_style_copy(lv_style_t * dst, const lv_style_t * src);
/**
* Check if a style is constant
* @param style pointer to a style
@@ -409,6 +423,7 @@ static inline bool lv_style_is_const(const lv_style_t * style)
return false;
}
/**
* Register a new style property for custom usage
* @return a new property ID, or LV_STYLE_PROP_INV if there are no more available.

View File

@@ -23,11 +23,15 @@
#include "parsers/lv_xml_button_parser.h"
#include "parsers/lv_xml_label_parser.h"
#include "parsers/lv_xml_image_parser.h"
#include "parsers/lv_xml_bar_parser.h"
#include "parsers/lv_xml_slider_parser.h"
#include "parsers/lv_xml_tabview_parser.h"
#include "parsers/lv_xml_chart_parser.h"
#include "parsers/lv_xml_table_parser.h"
#include "parsers/lv_xml_dropdown_parser.h"
#include "parsers/lv_xml_roller_parser.h"
#include "parsers/lv_xml_scale_parser.h"
#include "parsers/lv_xml_spangroup_parser.h"
#include "../../libs/expat/expat.h"
#include "../../draw/lv_draw_image.h"
@@ -73,6 +77,7 @@ void lv_xml_init(void)
lv_xml_widget_register("lv_button", lv_xml_button_create, lv_xml_button_apply);
lv_xml_widget_register("lv_label", lv_xml_label_create, lv_xml_label_apply);
lv_xml_widget_register("lv_image", lv_xml_image_create, lv_xml_image_apply);
lv_xml_widget_register("lv_bar", lv_xml_bar_create, lv_xml_bar_apply);
lv_xml_widget_register("lv_slider", lv_xml_slider_create, lv_xml_slider_apply);
lv_xml_widget_register("lv_tabview", lv_xml_tabview_create, lv_xml_tabview_apply);
lv_xml_widget_register("lv_tabview-tab_bar", lv_xml_tabview_tab_bar_create, lv_xml_tabview_tab_bar_apply);
@@ -86,6 +91,11 @@ void lv_xml_init(void)
lv_xml_widget_register("lv_table-cell", lv_xml_table_cell_create, lv_xml_table_cell_apply);
lv_xml_widget_register("lv_dropdown", lv_xml_dropdown_create, lv_xml_dropdown_apply);
lv_xml_widget_register("lv_dropdown-list", lv_xml_dropdown_list_create, lv_xml_dropdown_list_apply);
lv_xml_widget_register("lv_roller", lv_xml_roller_create, lv_xml_roller_apply);
lv_xml_widget_register("lv_scale", lv_xml_scale_create, lv_xml_scale_apply);
lv_xml_widget_register("lv_scale-section", lv_xml_scale_section_create, lv_xml_scale_section_apply);
lv_xml_widget_register("lv_spangroup", lv_xml_spangroup_create, lv_xml_spangroup_apply);
lv_xml_widget_register("lv_spangroup-span", lv_xml_spangroup_span_create, lv_xml_spangroup_span_apply);
}
void * lv_xml_create_from_ctx(lv_obj_t * parent, lv_xml_component_ctx_t * parent_ctx, lv_xml_component_ctx_t * ctx,
@@ -356,7 +366,7 @@ static void view_start_element_handler(void * user_data, const char * name, cons
/* If it isn't a component either then it is unknown */
if(item == NULL) {
LV_LOG_WARN("'%s' in not a known widget, element, or component", name);
LV_LOG_WARN("'%s' is not a known widget, element, or component", name);
return;
}

View File

@@ -54,7 +54,10 @@ const char * lv_xml_get_value_of(const char ** attrs, const char * name)
lv_color_t lv_xml_to_color(const char * str)
{
return lv_color_hex(lv_xml_strtol(str, NULL, 16));
/*fff, #fff, 0xfff*/
if(lv_strlen(str) <= 5) return lv_color_hex3(lv_xml_strtol(str, NULL, 16));
/*ffffff, #ffffff, 0xffffff*/
else return lv_color_hex(lv_xml_strtol(str, NULL, 16));
}
lv_opa_t lv_xml_to_opa(const char * str)

View File

@@ -0,0 +1,111 @@
/**
* @file lv_xml_bar_parser.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_xml_bar_parser.h"
#if LV_USE_XML
#include "../../../lvgl.h"
#include "../../../lvgl_private.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_bar_orientation_t orentation_text_to_enum_value(const char * txt);
static lv_bar_mode_t mode_text_to_enum_value(const char * txt);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void * lv_xml_bar_create(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(attrs);
void * item = lv_bar_create(lv_xml_state_get_parent(state));
return item;
}
void lv_xml_bar_apply(lv_xml_parser_state_t * state, const char ** attrs)
{
void * item = lv_xml_state_get_item(state);
lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("value", name)) {
char buf[64];
lv_strlcpy(buf, value, sizeof(buf));
char * buf_p = buf;
int32_t v1 = lv_xml_atoi(lv_xml_split_str(&buf_p, ' '));
bool v2 = lv_xml_to_bool(buf_p);
lv_bar_set_value(item, v1, v2);
}
if(lv_streq("start_value", name)) {
char buf[64];
lv_strlcpy(buf, value, sizeof(buf));
char * buf_p = buf;
int32_t v1 = lv_xml_atoi(lv_xml_split_str(&buf_p, ' '));
bool v2 = lv_xml_to_bool(buf_p);
lv_bar_set_start_value(item, v1, v2);
}
if(lv_streq("orientation", name)) lv_bar_set_orientation(item, orentation_text_to_enum_value(value));
if(lv_streq("mode", name)) lv_bar_set_mode(item, mode_text_to_enum_value(value));
if(lv_streq("range", name)) {
char buf[64];
lv_strlcpy(buf, value, sizeof(buf));
char * buf_p = buf;
int32_t v1 = lv_xml_atoi(lv_xml_split_str(&buf_p, ' '));
int32_t v2 = lv_xml_atoi(buf_p);
lv_bar_set_range(item, v1, v2);
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
static lv_bar_orientation_t orentation_text_to_enum_value(const char * txt)
{
if(lv_streq("auto", txt)) return LV_BAR_ORIENTATION_AUTO;
if(lv_streq("horizontal", txt)) return LV_BAR_ORIENTATION_HORIZONTAL;
if(lv_streq("vertical", txt)) return LV_BAR_ORIENTATION_VERTICAL;
LV_LOG_WARN("%s is an unknown value for bar's orientation", txt);
return 0; /*Return 0 in lack of a better option. */
}
static lv_bar_mode_t mode_text_to_enum_value(const char * txt)
{
if(lv_streq("normal", txt)) return LV_BAR_MODE_NORMAL;
if(lv_streq("range", txt)) return LV_BAR_MODE_RANGE;
if(lv_streq("symmetrical", txt)) return LV_BAR_MODE_SYMMETRICAL;
LV_LOG_WARN("%s is an unknown value for bar's mode", txt);
return 0; /*Return 0 in lack of a better option. */
}
#endif /* LV_USE_XML */

View File

@@ -0,0 +1,40 @@
/**
* @file lv_xml_bar_parser.h
*
*/
#ifndef LV_BAR_XML_PARSER_H
#define LV_BAR_XML_PARSER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_xml.h"
#if LV_USE_XML
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void * lv_xml_bar_create(lv_xml_parser_state_t * state, const char ** attrs);
void lv_xml_bar_apply(lv_xml_parser_state_t * state, const char ** attrs);
/**********************
* MACROS
**********************/
#endif /* LV_USE_XML */
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_BAR_XML_PARSE_H*/

View File

@@ -0,0 +1,108 @@
/**
* @file lv_xml_roller_parser.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_xml_roller_parser.h"
#if LV_USE_XML
#include "../../../lvgl.h"
#include "../../../lvgl_private.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_roller_mode_t mode_text_to_enum_value(const char * txt);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void * lv_xml_roller_create(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(attrs);
void * item = lv_roller_create(lv_xml_state_get_parent(state));
return item;
}
void lv_xml_roller_apply(lv_xml_parser_state_t * state, const char ** attrs)
{
void * item = lv_xml_state_get_item(state);
lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("selected", name)) {
char buf[64];
lv_strlcpy(buf, value, sizeof(buf));
char * buf_p = buf;
int32_t v1 = lv_xml_atoi(lv_xml_split_str(&buf_p, ' '));
bool v2 = lv_xml_to_bool(buf_p);
lv_roller_set_selected(item, v1, v2);
}
if(lv_streq("visible_row_count", name)) {
lv_roller_set_visible_row_count(item, lv_xml_atoi(value));
}
if(lv_streq("options", name)) {
/*E.g. 'a\nb\nc' true'*/
size_t opts_len = lv_strlen(value);
char * opts_buf = lv_malloc(opts_len + 1);
lv_memcpy(opts_buf, value, opts_len + 1);
LV_ASSERT_MALLOC(opts_buf);
/*Find the last space and trim the rest*/
uint32_t space_pos_from_back = 1;
while(space_pos_from_back < opts_len && value[opts_len - space_pos_from_back] != ' ') {
space_pos_from_back++;
}
opts_buf[opts_len - space_pos_from_back - 1] = '\0'; /*Also trim the `'`*/
lv_roller_mode_t mode = mode_text_to_enum_value(&opts_buf[opts_len - space_pos_from_back + 1]);
/*Also skip the leading `'`*/
lv_roller_set_options(item, opts_buf + 1, mode);
lv_free(opts_buf);
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
static lv_roller_mode_t mode_text_to_enum_value(const char * txt)
{
if(lv_streq("normal", txt)) return LV_ROLLER_MODE_NORMAL;
if(lv_streq("infinite", txt)) return LV_ROLLER_MODE_INFINITE;
LV_LOG_WARN("%s is an unknown value for roller's mode", txt);
return 0; /*Return 0 in lack of a better option. */
}
#endif /* LV_USE_XML */

View File

@@ -0,0 +1,40 @@
/**
* @file lv_xml_roller_parser.h
*
*/
#ifndef LV_ROLLER_XML_PARSER_H
#define LV_ROLLER_XML_PARSER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_xml.h"
#if LV_USE_XML
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void * lv_xml_roller_create(lv_xml_parser_state_t * state, const char ** attrs);
void lv_xml_roller_apply(lv_xml_parser_state_t * state, const char ** attrs);
/**********************
* MACROS
**********************/
#endif /* LV_USE_XML */
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_ROLLER_XML_PARSE_H*/

View File

@@ -0,0 +1,135 @@
/**
* @file lv_xml_scale_parser.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_xml_scale_parser.h"
#if LV_USE_XML
#include "../../../lvgl.h"
#include "../../../lvgl_private.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_scale_mode_t scale_mode_to_enum(const char * txt);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void * lv_xml_scale_create(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(attrs);
void * item = lv_scale_create(lv_xml_state_get_parent(state));
return item;
}
void lv_xml_scale_apply(lv_xml_parser_state_t * state, const char ** attrs)
{
void * item = lv_xml_state_get_item(state);
lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
// <prop name="text_src" type="string[NULL]" help=""/>
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("mode", name)) lv_scale_set_mode(item, scale_mode_to_enum(value));
else if(lv_streq("total_tick_count", name)) lv_scale_set_total_tick_count(item, lv_xml_atoi(value));
else if(lv_streq("major_tick_every", name)) lv_scale_set_major_tick_every(item, lv_xml_atoi(value));
else if(lv_streq("label_show", name)) lv_scale_set_label_show(item, lv_xml_to_bool(value));
else if(lv_streq("post_draw", name)) lv_scale_set_post_draw(item, lv_xml_to_bool(value));
else if(lv_streq("draw_ticks_on_top", name)) lv_scale_set_draw_ticks_on_top(item, lv_xml_to_bool(value));
else if(lv_streq("range", name)) {
int32_t value1 = lv_xml_atoi_split(&value, ' ');
int32_t value2 = lv_xml_atoi_split(&value, ' ');
lv_scale_set_range(item, value1, value2);
}
else if(lv_streq("angle_range", name)) lv_scale_set_angle_range(item, lv_xml_to_bool(value));
else if(lv_streq("rotation", name)) lv_scale_set_rotation(item, lv_xml_to_bool(value));
}
}
void * lv_xml_scale_section_create(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(attrs);
void * item = lv_scale_add_section(lv_xml_state_get_parent(state));
return item;
}
void lv_xml_scale_section_apply(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(state);
LV_UNUSED(attrs);
lv_obj_t * scale = lv_xml_state_get_parent(state);
lv_scale_section_t * section = lv_xml_state_get_item(state);
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("range", name)) {
int32_t value1 = lv_xml_atoi_split(&value, ' ');
int32_t value2 = lv_xml_atoi_split(&value, ' ');
lv_scale_set_section_range(scale, section, value1, value2);
}
else if(lv_streq("style_main", name)) {
lv_xml_style_t * style_dsc = lv_xml_get_style_by_name(&state->ctx, value);
lv_scale_set_section_style_main(scale, section, &style_dsc->style);
}
else if(lv_streq("style_indicator", name)) {
lv_xml_style_t * style_dsc = lv_xml_get_style_by_name(&state->ctx, value);
lv_scale_set_section_style_indicator(scale, section, &style_dsc->style);
}
else if(lv_streq("style_items", name)) {
lv_xml_style_t * style_dsc = lv_xml_get_style_by_name(&state->ctx, value);
lv_scale_set_section_style_items(scale, section, &style_dsc->style);
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
static lv_scale_mode_t scale_mode_to_enum(const char * txt)
{
if(lv_streq("horizontal_top", txt)) return LV_SCALE_MODE_HORIZONTAL_TOP;
if(lv_streq("horizontal_bottom", txt)) return LV_SCALE_MODE_HORIZONTAL_BOTTOM;
if(lv_streq("vertical_left", txt)) return LV_SCALE_MODE_VERTICAL_LEFT;
if(lv_streq("vertical_right", txt)) return LV_SCALE_MODE_VERTICAL_RIGHT;
if(lv_streq("round_inner", txt)) return LV_SCALE_MODE_ROUND_INNER;
if(lv_streq("round_outer", txt)) return LV_SCALE_MODE_ROUND_OUTER;
LV_LOG_WARN("%s is an unknown value for scale's mode", txt);
return 0; /*Return 0 in lack of a better option. */
}
#endif /* LV_USE_XML */

View File

@@ -0,0 +1,41 @@
/**
* @file lv_xml_scale_parser.h
*
*/
#ifndef LV_SCALE_XML_PARSER_H
#define LV_SCALE_XML_PARSER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_xml.h"
#if LV_USE_XML
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void * lv_xml_scale_create(lv_xml_parser_state_t * state, const char ** attrs);
void lv_xml_scale_apply(lv_xml_parser_state_t * state, const char ** attrs);
void * lv_xml_scale_section_create(lv_xml_parser_state_t * state, const char ** attrs);
void lv_xml_scale_section_apply(lv_xml_parser_state_t * state, const char ** attrs);
/**********************
* MACROS
**********************/
#endif /* LV_USE_XML */
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_SCALE_XML_PARSE_H*/

View File

@@ -55,8 +55,23 @@ void lv_xml_slider_apply(lv_xml_parser_state_t * state, const char ** attrs)
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("value", name)) lv_slider_set_value(item, lv_xml_atoi(value), LV_ANIM_OFF);
if(lv_streq("left_value", name)) lv_slider_set_left_value(item, lv_xml_atoi(value), LV_ANIM_OFF);
if(lv_streq("value", name)) {
char buf[64];
lv_strlcpy(buf, value, sizeof(buf));
char * buf_p = buf;
int32_t v1 = lv_xml_atoi(lv_xml_split_str(&buf_p, ' '));
bool v2 = lv_xml_to_bool(buf_p);
lv_bar_set_value(item, v1, v2);
}
if(lv_streq("start_value", name)) {
char buf[64];
lv_strlcpy(buf, value, sizeof(buf));
char * buf_p = buf;
int32_t v1 = lv_xml_atoi(lv_xml_split_str(&buf_p, ' '));
bool v2 = lv_xml_to_bool(buf_p);
lv_bar_set_start_value(item, v1, v2);
}
if(lv_streq("orientation", name)) lv_slider_set_orientation(item, orentation_text_to_enum_value(value));
if(lv_streq("mode", name)) lv_slider_set_mode(item, mode_text_to_enum_value(value));
if(lv_streq("range_min", name)) lv_slider_set_range(item, lv_xml_atoi(value), lv_slider_get_max_value(item));

View File

@@ -0,0 +1,106 @@
/**
* @file lv_xml_spangroup_parser.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_xml_spangroup_parser.h"
#if LV_USE_XML
#include "../../../lvgl.h"
#include "../../../lvgl_private.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_span_overflow_t spangroup_overflow_to_enum(const char * txt);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void * lv_xml_spangroup_create(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(attrs);
void * item = lv_spangroup_create(lv_xml_state_get_parent(state));
return item;
}
void lv_xml_spangroup_apply(lv_xml_parser_state_t * state, const char ** attrs)
{
void * item = lv_xml_state_get_item(state);
lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("overflow", name)) lv_spangroup_set_overflow(item, spangroup_overflow_to_enum(value));
else if(lv_streq("max_lines", name)) lv_spangroup_set_max_lines(item, lv_xml_atoi(value));
else if(lv_streq("indent", name)) lv_spangroup_set_indent(item, lv_xml_atoi(value));
}
}
void * lv_xml_spangroup_span_create(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(attrs);
void * item = lv_spangroup_add_span(lv_xml_state_get_parent(state));
return item;
}
void lv_xml_spangroup_span_apply(lv_xml_parser_state_t * state, const char ** attrs)
{
LV_UNUSED(state);
LV_UNUSED(attrs);
lv_obj_t * spangroup = lv_xml_state_get_parent(state);
lv_span_t * span = lv_xml_state_get_item(state);
for(int i = 0; attrs[i]; i += 2) {
const char * name = attrs[i];
const char * value = attrs[i + 1];
if(lv_streq("text", name)) lv_spangroup_set_span_text(spangroup, span, value);
else if(lv_streq("style", name)) {
lv_xml_style_t * style_dsc = lv_xml_get_style_by_name(&state->ctx, value);
lv_spangroup_set_span_style(spangroup, span, &style_dsc->style);
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
static lv_span_overflow_t spangroup_overflow_to_enum(const char * txt)
{
if(lv_streq("clip", txt)) return LV_SPAN_OVERFLOW_CLIP;
if(lv_streq("ellipsis", txt)) return LV_SPAN_OVERFLOW_ELLIPSIS;
LV_LOG_WARN("%s is an unknown value for span's overflow", txt);
return 0; /*Return 0 in lack of a better option. */
}
#endif /* LV_USE_XML */

View File

@@ -0,0 +1,41 @@
/**
* @file lv_xml_spangroup_parser.h
*
*/
#ifndef LV_SPANGROUP_XML_PARSER_H
#define LV_SPANGROUP_XML_PARSER_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_xml.h"
#if LV_USE_XML
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void * lv_xml_spangroup_create(lv_xml_parser_state_t * state, const char ** attrs);
void lv_xml_spangroup_apply(lv_xml_parser_state_t * state, const char ** attrs);
void * lv_xml_spangroup_span_create(lv_xml_parser_state_t * state, const char ** attrs);
void lv_xml_spangroup_span_apply(lv_xml_parser_state_t * state, const char ** attrs);
/**********************
* MACROS
**********************/
#endif /* LV_USE_XML */
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_SPANGROUP_XML_PARSE_H*/

View File

@@ -51,10 +51,10 @@ static void scale_get_tick_points(lv_obj_t * obj, const uint32_t tick_idx, bool
static void scale_get_label_coords(lv_obj_t * obj, lv_draw_label_dsc_t * label_dsc, lv_point_t * tick_point,
lv_area_t * label_coords);
static void scale_set_indicator_label_properties(lv_obj_t * obj, lv_draw_label_dsc_t * label_dsc,
lv_style_t * indicator_section_style);
static void scale_set_line_properties(lv_obj_t * obj, lv_draw_line_dsc_t * line_dsc, lv_style_t * section_style,
const lv_style_t * indicator_section_style);
static void scale_set_line_properties(lv_obj_t * obj, lv_draw_line_dsc_t * line_dsc, const lv_style_t * section_style,
lv_part_t part);
static void scale_set_arc_properties(lv_obj_t * obj, lv_draw_arc_dsc_t * arc_dsc, lv_style_t * section_style);
static void scale_set_arc_properties(lv_obj_t * obj, lv_draw_arc_dsc_t * arc_dsc, const lv_style_t * section_style);
/* Helpers */
static void scale_find_section_tick_idx(lv_obj_t * obj);
static void scale_store_main_line_tick_width_compensation(lv_obj_t * obj, const uint32_t tick_idx,
@@ -350,6 +350,18 @@ lv_scale_section_t * lv_scale_add_section(lv_obj_t * obj)
return section;
}
void lv_scale_set_section_range(lv_obj_t * scale, lv_scale_section_t * section, int32_t min, int32_t max)
{
LV_ASSERT_OBJ(scale, MY_CLASS);
LV_ASSERT_NULL(section);
section->range_min = min;
section->range_max = max;
lv_obj_invalidate(scale);
}
void lv_scale_section_set_range(lv_scale_section_t * section, int32_t min, int32_t max)
{
if(NULL == section) return;
@@ -358,8 +370,38 @@ void lv_scale_section_set_range(lv_scale_section_t * section, int32_t min, int32
section->range_max = max;
}
void lv_scale_set_section_style_main(lv_obj_t * scale, lv_scale_section_t * section, const lv_style_t * style)
{
LV_ASSERT_OBJ(scale, MY_CLASS);
LV_ASSERT_NULL(section);
section->main_style = style;
lv_obj_invalidate(scale);
}
void lv_scale_set_section_style_indicator(lv_obj_t * scale, lv_scale_section_t * section, const lv_style_t * style)
{
LV_ASSERT_OBJ(scale, MY_CLASS);
LV_ASSERT_NULL(section);
section->indicator_style = style;
lv_obj_invalidate(scale);
}
void lv_scale_set_section_style_items(lv_obj_t * scale, lv_scale_section_t * section, const lv_style_t * style)
{
LV_ASSERT_OBJ(scale, MY_CLASS);
LV_ASSERT_NULL(section);
section->items_style = style;
lv_obj_invalidate(scale);
}
void lv_scale_section_set_style(lv_scale_section_t * section, lv_part_t part, lv_style_t * section_part_style)
{
LV_LOG_WARN("Deprecated, use lv_scale_set_section_style_main/indicator/items instead");
if(NULL == section) return;
switch(part) {
@@ -1232,7 +1274,7 @@ static void scale_get_label_coords(lv_obj_t * obj, lv_draw_label_dsc_t * label_d
* @param items_section_style pointer to indicator section style
* @param part line part, example: LV_PART_INDICATOR, LV_PART_ITEMS, LV_PART_MAIN
*/
static void scale_set_line_properties(lv_obj_t * obj, lv_draw_line_dsc_t * line_dsc, lv_style_t * section_style,
static void scale_set_line_properties(lv_obj_t * obj, lv_draw_line_dsc_t * line_dsc, const lv_style_t * section_style,
lv_part_t part)
{
if(section_style) {
@@ -1282,7 +1324,7 @@ static void scale_set_line_properties(lv_obj_t * obj, lv_draw_line_dsc_t * line_
* @param arc_dsc pointer to arc descriptor
* @param items_section_style pointer to indicator section style
*/
static void scale_set_arc_properties(lv_obj_t * obj, lv_draw_arc_dsc_t * arc_dsc, lv_style_t * section_style)
static void scale_set_arc_properties(lv_obj_t * obj, lv_draw_arc_dsc_t * arc_dsc, const lv_style_t * section_style)
{
if(section_style) {
lv_style_value_t value;
@@ -1352,7 +1394,7 @@ static void scale_set_arc_properties(lv_obj_t * obj, lv_draw_arc_dsc_t * arc_dsc
* @param items_section_style pointer to indicator section style
*/
static void scale_set_indicator_label_properties(lv_obj_t * obj, lv_draw_label_dsc_t * label_dsc,
lv_style_t * indicator_section_style)
const lv_style_t * indicator_section_style)
{
if(indicator_section_style) {
lv_style_value_t value;
@@ -1579,7 +1621,7 @@ static void scale_store_section_line_tick_width_compensation(lv_obj_t * obj, con
/* This can also apply when
* (tick_idx == section->first_tick_idx_in_section) when the
* beginning and ending vlues of the range are the same. */
* beginning and ending values of the range are the same. */
if(tick_idx == section->last_tick_idx_in_section) {
if(section->last_tick_idx_is_major) {
tmp_width = major_tick_dsc->width;

View File

@@ -197,13 +197,14 @@ void lv_scale_set_draw_ticks_on_top(lv_obj_t * obj, bool en);
/**
* Add a Section to specified Scale. Section will not be drawn until
* a valid range is set for it using `lv_scale_section_set_range()`.
* a valid range is set for it using `lv_scale_set_section_range()`.
* @param obj pointer to Scale Widget
* @return pointer to new Section
*/
lv_scale_section_t * lv_scale_add_section(lv_obj_t * obj);
/**
* DEPRECATED, use lv_scale_set_section_rangeinstead.
* Set range for specified Scale Section
* @param section pointer to Section
* @param range_min Section new minimum value
@@ -212,6 +213,16 @@ lv_scale_section_t * lv_scale_add_section(lv_obj_t * obj);
void lv_scale_section_set_range(lv_scale_section_t * section, int32_t min, int32_t max);
/**
* Set the range of a scale section
* @param scale pointer to scale
* @param section pointer to section
* @param range_min section new minimum value
* @param range_max section new maximum value
*/
void lv_scale_set_section_range(lv_obj_t * scale, lv_scale_section_t * section, int32_t min, int32_t max);
/**
* DEPRECATED, use lv_scale_set_section_style_main/indicator/items instead.
* Set style for specified part of Section.
* @param section pointer to Section
* @param part the part of the Scale the style will apply to, e.g. LV_PART_INDICATOR
@@ -219,6 +230,30 @@ void lv_scale_section_set_range(lv_scale_section_t * section, int32_t min, int32
*/
void lv_scale_section_set_style(lv_scale_section_t * section, lv_part_t part, lv_style_t * section_part_style);
/**
* Set the style of the line on a section.
* @param scale pointer to scale
* @param section pointer to section
* @param style point to a style
*/
void lv_scale_set_section_style_main(lv_obj_t * scale, lv_scale_section_t * section, const lv_style_t * style);
/**
* Set the style of the major ticks and label on a section.
* @param scale pointer to scale
* @param section pointer to section
* @param style point to a style
*/
void lv_scale_set_section_style_indicator(lv_obj_t * scale, lv_scale_section_t * section, const lv_style_t * style);
/**
* Set the style of the minor ticks on a section.
* @param scale pointer to scale
* @param section pointer to section
* @param style point to a style
*/
void lv_scale_set_section_style_items(lv_obj_t * scale, lv_scale_section_t * section, const lv_style_t * style);
/*=====================
* Getter functions
*====================*/

View File

@@ -28,12 +28,18 @@ extern "C" {
**********************/
struct _lv_scale_section_t {
lv_style_t * main_style; /**< Style to use for MAIN part(s) of scale
* when it falls within this section's range */
lv_style_t * indicator_style; /**< Style to use for INDICATOR part(s) of scale
* when it falls within this section's range */
lv_style_t * items_style; /**< Style to use for ITEMS part(s) of scale
* when it falls within this section's range */
/** Style to use for MAIN part(s) of scale
* when it falls within this section's range */
const lv_style_t * main_style;
/** Style to use for INDICATOR part(s) of scale
* when it falls within this section's range */
const lv_style_t * indicator_style;
/** Style to use for ITEMS part(s) of scale
* when it falls within this section's range */
const lv_style_t * items_style;
int32_t range_min; /**< Scale parts with value >= this value will be drawn using applicable style. */
int32_t range_max; /**< Scale parts with value <= this value will be drawn using applicable style. */
uint32_t first_tick_idx_in_section; /**< Internal (set during drawing): Tick index of first tick that falls within

View File

@@ -59,7 +59,7 @@ static const lv_property_ops_t properties[] = {
},
{
.id = LV_PROPERTY_SLIDER_LEFT_VALUE,
.setter = lv_slider_set_left_value,
.setter = lv_slider_set_start_value,
.getter = lv_slider_get_left_value,
},
{
@@ -145,7 +145,7 @@ void lv_slider_set_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim)
lv_bar_set_value(obj, value, anim);
}
void lv_slider_set_left_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim)
void lv_slider_set_start_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim)
{
lv_bar_set_start_value(obj, value, anim);
}
@@ -338,11 +338,11 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e)
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
if(!slider->left_knob_focus) lv_slider_set_value(obj, lv_slider_get_value(obj) + 1, LV_ANIM_ON);
else lv_slider_set_left_value(obj, lv_slider_get_left_value(obj) + 1, LV_ANIM_ON);
else lv_slider_set_start_value(obj, lv_slider_get_left_value(obj) + 1, LV_ANIM_ON);
}
else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
if(!slider->left_knob_focus) lv_slider_set_value(obj, lv_slider_get_value(obj) - 1, LV_ANIM_ON);
else lv_slider_set_left_value(obj, lv_slider_get_left_value(obj) - 1, LV_ANIM_ON);
else lv_slider_set_start_value(obj, lv_slider_get_left_value(obj) - 1, LV_ANIM_ON);
}
else {
return;
@@ -355,7 +355,7 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e)
int32_t r = lv_event_get_rotary_diff(e);
if(!slider->left_knob_focus) lv_slider_set_value(obj, lv_slider_get_value(obj) + r, LV_ANIM_ON);
else lv_slider_set_left_value(obj, lv_slider_get_left_value(obj) + 1, LV_ANIM_ON);
else lv_slider_set_start_value(obj, lv_slider_get_left_value(obj) + 1, LV_ANIM_ON);
res = lv_obj_send_event(obj, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RESULT_OK) return;

View File

@@ -85,7 +85,7 @@ void lv_slider_set_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim);
* @param value new value
* @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately
*/
void lv_slider_set_left_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim);
void lv_slider_set_start_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim);
/**
* Set minimum and the maximum values of a bar

View File

@@ -48,7 +48,6 @@ static void lv_spangroup_destructor(const lv_obj_class_t * class_p, lv_obj_t * o
static void lv_spangroup_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void lv_spangroup_event(const lv_obj_class_t * class_p, lv_event_t * e);
static void draw_main(lv_event_t * e);
static void refresh_self_size(lv_obj_t * obj);
static const lv_font_t * lv_span_get_style_text_font(lv_obj_t * par, lv_span_t * span);
static int32_t lv_span_get_style_text_letter_space(lv_obj_t * par, lv_span_t * span);
@@ -115,7 +114,7 @@ lv_obj_t * lv_spangroup_create(lv_obj_t * par)
return obj;
}
lv_span_t * lv_spangroup_new_span(lv_obj_t * obj)
lv_span_t * lv_spangroup_add_span(lv_obj_t * obj)
{
if(obj == NULL) {
return NULL;
@@ -129,9 +128,8 @@ lv_span_t * lv_spangroup_new_span(lv_obj_t * obj)
lv_style_init(&span->style);
span->txt = (char *)"";
span->static_flag = 1;
span->spangroup = obj;
refresh_self_size(obj);
lv_spangroup_refresh(obj);
return span;
}
@@ -159,7 +157,7 @@ void lv_spangroup_delete_span(lv_obj_t * obj, lv_span_t * span)
}
}
refresh_self_size(obj);
lv_spangroup_refresh(obj);
}
/*=====================
@@ -187,8 +185,12 @@ void lv_span_set_text(lv_span_t * span, const char * text)
span->static_flag = 0;
lv_memcpy(span->txt, text, text_alloc_len);
}
refresh_self_size(span->spangroup);
void lv_spangroup_set_span_text(lv_obj_t * obj, lv_span_t * span, const char * text)
{
lv_span_set_text(span, text);
lv_spangroup_refresh(obj);
}
void lv_span_set_text_static(lv_span_t * span, const char * text)
@@ -203,12 +205,28 @@ void lv_span_set_text_static(lv_span_t * span, const char * text)
}
span->static_flag = 1;
span->txt = (char *)text;
}
refresh_self_size(span->spangroup);
void lv_spangroup_set_span_text_static(lv_obj_t * obj, lv_span_t * span, const char * text)
{
lv_span_set_text_static(span, text);
lv_spangroup_refresh(obj);
}
void lv_spangroup_set_span_style(lv_obj_t * obj, lv_span_t * span, const lv_style_t * style)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(span);
lv_style_copy(&span->style, style);
lv_spangroup_refresh(obj);
}
void lv_spangroup_set_align(lv_obj_t * obj, lv_text_align_t align)
{
LV_LOG_WARN("DEPRECATED. Use the text_align style property instead");
lv_obj_set_style_text_align(obj, align, LV_PART_MAIN);
}
@@ -230,18 +248,38 @@ void lv_spangroup_set_indent(lv_obj_t * obj, int32_t indent)
spans->indent = indent;
refresh_self_size(obj);
lv_spangroup_refresh(obj);
}
void lv_spangroup_set_mode(lv_obj_t * obj, lv_span_mode_t mode)
{
LV_LOG_WARN("DEPRECATED, set the width to LV_SIZE_CONTENT or fixed value to control expanding/wrapping");
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
if(mode >= LV_SPAN_MODE_LAST) return;
spans->mode = mode;
lv_spangroup_refr_mode(obj);
if(mode == LV_SPAN_MODE_EXPAND) {
lv_obj_set_width(obj, LV_SIZE_CONTENT);
lv_obj_set_height(obj, LV_SIZE_CONTENT);
}
else if(mode == LV_SPAN_MODE_BREAK) {
if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
lv_obj_set_width(obj, 100);
}
lv_obj_set_height(obj, LV_SIZE_CONTENT);
}
else if(mode == LV_SPAN_MODE_FIXED) {
/* use this mode, The user needs to set the size. */
/* This is just to prevent an infinite loop. */
if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
lv_obj_set_width(obj, 100);
}
if(lv_obj_get_style_height(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
lv_obj_set_content_height(obj, 100);
}
}
lv_spangroup_refresh(obj);
}
void lv_spangroup_set_max_lines(lv_obj_t * obj, int32_t lines)
@@ -249,7 +287,8 @@ void lv_spangroup_set_max_lines(lv_obj_t * obj, int32_t lines)
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
spans->lines = lines;
lv_spangroup_refr_mode(obj);
lv_spangroup_refresh(obj);
}
/*=====================
@@ -338,8 +377,19 @@ int32_t lv_spangroup_get_indent(lv_obj_t * obj)
lv_span_mode_t lv_spangroup_get_mode(lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
return spans->mode;
if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
return LV_SPAN_MODE_EXPAND;
}
/*Width is fixed for the following cases*/
else if(lv_obj_get_style_height(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
return LV_SPAN_MODE_BREAK;
}
/*Both fixed*/
else {
return LV_SPAN_MODE_FIXED;
}
}
int32_t lv_spangroup_get_max_lines(lv_obj_t * obj)
@@ -349,39 +399,6 @@ int32_t lv_spangroup_get_max_lines(lv_obj_t * obj)
return spans->lines;
}
void lv_spangroup_refr_mode(lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
if(spans->mode == LV_SPAN_MODE_EXPAND) {
lv_obj_set_width(obj, LV_SIZE_CONTENT);
lv_obj_set_height(obj, LV_SIZE_CONTENT);
}
else if(spans->mode == LV_SPAN_MODE_BREAK) {
if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
lv_obj_set_width(obj, 100);
}
lv_obj_set_height(obj, LV_SIZE_CONTENT);
}
else if(spans->mode == LV_SPAN_MODE_FIXED) {
/* use this mode, The user needs to set the size. */
/* This is just to prevent an infinite loop. */
if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
lv_obj_set_width(obj, 100);
}
if(lv_obj_get_style_height(obj, LV_PART_MAIN) == LV_SIZE_CONTENT) {
int32_t width = lv_obj_get_style_width(obj, LV_PART_MAIN);
if(LV_COORD_IS_PCT(width)) {
width = 100;
}
int32_t height = lv_spangroup_get_expand_height(obj, width);
lv_obj_set_content_height(obj, height);
}
}
refresh_self_size(obj);
}
int32_t lv_spangroup_get_max_line_height(lv_obj_t * obj)
{
@@ -618,6 +635,19 @@ lv_span_t * lv_spangroup_get_span_by_point(lv_obj_t * obj, const lv_point_t * p)
return NULL;
}
/*=====================
* Other functions
*====================*/
void lv_spangroup_refresh(lv_obj_t * obj)
{
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
spans->refresh = 1;
lv_obj_invalidate(obj);
lv_obj_refresh_self_size(obj);
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -629,7 +659,6 @@ static void lv_spangroup_constructor(const lv_obj_class_t * class_p, lv_obj_t *
lv_ll_init(&spans->child_ll, sizeof(lv_span_t));
spans->indent = 0;
spans->lines = -1;
spans->mode = LV_SPAN_MODE_EXPAND;
spans->overflow = LV_SPAN_OVERFLOW_CLIP;
spans->cache_w = 0;
spans->cache_h = 0;
@@ -668,17 +697,18 @@ static void lv_spangroup_event(const lv_obj_class_t * class_p, lv_event_t * e)
draw_main(e);
}
else if(code == LV_EVENT_STYLE_CHANGED) {
refresh_self_size(obj);
lv_spangroup_refresh(obj);
}
else if(code == LV_EVENT_SIZE_CHANGED) {
refresh_self_size(obj);
lv_spangroup_refresh(obj);
}
else if(code == LV_EVENT_GET_SELF_SIZE) {
int32_t width = 0;
int32_t height = 0;
lv_point_t * self_size = lv_event_get_param(e);
if(spans->mode == LV_SPAN_MODE_EXPAND) {
lv_span_mode_t mode = lv_spangroup_get_mode(obj);
if(mode == LV_SPAN_MODE_EXPAND) {
if(spans->refresh) {
spans->cache_w = (int32_t)lv_spangroup_get_expand_width(obj, 0);
spans->cache_h = lv_spangroup_get_max_line_height(obj);
@@ -687,7 +717,7 @@ static void lv_spangroup_event(const lv_obj_class_t * class_p, lv_event_t * e)
width = spans->cache_w;
height = spans->cache_h;
}
else if(spans->mode == LV_SPAN_MODE_BREAK) {
else if(mode == LV_SPAN_MODE_BREAK) {
width = lv_obj_get_content_width(obj);
if(self_size->y >= 0) {
if(width != spans->cache_w || spans->refresh) {
@@ -701,7 +731,7 @@ static void lv_spangroup_event(const lv_obj_class_t * class_p, lv_event_t * e)
}
}
}
else if(spans->mode == LV_SPAN_MODE_FIXED) {
else if(mode == LV_SPAN_MODE_FIXED) {
width = self_size->x >= 0 ? lv_obj_get_content_width(obj) : 0;
height = self_size->y >= 0 ? lv_obj_get_content_height(obj) : 0;
}
@@ -870,7 +900,7 @@ static int32_t convert_indent_pct(lv_obj_t * obj, int32_t width)
int32_t indent = spans->indent;
if(LV_COORD_IS_PCT(spans->indent)) {
if(spans->mode == LV_SPAN_MODE_EXPAND) {
if(lv_spangroup_get_mode(obj) == LV_SPAN_MODE_EXPAND) {
indent = 0;
}
else {
@@ -1132,14 +1162,6 @@ Next_line_init:
layer->_clip_area = clip_area_ori;
}
static void refresh_self_size(lv_obj_t * obj)
{
lv_spangroup_t * spans = (lv_spangroup_t *)obj;
spans->refresh = 1;
lv_obj_invalidate(obj);
lv_obj_refresh_self_size(obj);
}
static lv_span_coords_t make_span_coords(const lv_span_t * prev_span, const lv_span_t * curr_span, const int32_t width,
const lv_area_t padding, const int32_t indent)
{

View File

@@ -69,7 +69,7 @@ lv_obj_t * lv_spangroup_create(lv_obj_t * parent);
* @param obj pointer to a spangroup object.
* @return pointer to the created span.
*/
lv_span_t * lv_spangroup_new_span(lv_obj_t * obj);
lv_span_t * lv_spangroup_add_span(lv_obj_t * obj);
/**
* Remove the span from the spangroup and free memory.
@@ -84,11 +84,40 @@ void lv_spangroup_delete_span(lv_obj_t * obj, lv_span_t * span);
/**
* Set a new text for a span. Memory will be allocated to store the text by the span.
* As the spangroup is not passed a redraw (invalidation) can't be triggered automatically.
* Therefore `lv_spangroup_refresh(spangroup)` needs to be called manually,
* @param span pointer to a span.
* @param text pointer to a text.
*/
void lv_span_set_text(lv_span_t * span, const char * text);
/**
* Set a static text. It will not be saved by the span so the 'text' variable
* has to be 'alive' while the span exist.
* As the spangroup is not passed a redraw (invalidation) can't be triggered automatically.
* Therefore `lv_spangroup_refresh(spangroup)` needs to be called manually,
*
* @param span pointer to a span.
* @param text pointer to a text.
*/
void lv_span_set_text_static(lv_span_t * span, const char * text);
/**
* Set a new text for a span. Memory will be allocated to store the text by the span.
* @param obj pointer to a spangroup widget.
* @param span pointer to a span.
* @param text pointer to a text.
*/
void lv_spangroup_set_span_text(lv_obj_t * obj, lv_span_t * span, const char * text);
/**
* Set a new text for a span. Memory will be allocated to store the text by the span.
* @param obj pointer to a spangroup widget.
* @param span pointer to a span.
* @param text pointer to a text.
*/
void lv_spangroup_set_span_text_static(lv_obj_t * obj, lv_span_t * span, const char * text);
/**
* Set a static text. It will not be saved by the span so the 'text' variable
* has to be 'alive' while the span exist.
@@ -98,6 +127,15 @@ void lv_span_set_text(lv_span_t * span, const char * text);
void lv_span_set_text_static(lv_span_t * span, const char * text);
/**
* Copy all style properties of style to the bbuilt-in static style of the span.
* @param obj pointer_to a spangroup
* @param span pointer to a span.
* @param style pointer to a style to copy into the span's built-in style
*/
void lv_spangroup_set_span_style(lv_obj_t * obj, lv_span_t * span, const lv_style_t * style);
/**
* DEPRECATED. Use the text_align style property instead
* Set the align of the spangroup.
* @param obj pointer to a spangroup object.
* @param align see lv_text_align_t for details.
@@ -119,6 +157,7 @@ void lv_spangroup_set_overflow(lv_obj_t * obj, lv_span_overflow_t overflow);
void lv_spangroup_set_indent(lv_obj_t * obj, int32_t indent);
/**
* DEPRECATED, set the width to LV_SIZE_CONTENT or fixed value to control expanding/wrapping"
* Set the mode of the spangroup.
* @param obj pointer to a spangroup object.
* @param mode see lv_span_mode_t for details.
@@ -137,10 +176,11 @@ void lv_spangroup_set_max_lines(lv_obj_t * obj, int32_t lines);
*====================*/
/**
* Get a pointer to the style of a span
* Get a pointer to the style of a span's built-in style.
* Any lv_style_set_... functions can be applied on the returned style.
* @param span pointer to the span
* @return pointer to the style. valid as long as the span is valid
*/
* @return pointer to the style. (valid as long as the span is valid)
*/
lv_style_t * lv_span_get_style(lv_span_t * span);
/**
@@ -269,7 +309,7 @@ lv_span_t * lv_spangroup_get_span_by_point(lv_obj_t * obj, const lv_point_t * po
* Update the mode of the spangroup.
* @param obj pointer to a spangroup object.
*/
void lv_spangroup_refr_mode(lv_obj_t * obj);
void lv_spangroup_refresh(lv_obj_t * obj);
/**********************
* MACROS

View File

@@ -29,7 +29,6 @@ extern "C" {
struct _lv_span_t {
char * txt; /**< a pointer to display text */
lv_obj_t * spangroup; /**< a pointer to spangroup */
lv_style_t style; /**< display text style */
uint32_t static_flag : 1; /**< the text is static flag */
@@ -45,7 +44,6 @@ struct _lv_spangroup_t {
int32_t cache_w; /**< the cache automatically calculates the width */
int32_t cache_h; /**< similar cache_w */
lv_ll_t child_ll;
uint32_t mode : 2; /**< details see lv_span_mode_t */
uint32_t overflow : 1; /**< details see lv_span_overflow_t */
uint32_t refresh : 1; /**< the spangroup need refresh cache_w and cache_h */
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -117,10 +117,10 @@ void test_scale_render_example_2(void)
lv_scale_section_t * section = lv_scale_add_section(scale);
/* Configure section styles */
lv_scale_section_set_range(section, 75, 100);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style);
lv_scale_set_section_range(scale, section, 75, 100);
lv_scale_set_section_style_indicator(scale, section, &section_label_style);
lv_scale_set_section_style_items(scale, section, &section_minor_tick_style);
lv_scale_set_section_style_main(scale, section, &section_main_line_style);
lv_obj_set_style_bg_color(scale, lv_palette_main(LV_PALETTE_BLUE_GREY), 0);
lv_obj_set_style_bg_opa(scale, LV_OPA_50, 0);
@@ -234,10 +234,10 @@ void test_scale_render_example_4(void)
/* Configure section styles */
lv_scale_section_t * section = lv_scale_add_section(scale);
lv_scale_section_set_range(section, 75, 100);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style);
lv_scale_set_section_range(scale, section, 75, 100);
lv_scale_set_section_style_indicator(scale, section, &section_label_style);
lv_scale_set_section_style_items(scale, section, &section_minor_tick_style);
lv_scale_set_section_style_main(scale, section, &section_main_line_style);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/scale_4.png");
}
@@ -321,16 +321,16 @@ void test_scale_set_style(void)
/* Configure section styles */
lv_scale_section_t * section = lv_scale_add_section(scale);
lv_scale_section_set_range(section, 75, 100);
lv_scale_set_section_range(scale, section, 75, 100);
lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style);
lv_scale_set_section_style_main(scale, section, &section_main_line_style);
TEST_ASSERT_NOT_NULL(section->main_style);
TEST_ASSERT_NULL(section->indicator_style);
TEST_ASSERT_NULL(section->items_style);
TEST_ASSERT_EQUAL(section->main_style, &section_main_line_style);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_set_section_style_indicator(scale, section, &section_label_style);
TEST_ASSERT_NOT_NULL(section->main_style);
TEST_ASSERT_NOT_NULL(section->indicator_style);
TEST_ASSERT_NULL(section->items_style);
@@ -338,7 +338,7 @@ void test_scale_set_style(void)
TEST_ASSERT_EQUAL(section->main_style, &section_main_line_style);
TEST_ASSERT_EQUAL(section->indicator_style, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_set_section_style_items(scale, section, &section_minor_tick_style);
TEST_ASSERT_NOT_NULL(section->main_style);
TEST_ASSERT_NOT_NULL(section->indicator_style);
TEST_ASSERT_NOT_NULL(section->items_style);
@@ -346,22 +346,6 @@ void test_scale_set_style(void)
TEST_ASSERT_EQUAL(section->main_style, &section_main_line_style);
TEST_ASSERT_EQUAL(section->indicator_style, &section_label_style);
TEST_ASSERT_EQUAL(section->items_style, &section_minor_tick_style);
/* Invalid part */
lv_scale_section_set_style(section, LV_PART_CURSOR, &section_minor_tick_style);
TEST_ASSERT_NOT_NULL(section->main_style);
TEST_ASSERT_NOT_NULL(section->indicator_style);
TEST_ASSERT_NOT_NULL(section->items_style);
TEST_ASSERT_EQUAL(section->main_style, &section_main_line_style);
TEST_ASSERT_EQUAL(section->indicator_style, &section_label_style);
TEST_ASSERT_EQUAL(section->items_style, &section_minor_tick_style);
/* NULL section */
lv_scale_section_t * null_section = NULL;
lv_scale_section_set_range(null_section, 75, 100);
lv_scale_section_set_style(null_section, LV_PART_MAIN, &section_main_line_style);
}
/* The scale internally counts the number of custom labels until it finds the NULL sentinel */

View File

@@ -150,7 +150,7 @@ void test_slider_normal_mode_should_leave_edit_mode_if_released(void)
void test_ranged_mode_adjust_with_encoder(void)
{
lv_slider_set_value(sliderRangeMode, 90, LV_ANIM_OFF);
lv_slider_set_left_value(sliderRangeMode, 10, LV_ANIM_OFF);
lv_slider_set_start_value(sliderRangeMode, 10, LV_ANIM_OFF);
/* Setup group and encoder indev */
lv_group_add_obj(g, sliderRangeMode);

View File

@@ -33,7 +33,7 @@ void test_spangroup_create_returns_not_null_object(void)
void test_spangroup_new_span_with_null_parameter_returns_null_object(void)
{
lv_span_t * span = lv_spangroup_new_span(NULL);
lv_span_t * span = lv_spangroup_add_span(NULL);
TEST_ASSERT(NULL == span);
TEST_ASSERT_EQUAL_INT(0, lv_spangroup_get_span_count(spangroup));
@@ -41,7 +41,7 @@ void test_spangroup_new_span_with_null_parameter_returns_null_object(void)
void test_spangroup_new_span_with_valid_parameter_returns_not_null_object(void)
{
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
TEST_ASSERT(NULL != span);
TEST_ASSERT_EQUAL_INT(1, lv_spangroup_get_span_count(spangroup));
@@ -49,7 +49,7 @@ void test_spangroup_new_span_with_valid_parameter_returns_not_null_object(void)
void test_spangroup_delete_span_span_is_null(void)
{
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_spangroup_delete_span(spangroup, span);
@@ -59,7 +59,7 @@ void test_spangroup_delete_span_span_is_null(void)
void test_span_set_text(void)
{
const char * test_text = "Test Text";
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_span_set_text(span, test_text);
@@ -69,7 +69,7 @@ void test_span_set_text(void)
void test_span_set_text_with_bad_parameter_no_action_performed(void)
{
const char * test_text = "Test Text";
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_span_set_text(span, test_text);
lv_span_set_text(span, NULL);
@@ -81,7 +81,7 @@ void test_span_set_text_with_previous_test_overwrites(void)
{
const char * old_test_text = "Old Test Text";
const char * new_test_text = "New Test Text and it is longer";
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_span_set_text(span, old_test_text);
lv_span_set_text(span, new_test_text);
@@ -92,7 +92,7 @@ void test_span_set_text_with_previous_test_overwrites(void)
void test_span_set_text_static(void)
{
const char * test_text = "Test Text";
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_span_set_text_static(span, test_text);
@@ -102,7 +102,7 @@ void test_span_set_text_static(void)
void test_span_set_text_static_with_bad_parameter_no_action_performed(void)
{
const char * test_text = "Test Text";
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_span_set_text_static(span, test_text);
lv_span_set_text_static(span, NULL);
@@ -114,7 +114,7 @@ void test_span_set_text_static_with_previous_text_overwrites(void)
{
const char * old_test_text = "Old Test Text";
const char * new_test_text = "New Test Text and it is longer";
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_span_set_text_static(span, old_test_text);
lv_span_set_text_static(span, new_test_text);
@@ -205,7 +205,7 @@ void test_spangroup_get_max_line_h(void)
TEST_ASSERT_EQUAL(0, (uint32_t)max_line);
(void)lv_spangroup_new_span(spangroup);
(void)lv_spangroup_add_span(spangroup);
max_line = lv_spangroup_get_max_line_height(spangroup);
// TODO: find out why this magic numberdd
@@ -218,12 +218,12 @@ void test_spangroup_draw(void)
spangroup = lv_spangroup_create(active_screen);
lv_spangroup_set_mode(spangroup, LV_SPAN_MODE_BREAK);
lv_obj_set_width(spangroup, 100);
lv_span_t * span_1 = lv_spangroup_new_span(spangroup);
lv_span_t * span_1 = lv_spangroup_add_span(spangroup);
lv_span_set_text(span_1, "This text is over 100 pixels width");
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_01.png");
lv_span_t * span_2 = lv_spangroup_new_span(spangroup);
lv_span_t * span_2 = lv_spangroup_add_span(spangroup);
lv_span_set_text(span_2, "This text is also over 100 pixels width");
lv_style_set_text_decor(&span_2->style, LV_TEXT_DECOR_STRIKETHROUGH);
@@ -246,8 +246,8 @@ void test_spangroup_get_child(void)
{
const int32_t span_1_idx = 0;
const int32_t span_2_idx = 1;
lv_span_t * span_1 = lv_spangroup_new_span(spangroup);
lv_span_t * span_2 = lv_spangroup_new_span(spangroup);
lv_span_t * span_1 = lv_spangroup_add_span(spangroup);
lv_span_t * span_2 = lv_spangroup_add_span(spangroup);
TEST_ASSERT_EQUAL_PTR(span_2, lv_spangroup_get_child(spangroup, span_2_idx));
TEST_ASSERT_EQUAL_PTR(span_1, lv_spangroup_get_child(spangroup, span_1_idx));
@@ -255,8 +255,8 @@ void test_spangroup_get_child(void)
void test_spangroup_get_child_count(void)
{
(void)lv_spangroup_new_span(spangroup);
(void)lv_spangroup_new_span(spangroup);
(void)lv_spangroup_add_span(spangroup);
(void)lv_spangroup_add_span(spangroup);
const uint32_t cnt = lv_spangroup_get_span_count(spangroup);
@@ -270,7 +270,7 @@ void test_spangroup_get_expand_width(void)
active_screen = lv_screen_active();
spangroup = lv_spangroup_create(active_screen);
lv_span_t * span = lv_spangroup_new_span(spangroup);
lv_span_t * span = lv_spangroup_add_span(spangroup);
lv_span_set_text(span, "This text is over 100 pixels width");
TEST_ASSERT_EQUAL_INT(experimental_size,
@@ -286,26 +286,26 @@ void test_spangroup_newlines(void)
spangroup = lv_spangroup_create(active_screen);
lv_obj_set_size(spangroup, LV_PCT(100), LV_PCT(100));
lv_span_set_text(lv_spangroup_new_span(spangroup), "Lorem\n");
lv_span_set_text(lv_spangroup_new_span(spangroup), "ipsum");
lv_span_set_text(lv_spangroup_add_span(spangroup), "Lorem\n");
lv_span_set_text(lv_spangroup_add_span(spangroup), "ipsum");
lv_span_set_text(lv_spangroup_new_span(spangroup), "\n\n");
lv_span_set_text(lv_spangroup_add_span(spangroup), "\n\n");
lv_span_set_text(lv_spangroup_new_span(spangroup), "dolor");
lv_span_set_text(lv_spangroup_new_span(spangroup), "");
lv_span_set_text(lv_spangroup_new_span(spangroup), "\nsit");
lv_span_set_text(lv_spangroup_add_span(spangroup), "dolor");
lv_span_set_text(lv_spangroup_add_span(spangroup), "");
lv_span_set_text(lv_spangroup_add_span(spangroup), "\nsit");
/* carriage return is treated as equivalent to line feed */
lv_span_set_text(lv_spangroup_new_span(spangroup), "\r");
lv_span_set_text(lv_spangroup_add_span(spangroup), "\r");
lv_span_set_text(lv_spangroup_new_span(spangroup), "amet,\n consectetur");
lv_span_set_text(lv_spangroup_new_span(spangroup), " adipiscing");
lv_span_set_text(lv_spangroup_add_span(spangroup), "amet,\n consectetur");
lv_span_set_text(lv_spangroup_add_span(spangroup), " adipiscing");
lv_span_set_text(lv_spangroup_new_span(spangroup), "\n");
lv_span_set_text(lv_spangroup_new_span(spangroup), "");
lv_span_set_text(lv_spangroup_add_span(spangroup), "\n");
lv_span_set_text(lv_spangroup_add_span(spangroup), "");
lv_span_set_text(lv_spangroup_new_span(spangroup), "\relit, sed\n");
lv_span_set_text(lv_spangroup_new_span(spangroup), "do eiusmod");
lv_span_set_text(lv_spangroup_add_span(spangroup), "\relit, sed\n");
lv_span_set_text(lv_spangroup_add_span(spangroup), "do eiusmod");
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_06.png");
}
@@ -331,15 +331,15 @@ void test_spangroup_chinese_break_line(void)
lv_obj_set_style_border_width(spangroup, 2, 0);
lv_obj_set_width(spangroup, 250);
lv_span_t * span1 = lv_spangroup_new_span(spangroup);
lv_span_t * span1 = lv_spangroup_add_span(spangroup);
lv_span_set_text(span1, "八百标兵奔北坡");
lv_span_t * span2 = lv_spangroup_new_span(spangroup);
lv_span_t * span2 = lv_spangroup_add_span(spangroup);
lv_span_set_text(span2, "炮兵并排北边跑");
lv_style_set_text_color(&span2->style, lv_palette_main(LV_PALETTE_RED));
lv_span_t * span3 = lv_spangroup_new_span(spangroup);
lv_span_t * span3 = lv_spangroup_add_span(spangroup);
lv_span_set_text(span3, "中英文测试。The quick brown fox jumps over a lazy dog. ");
lv_style_set_text_color(&span3->style, lv_palette_main(LV_PALETTE_BLUE));
lv_span_t * span4 = lv_spangroup_new_span(spangroup);
lv_span_t * span4 = lv_spangroup_add_span(spangroup);
lv_span_set_text(span4, "abcdefghijklmn中英文测试");
lv_style_set_text_color(&span4->style, lv_palette_main(LV_PALETTE_GREEN));
@@ -365,12 +365,12 @@ void test_spangroup_style_text_letter_space(void)
lv_obj_set_style_outline_width(spangroup, 1, 0);
lv_obj_set_style_text_letter_space(spangroup, 20, 0);
lv_span_set_text(lv_spangroup_new_span(spangroup), "A");
lv_span_set_text(lv_spangroup_new_span(spangroup), "B");
lv_span_set_text(lv_spangroup_new_span(spangroup), "C");
lv_span_set_text(lv_spangroup_new_span(spangroup), "D");
lv_span_set_text(lv_spangroup_new_span(spangroup), "E");
lv_span_set_text(lv_spangroup_new_span(spangroup), "F");
lv_span_set_text(lv_spangroup_add_span(spangroup), "A");
lv_span_set_text(lv_spangroup_add_span(spangroup), "B");
lv_span_set_text(lv_spangroup_add_span(spangroup), "C");
lv_span_set_text(lv_spangroup_add_span(spangroup), "D");
lv_span_set_text(lv_spangroup_add_span(spangroup), "E");
lv_span_set_text(lv_spangroup_add_span(spangroup), "F");
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/span_08.png");
}
@@ -393,33 +393,33 @@ void test_spangroup_get_span_coords(void)
lv_obj_set_style_pad_all(spangroup, 20, LV_PART_MAIN);
/* Create spans and set their properties */
spans[0] = lv_spangroup_new_span(spangroup);
spans[0] = lv_spangroup_add_span(spangroup);
lv_span_set_text(spans[0], "China is a beautiful country.");
lv_style_set_text_color(lv_span_get_style(spans[0]), lv_palette_main(LV_PALETTE_RED));
lv_style_set_text_decor(lv_span_get_style(spans[0]), LV_TEXT_DECOR_UNDERLINE);
lv_style_set_text_opa(lv_span_get_style(spans[0]), LV_OPA_50);
spans[1] = lv_spangroup_new_span(spangroup);
spans[1] = lv_spangroup_add_span(spangroup);
lv_span_set_text_static(spans[1], "good good study, day day up.");
lv_style_set_text_font(lv_span_get_style(spans[1]), &lv_font_montserrat_24);
lv_style_set_text_color(lv_span_get_style(spans[1]), lv_palette_main(LV_PALETTE_GREEN));
spans[2] = lv_spangroup_new_span(spangroup);
spans[2] = lv_spangroup_add_span(spangroup);
lv_span_set_text_static(spans[2], "LVGL is an open-source graphics library.");
lv_style_set_text_color(lv_span_get_style(spans[2]), lv_palette_main(LV_PALETTE_BLUE));
spans[3] = lv_spangroup_new_span(spangroup);
spans[3] = lv_spangroup_add_span(spangroup);
lv_span_set_text_static(spans[3], "the boy no name.");
lv_style_set_text_color(lv_span_get_style(spans[3]), lv_palette_main(LV_PALETTE_GREEN));
lv_style_set_text_font(lv_span_get_style(spans[3]), &lv_font_montserrat_20);
lv_style_set_text_decor(lv_span_get_style(spans[3]), LV_TEXT_DECOR_UNDERLINE);
spans[4] = lv_spangroup_new_span(spangroup);
spans[4] = lv_spangroup_add_span(spangroup);
lv_span_set_text(spans[4], "I have a dream that hope to come true.");
lv_style_set_text_decor(lv_span_get_style(spans[4]), LV_TEXT_DECOR_STRIKETHROUGH);
/* Refresh the span group mode and update layout */
lv_spangroup_refr_mode(spangroup);
lv_spangroup_refresh(spangroup);
lv_obj_update_layout(spangroup);
/* Define expected coordinates for testing */

View File

@@ -0,0 +1,74 @@
#if LV_BUILD_TEST
#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());
}
static void test_with_attrs(const char * name)
{
lv_obj_t * scr = lv_screen_active();
lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_xml_create(scr, name, NULL);
const char * attrs_1[] = {
"value", "30",
"width", "100",
NULL, NULL,
};
lv_xml_create(scr, name, attrs_1);
const char * attrs_2[] = {
"range", "-100 100",
"mode", "symmetrical",
"value", "50",
NULL, NULL,
};
lv_xml_create(scr, name, attrs_2);
const char * attrs_3[] = {
"orientation", "vertical",
"height", "80",
"width", "30",
"value", "40",
NULL, NULL,
};
lv_xml_create(scr, name, attrs_3);
TEST_ASSERT_EQUAL_SCREENSHOT("xml/lv_bar.png");
}
void test_xml_bar_widget(void)
{
test_with_attrs("lv_bar");
}
void test_xml_bar_component(void)
{
const char * xml = "<component>"
"<view extends=\"lv_bar\">"
"</view>"
"</component>";
lv_xml_component_register_from_data("bar_test", xml);
test_with_attrs("bar_test");
}
#endif

View File

@@ -1,3 +1,4 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
@@ -23,6 +24,8 @@ void test_xml_chart_with_attrs(void)
"height", "100",
"type", "bar",
"point_count", "8",
"style_length:indicator", "10",
"style_transform_rotation:indicator", "300",
NULL, NULL,
};

View File

@@ -0,0 +1,36 @@
#if LV_BUILD_TEST
#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_roller_with_attrs(void)
{
lv_obj_t * scr = lv_screen_active();
const char * roller_attrs[] = {
"width", "200",
"options", "'a\nb\nc\nd\ne' infinite",
"selected", "2 true",
"visible_line_count", "3",
NULL, NULL,
};
lv_obj_t * roller = lv_xml_create(scr, "lv_roller", roller_attrs);
lv_obj_center(roller);
TEST_ASSERT_EQUAL_SCREENSHOT("xml/lv_roller.png");
}
#endif

View File

@@ -0,0 +1,53 @@
#if LV_BUILD_TEST
#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_scale_with_attrs(void)
{
lv_obj_t * scr = lv_screen_active();
const char * scale_attrs[] = {
"width", "120",
"height", "120",
"mode", "round_outer",
"range", "0 150",
"total_tick_count", "16",
"major_tick_every", "3",
"style_length:indicator", "10",
"style_transform_rotation:indicator", "300",
NULL, NULL,
};
lv_obj_t * scale = lv_xml_create(scr, "lv_scale", scale_attrs);
lv_obj_center(scale);
const char * section_attrs[] = {
"range", "10 80",
NULL, NULL,
};
lv_scale_section_t * section = lv_xml_create(scale, "lv_scale-section", section_attrs);
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_color(&style, lv_color_hex(0xff0000));
lv_style_set_line_color(&style, lv_color_hex(0x00ff00));
lv_style_set_line_width(&style, 4);
lv_scale_set_section_style_indicator(scale, section, &style);
TEST_ASSERT_EQUAL_SCREENSHOT("xml/lv_scale.png");
}
#endif

View File

@@ -32,8 +32,7 @@ static void test_with_attrs(const char * name)
lv_xml_create(scr, name, attrs_1);
const char * attrs_2[] = {
"range_min", "-100",
"range_max", "100",
"range", "-100 100",
"mode", "symmetrical",
"value", "50",
NULL, NULL,

View File

@@ -0,0 +1,67 @@
#if LV_BUILD_TEST
#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_spangroup_with_attrs(void)
{
lv_obj_t * scr = lv_screen_active();
const char * spangroup_attrs[] = {
"width", "300",
"indent", "40",
"max_lines", "3",
"overflow", "ellipsis",
"style_text_align", "center",
"style_bg_opa", "20%",
"style_bg_color", "#ffff00",
NULL, NULL,
};
lv_obj_t * spangroup = lv_xml_create(scr, "lv_spangroup", spangroup_attrs);
lv_obj_center(spangroup);
const char * span1_attrs[] = {
"text", "This is a red text as a span!",
NULL, NULL,
};
lv_span_t * span1 = lv_xml_create(spangroup, "lv_spangroup-span", span1_attrs);
static lv_style_t style1;
lv_style_init(&style1);
lv_style_set_text_color(&style1, lv_color_hex(0xff0000));
lv_style_set_text_letter_space(&style1, 5);
lv_spangroup_set_span_style(spangroup, span1, &style1);
const char * span2_attrs[] = {
"text", "And this a large blue!",
NULL, NULL,
};
lv_span_t * span2 = lv_xml_create(spangroup, "lv_spangroup-span", span2_attrs);
static lv_style_t style2;
lv_style_init(&style2);
lv_style_set_text_color(&style2, lv_color_hex(0x0000ff));
lv_style_set_text_font(&style2, &lv_font_montserrat_48);
lv_spangroup_set_span_style(spangroup, span2, &style2);
TEST_ASSERT_EQUAL_SCREENSHOT("xml/lv_spangroup.png");
}
#endif

View File

@@ -1,6 +1,6 @@
<!--
Example
<lv_bar mode="symmetrical" angles="100° 200°" bg_angles="30° 150° range="40 100" value="60"/>
<lv_bar mode="symmetrical" range="-40 100" value="60"/>
-->
<widget>
@@ -27,12 +27,13 @@ Example
<param name ="animated" type="bool" help="Set the value with animation" optional="true" default="false"/>
</prop>
<prop name="mode" help="The mode">
<param name="mode" type="enum:lv_bar_mode"/>
<prop name="start_value" help="The current left value in case of range mode">
<param name ="value" type="int" help="The current value"/>
<param name ="animated" type="bool" help="Set the value with animation" optional="true" default="false"/>
</prop>
<prop name="orientation" help="Orientation">
<param name="mode" type="enum:lv_bar_orientation"/>
</prop>
<prop name="mode" type="enum:lv_bar_mode"/>
<prop name="orientation" type="enum:lv_bar_orientation"/>
</api>
</widget>

View File

@@ -9,7 +9,10 @@ Example
<api>
<prop name="text" type="string" help="Show it instead of the selected options"/>
<prop name="options" type="string" help="The options as a \n separated string"/>
<prop name="selected" type="int" help="The index of the selected option"/>
<prop name="selected" help="The index of the selected option">
<param name="selected" type="int" help="The index of the selected option"/>
<param name="anim" type="bool" help="Move to the option with animation" default="false"/>
</prop>
<prop name="symbol" type="string" help="The symbol, usually a caret"/>
<element name="list" access="get" type="lv_obj" help=""/>
</api>

21
xmls/lv_roller.xml Normal file
View File

@@ -0,0 +1,21 @@
<!--
Example
<lv_roller options="'a\nb\nc\nd' infinite" selected="2 true" visible_row_count="3"/>
-->
<widget>
<api>
<enumdef name="lv_roller_mode">
<enum name="normal" help=""/>
<enum name="infinite" help=""/>
</enumdef>
<prop name="options" type="int">
<param name="values" type="string"/>
<param name="mode" type="enum:lv_roller_mode"/>
</prop>
<prop name="selected" type="int" help=""/>
<prop name="visible_row_count" type="int" help=""/>
</api>
</widget>

View File

@@ -15,47 +15,28 @@
<enum name="round_outer" help=""/>
</enumdef>
<prop name="mode" help="">
<param name="mode" type="enum:lv_scale_mode" help=""/>
</prop>
<prop name="total_tick_count" help="">
<param name="cnt" type="int" help=""/>
</prop>
<prop name="major_tick_every" help="">
<param name="cnt" type="int" help=""/>
</prop>
<prop name="label_show" help="">
<param name="en" type="bool" help=""/>
</prop>
<prop name="mode" type="enum:lv_scale_mode" help=""/>
<prop name="total_tick_count" type="int" help=""/>
<prop name="major_tick_every" type="int" help=""/>
<prop name="label_show" type="bool" help=""/>
<prop name="range" help="">
<param name="range_min" type="int" help=""/>
<param name="range_max" type="int" help=""/>
</prop>
<prop name="angle_range" help="">
<param name="range" type="deg" help=""/>
</prop>
<prop name="rotation" help="">
<param name="rotation" type="deg" help=""/>
</prop>
<prop name="text_src" help="">
<param name="texts" type="string[NULL]" help=""/>
</prop>
<prop name="post_draw" help="">
<param name="en" type="bool" help=""/>
</prop>
<prop name="draw_ticks_on_top" help="">
<param name="en" type="bool" help=""/>
</prop>
<prop name="angle_range" type="deg" help=""/>
<prop name="rotation" type="deg" help=""/>
<prop name="text_src" type="string[NULL]" help=""/>
<prop name="post_draw" type="bool" help=""/>
<prop name="draw_ticks_on_top" type="bool" help=""/>
<element name="section" type="custom:scale_section" access="add">
<element name="section" type="lv_scale_section" access="add">
<prop name="range" help="">
<param name="int" type="minor_range" help=""/>
<param name="int" type="major_range" help=""/>
</prop>
<prop name="style" help="">
<param name="part" type="part" help=""/>
<param name="style" type="style" help=""/>
</prop>
<prop name="style_main" type="style" help=""/>
<prop name="style_indicator" type="style" help=""/>
<prop name="style_items" type="style" help=""/>
</element>
</api>
</widget>

View File

@@ -20,6 +20,11 @@ Example
<param name="anim" type="bool" default="false"/>
</prop>
<prop name="start_value" type="int">
<param name="range_min" type="int"/>
<param name="anim" type="bool" default="false"/>
</prop>
<prop name="mode" type="enum:lv_slider_mode">
<param name="range_min" type="int"/>
</prop>

View File

@@ -12,35 +12,20 @@ Example
<enum name="clip" help=""/>
<enum name="ellipses" help=""/>
</enumdef>
<enumdef name="lv_span_mode">
<enum name="fixed" help=""/>
<enum name="expand" help=""/>
<enum name="break" help=""/>
</enumdef>
<prop name="align" help="align the text of the span group">
<param name="align" type="enum:lv_text_align" help=""/>
</prop>
<prop name="overflow" help="">
<param name="overflow" type="enum:lv_span_overflow" help=""/>
</prop>
<prop name="mode" help="">
<param name="mode" type="enum:lv_span_mode" help=""/>
</prop>
<prop name="max_lines" help="">
<param name="max_lines" type="int" help=""/>
</prop>
<prop name="indent" help="">
<param name="indent" type="int" help=""/>
</prop>
<prop name="overflow" type="enum:lv_span_overflow" help=""/>
<prop name="max_lines" type="int" help=""/>
<prop name="indent" type="int" help=""/>
<element name="span" type="custom:span" access="add">
<param name="text" type="string" help=""/>
<param name="style" type="style" help=""/>
<prop name="text" type="string" help=""/>
<prop name="style" type="style" help=""/>
</element>
</api>
</widget>