mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-27 11:57:48 +08:00
chore: minor fixed in XML and observer related codes
This commit is contained in:
committed by
Felipe Neves
parent
92a51f056f
commit
b4c9d2e690
@@ -372,7 +372,7 @@ integer value:
|
|||||||
- Drop-Down
|
- Drop-Down
|
||||||
- Roller
|
- Roller
|
||||||
- Slider
|
- Slider
|
||||||
- Scale Section Min/Max value
|
+ - Scale Section Min/Max values
|
||||||
|
|
||||||
Any number of Observers can be created for a single Widget, each bound to ONE of
|
Any number of Observers can be created for a single Widget, each bound to ONE of
|
||||||
the above properties.
|
the above properties.
|
||||||
@@ -521,6 +521,9 @@ The only difference is that in the bind function both the spangroup and the span
|
|||||||
|
|
||||||
:cpp:expr:`lv_spangroup_bind_span_text(spangroup, span1, &subject, format_string)`
|
:cpp:expr:`lv_spangroup_bind_span_text(spangroup, span1, &subject, format_string)`
|
||||||
|
|
||||||
|
Note that before calling :cpp:expr:`lv_spangroup_delete_span` :cpp:expr:`lv_observer_remove`
|
||||||
|
needs to be called manually as LVGL can't remove the binding automatically.
|
||||||
|
|
||||||
Arc Widgets
|
Arc Widgets
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
@@ -578,10 +581,10 @@ Scale's Section
|
|||||||
|
|
||||||
This method of subscribing to an integer Subject affects a Section of a Scale Widget's integer
|
This method of subscribing to an integer Subject affects a Section of a Scale Widget's integer
|
||||||
minimum or maximum values directly. Note that this is a one way binding (Subject ==> Widget)
|
minimum or maximum values directly. Note that this is a one way binding (Subject ==> Widget)
|
||||||
as the Scale Section's are not interactive.
|
as the Scale Section's boundaries are not interactive.
|
||||||
(Requires :c:macro:`LV_USE_SCALE` to be configured to ``1``.)
|
(Requires :c:macro:`LV_USE_SCALE` to be configured to ``1``.)
|
||||||
|
|
||||||
It support only integer subjects.
|
It supports only integer subjects.
|
||||||
|
|
||||||
- :cpp:expr:`lv_scale_bind_section_min_value(scale, section1, &subject)`
|
- :cpp:expr:`lv_scale_bind_section_min_value(scale, section1, &subject)`
|
||||||
- :cpp:expr:`lv_scale_bind_section_max_value(scale, section1, &subject)`
|
- :cpp:expr:`lv_scale_bind_section_max_value(scale, section1, &subject)`
|
||||||
|
|||||||
@@ -9,17 +9,26 @@
|
|||||||
<style name="btn_pr_style" bg_opa="255"/>
|
<style name="btn_pr_style" bg_opa="255"/>
|
||||||
</styles>
|
</styles>
|
||||||
|
|
||||||
<view extends="lv_obj" name="main" width="280" height="content" style_bg_color="#light_blue">
|
<view extends="lv_obj" name="main" width="280" height="content" style_bg_color="#light_blue"
|
||||||
<lv_label text-translated="tiger"/>
|
style_layout="grid" style_grid_column_dsc_array="100 fr(1)" style_grid_row_dsc_array="50 200"
|
||||||
<my_card title="Card 1" name="card1"
|
|
||||||
y="30"
|
>
|
||||||
btn_rel_style="btn_style"
|
<lv_obj style_grid_cell_column_pos="0" style_grid_cell_column_span="1" style_grid_cell_x_align="stretch"
|
||||||
btn_pr_style="btn_pr_style"/>
|
style_grid_cell_row_pos="0" style_grid_cell_row_span="1" style_grid_cell_y_align="stretch">
|
||||||
|
<lv_label text="0/0"/>
|
||||||
|
</lv_obj>
|
||||||
|
<lv_obj style_grid_cell_column_pos="0" style_grid_cell_column_span="1" style_grid_cell_x_align="stretch"
|
||||||
|
style_grid_cell_row_pos="1" style_grid_cell_row_span="1" style_grid_cell_y_align="stretch">
|
||||||
|
<lv_label text="0/1"/>
|
||||||
|
</lv_obj>
|
||||||
|
<lv_obj style_grid_cell_column_pos="1" style_grid_cell_column_span="1" style_grid_cell_x_align="stretch"
|
||||||
|
style_grid_cell_row_pos="0" style_grid_cell_row_span="1" style_grid_cell_y_align="stretch">
|
||||||
|
<lv_label text="1/0"/>
|
||||||
|
</lv_obj>
|
||||||
|
<lv_obj style_grid_cell_column_pos="1" style_grid_cell_column_span="1" style_grid_cell_x_align="stretch"
|
||||||
|
style_grid_cell_row_pos="1" style_grid_cell_row_span="1" style_grid_cell_y_align="stretch">
|
||||||
|
<lv_label text="1/1"/>
|
||||||
|
</lv_obj>
|
||||||
|
|
||||||
<my_card y="125"
|
|
||||||
bg_color="0xffaaaa"
|
|
||||||
action="Apply"
|
|
||||||
btn_rel_style="btn_style"
|
|
||||||
btn_pr_style="btn_pr_style"/>
|
|
||||||
</view>
|
</view>
|
||||||
</component>
|
</component>
|
||||||
@@ -548,7 +548,7 @@ lv_observer_t * lv_label_bind_text(lv_obj_t * obj, lv_subject_t * subject, const
|
|||||||
#if LV_USE_LABEL
|
#if LV_USE_LABEL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind an integer, string, or pointer Subject to a Label.
|
* Bind an integer, string, or pointer Subject to a Spangroup's Span.
|
||||||
* @param obj pointer to Spangroup
|
* @param obj pointer to Spangroup
|
||||||
* @param span pointer to Span
|
* @param span pointer to Span
|
||||||
* @param subject pointer to Subject
|
* @param subject pointer to Subject
|
||||||
@@ -607,7 +607,7 @@ lv_observer_t * lv_dropdown_bind_value(lv_obj_t * obj, lv_subject_t * subject);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind an integer subject to a scales section minimum value
|
* Bind an integer subject to a scales section minimum value
|
||||||
* @param obj pointer to an Scale
|
* @param obj pointer to a Scale
|
||||||
* @param section pointer to a Scale section
|
* @param section pointer to a Scale section
|
||||||
* @param subject pointer to a Subject
|
* @param subject pointer to a Subject
|
||||||
* @return pointer to newly-created Observer
|
* @return pointer to newly-created Observer
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ lv_result_t lv_xml_style_register(lv_xml_component_scope_t * scope, const char *
|
|||||||
if(value[c] == ' ') item_cnt++;
|
if(value[c] == ' ') item_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t * dsc_array = lv_malloc((item_cnt + 1) * sizeof(int32_t)); /*+1 for LV_GRID_TEMPLATE_LAST*/
|
int32_t * dsc_array = lv_malloc((item_cnt + 2) * sizeof(int32_t)); /*+2 for LV_GRID_TEMPLATE_LAST*/
|
||||||
|
|
||||||
char * value_buf = (char *)value;
|
char * value_buf = (char *)value;
|
||||||
item_cnt = 0;
|
item_cnt = 0;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ extern "C" {
|
|||||||
#include "../../misc/lv_types.h"
|
#include "../../misc/lv_types.h"
|
||||||
#if LV_USE_XML
|
#if LV_USE_XML
|
||||||
|
|
||||||
#include "lv_xml.h"
|
|
||||||
#include "lv_xml_utils.h"
|
#include "lv_xml_utils.h"
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
|||||||
@@ -900,7 +900,7 @@ static void apply_styles(lv_xml_parser_state_t * state, lv_obj_t * obj, const ch
|
|||||||
if(value[i] == ' ') item_cnt++;
|
if(value[i] == ' ') item_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t * dsc_array = lv_malloc((item_cnt + 1) * sizeof(int32_t)); /*+1 for LV_GRID_TEMPLATE_LAST*/
|
int32_t * dsc_array = lv_malloc((item_cnt + 2) * sizeof(int32_t)); /*+2 for LV_GRID_TEMPLATE_LAST*/
|
||||||
|
|
||||||
char * value_buf = (char *)value;
|
char * value_buf = (char *)value;
|
||||||
item_cnt = 0;
|
item_cnt = 0;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
static lv_span_overflow_t spangroup_overflow_to_enum(const char * txt);
|
static lv_span_overflow_t spangroup_overflow_to_enum(const char * txt);
|
||||||
static void free_fmt_event_cb(lv_event_t * e);
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
@@ -97,7 +96,7 @@ void lv_xml_spangroup_span_apply(lv_xml_parser_state_t * state, const char ** at
|
|||||||
const char * fmt = lv_xml_get_value_of(attrs, "bind_text-fmt");
|
const char * fmt = lv_xml_get_value_of(attrs, "bind_text-fmt");
|
||||||
if(fmt) {
|
if(fmt) {
|
||||||
fmt = lv_strdup(fmt);
|
fmt = lv_strdup(fmt);
|
||||||
lv_obj_add_event_cb(spangroup, free_fmt_event_cb, LV_EVENT_DELETE, (void *) fmt);
|
lv_obj_add_event_cb(spangroup, lv_event_free_user_data_cb, LV_EVENT_DELETE, (void *) fmt);
|
||||||
}
|
}
|
||||||
lv_spangroup_bind_span_text(spangroup, span, subject, fmt);
|
lv_spangroup_bind_span_text(spangroup, span, subject, fmt);
|
||||||
}
|
}
|
||||||
@@ -117,10 +116,4 @@ static lv_span_overflow_t spangroup_overflow_to_enum(const char * txt)
|
|||||||
return 0; /*Return 0 in lack of a better option. */
|
return 0; /*Return 0 in lack of a better option. */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_fmt_event_cb(lv_event_t * e)
|
|
||||||
{
|
|
||||||
void * fmt = lv_event_get_user_data(e);
|
|
||||||
lv_free(fmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* LV_USE_XML */
|
#endif /* LV_USE_XML */
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void lv_xml_textarea_apply(lv_xml_parser_state_t * state, const char ** attrs)
|
|||||||
|
|
||||||
|
|
||||||
if(lv_streq("text", name)) lv_textarea_set_text(item, value);
|
if(lv_streq("text", name)) lv_textarea_set_text(item, value);
|
||||||
else if(lv_streq("placeholder", name)) lv_textarea_set_placeholder_text(item, value);
|
else if(lv_streq("placeholder_text", name)) lv_textarea_set_placeholder_text(item, value);
|
||||||
else if(lv_streq("one_line", name)) lv_textarea_set_one_line(item, lv_xml_to_bool(value));
|
else if(lv_streq("one_line", name)) lv_textarea_set_one_line(item, lv_xml_to_bool(value));
|
||||||
else if(lv_streq("password_mode", name)) lv_textarea_set_password_mode(item, lv_xml_to_bool(value));
|
else if(lv_streq("password_mode", name)) lv_textarea_set_password_mode(item, lv_xml_to_bool(value));
|
||||||
else if(lv_streq("password_show_time", name)) lv_textarea_set_password_show_time(item, lv_xml_atoi(value));
|
else if(lv_streq("password_show_time", name)) lv_textarea_set_password_show_time(item, lv_xml_atoi(value));
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text);
|
|||||||
* @code
|
* @code
|
||||||
* lv_label_set_text_fmt(label1, "%d user", user_num);
|
* lv_label_set_text_fmt(label1, "%d user", user_num);
|
||||||
* @endcode
|
* @endcode
|
||||||
* @note It ignores `LV_USE_ARABIC_PERSIAN_CHARS`
|
* @note If `LV_USE_ARABIC_PERSIAN_CHARS` is enabled the text will be modified to have the correct Arabic characters in it.
|
||||||
*/
|
*/
|
||||||
void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(2, 3);
|
void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(2, 3);
|
||||||
|
|
||||||
|
|||||||
@@ -209,11 +209,14 @@ void lv_span_set_text_fmt(lv_span_t * span, const char * fmt, ...)
|
|||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
char * text = lv_text_set_text_vfmt(fmt, args);
|
char * text = lv_text_set_text_vfmt(fmt, args);
|
||||||
LV_ASSERT_MALLOC(text);
|
LV_ASSERT_MALLOC(text);
|
||||||
if(text == NULL) return;
|
if(text == NULL) {
|
||||||
|
va_end(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if(span->txt == NULL && span->static_flag) {
|
if(span->txt && !span->static_flag) {
|
||||||
lv_free(span->txt);
|
lv_free(span->txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,11 +270,14 @@ void lv_spangroup_set_span_text_fmt(lv_obj_t * obj, lv_span_t * span, const char
|
|||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
char * text = lv_text_set_text_vfmt(fmt, args);
|
char * text = lv_text_set_text_vfmt(fmt, args);
|
||||||
LV_ASSERT_MALLOC(text);
|
LV_ASSERT_MALLOC(text);
|
||||||
if(text == NULL) return;
|
if(text == NULL) {
|
||||||
|
va_end(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if(span->txt == NULL && span->static_flag) {
|
if(span->txt && !span->static_flag) {
|
||||||
lv_free(span->txt);
|
lv_free(span->txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ lv_span_t * lv_spangroup_add_span(lv_obj_t * obj);
|
|||||||
* Remove the span from the spangroup and free memory.
|
* Remove the span from the spangroup and free memory.
|
||||||
* @param obj pointer to a spangroup object.
|
* @param obj pointer to a spangroup object.
|
||||||
* @param span pointer to a span.
|
* @param span pointer to a span.
|
||||||
|
* @note Note that before calling `lv_spangroup_delete_span`
|
||||||
|
* `lv_observer_remove` needs to be called manually as LVGL can't remove the
|
||||||
|
* binding automatically.
|
||||||
*/
|
*/
|
||||||
void lv_spangroup_delete_span(lv_obj_t * obj, lv_span_t * span);
|
void lv_spangroup_delete_span(lv_obj_t * obj, lv_span_t * span);
|
||||||
|
|
||||||
@@ -100,7 +103,7 @@ void lv_span_set_text(lv_span_t * span, const char * text);
|
|||||||
* @param span pointer to a span.
|
* @param span pointer to a span.
|
||||||
* @param fmt `printf`-like format string
|
* @param fmt `printf`-like format string
|
||||||
*/
|
*/
|
||||||
void lv_span_set_text_fmt(lv_span_t * span, const char * fmt, ...);
|
void lv_span_set_text_fmt(lv_span_t * span, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(2, 3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a static text. It will not be saved by the span so the 'text' variable
|
* Set a static text. It will not be saved by the span so the 'text' variable
|
||||||
@@ -136,7 +139,7 @@ void lv_spangroup_set_span_text_static(lv_obj_t * obj, lv_span_t * span, const c
|
|||||||
* @param span pointer to a span.
|
* @param span pointer to a span.
|
||||||
* @param fmt `printf`-like format string
|
* @param fmt `printf`-like format string
|
||||||
*/
|
*/
|
||||||
void lv_spangroup_set_span_text_fmt(lv_obj_t * obj, lv_span_t * span, const char * fmt, ...);
|
void lv_spangroup_set_span_text_fmt(lv_obj_t * obj, lv_span_t * span, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(3, 4);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a static text. It will not be saved by the span so the 'text' variable
|
* Set a static text. It will not be saved by the span so the 'text' variable
|
||||||
|
|||||||
+21
-21
@@ -1,35 +1,35 @@
|
|||||||
<!--
|
<!--
|
||||||
Example
|
Example
|
||||||
<lv_spangroup mode="fixed">
|
<lv_spangroup mode="fixed">
|
||||||
<lv_spangroup-span text="hello " style="red"/>
|
<lv_spangroup-span text="hello " style="red"/>
|
||||||
<lv_spangroup-span text="world" style="blue"/>
|
<lv_spangroup-span text="world" style="blue"/>
|
||||||
</lv_spangroup>
|
</lv_spangroup>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<widget>
|
<widget>
|
||||||
<api>
|
<api>
|
||||||
<enumdef name="lv_span_overflow">
|
<enumdef name="lv_span_overflow">
|
||||||
<enum name="clip" help=""/>
|
<enum name="clip" help=""/>
|
||||||
<enum name="ellipses" help=""/>
|
<enum name="ellipses" help=""/>
|
||||||
</enumdef>
|
</enumdef>
|
||||||
|
|
||||||
<enumdef name="lv_span_mode">
|
<enumdef name="lv_span_mode">
|
||||||
<enum name="fixed" help=""/>
|
<enum name="fixed" help=""/>
|
||||||
<enum name="expand" help=""/>
|
<enum name="expand" help=""/>
|
||||||
<enum name="break" help=""/>
|
<enum name="break" help=""/>
|
||||||
</enumdef>
|
</enumdef>
|
||||||
|
|
||||||
<prop name="overflow" type="enum:lv_span_overflow" help=""/>
|
<prop name="overflow" type="enum:lv_span_overflow" help=""/>
|
||||||
<prop name="max_lines" type="int" help=""/>
|
<prop name="max_lines" type="int" help=""/>
|
||||||
<prop name="indent" type="int" help=""/>
|
<prop name="indent" type="int" help=""/>
|
||||||
|
|
||||||
<element name="span" type="lv_span" access="add">
|
<element name="span" type="lv_span" access="add">
|
||||||
<prop name="text" type="string" help=""/>
|
<prop name="text" type="string" help=""/>
|
||||||
<prop name="style" type="style" help=""/>
|
<prop name="style" type="style" help=""/>
|
||||||
<prop name="bind_text" help="">
|
<prop name="bind_text" help="">
|
||||||
<param name="bind_text" type="subject"/>
|
<param name="bind_text" type="subject"/>
|
||||||
<param name="fmt" type="string" default="NULL"/>
|
<param name="fmt" type="string" default="NULL"/>
|
||||||
</prop>
|
</prop>
|
||||||
</element>
|
</element>
|
||||||
</api>
|
</api>
|
||||||
</widget>
|
</widget>
|
||||||
Reference in New Issue
Block a user