mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-21 14:32:44 +08:00
feat(xml): add grid support
This commit is contained in:
committed by
Felipe Neves
parent
272da82051
commit
92a51f056f
@@ -573,9 +573,6 @@ It support only integer subjects.
|
||||
|
||||
- :cpp:expr:`lv_dropdown_bind_value(dropdown, &subject)`
|
||||
|
||||
|
||||
.. _change_subject_on_event:
|
||||
|
||||
Scale's Section
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ lv_result_t lv_xml_style_register(lv_xml_component_scope_t * scope, const char *
|
||||
|
||||
lv_style_t * style = &xml_style->style;
|
||||
|
||||
for(int i = 0; attrs[i]; i += 2) {
|
||||
int32_t i;
|
||||
for(i = 0; attrs[i]; i += 2) {
|
||||
const char * name = attrs[i];
|
||||
const char * value = attrs[i + 1];
|
||||
if(lv_streq(name, "name")) continue;
|
||||
@@ -280,7 +281,40 @@ lv_result_t lv_xml_style_register(lv_xml_component_scope_t * scope, const char *
|
||||
else SET_STYLE_IF(grid_cell_row_pos, lv_xml_atoi(value));
|
||||
else SET_STYLE_IF(grid_cell_row_span, lv_xml_atoi(value));
|
||||
else SET_STYLE_IF(grid_cell_y_align, lv_xml_grid_align_to_enum(value));
|
||||
else if(lv_streq(name, "style_grid_column_dsc_array") ||
|
||||
lv_streq(name, "style_grid_row_dsc_array")) {
|
||||
|
||||
uint32_t item_cnt = 0;
|
||||
uint32_t c;
|
||||
for(c = 0; value[c] != '\0'; c++) {
|
||||
if(value[c] == ' ') item_cnt++;
|
||||
}
|
||||
|
||||
int32_t * dsc_array = lv_malloc((item_cnt + 1) * sizeof(int32_t)); /*+1 for LV_GRID_TEMPLATE_LAST*/
|
||||
|
||||
char * value_buf = (char *)value;
|
||||
item_cnt = 0;
|
||||
const char * sub_value = lv_xml_split_str(&value_buf, ' ');
|
||||
while(sub_value) {
|
||||
if(sub_value[0] == 'f' && sub_value[1] == 'r') {
|
||||
dsc_array[item_cnt] = LV_GRID_FR(lv_xml_atoi(sub_value + 3)); /*+3 to skip "fr("*/
|
||||
}
|
||||
else {
|
||||
dsc_array[item_cnt] = lv_xml_atoi(sub_value);
|
||||
}
|
||||
|
||||
item_cnt++;
|
||||
sub_value = lv_xml_split_str(&value_buf, ' ');
|
||||
}
|
||||
dsc_array[item_cnt] = LV_GRID_TEMPLATE_LAST;
|
||||
|
||||
if(lv_streq(name, "style_grid_column_dsc_array")) {
|
||||
lv_style_set_grid_column_dsc_array(style, dsc_array);
|
||||
}
|
||||
else {
|
||||
lv_style_set_grid_row_dsc_array(style, dsc_array);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
LV_LOG_WARN("%s style property is not supported", name);
|
||||
|
||||
@@ -891,6 +891,43 @@ static void apply_styles(lv_xml_parser_state_t * state, lv_obj_t * obj, const ch
|
||||
else SET_STYLE_IF(grid_cell_row_pos, lv_xml_atoi(value));
|
||||
else SET_STYLE_IF(grid_cell_row_span, lv_xml_atoi(value));
|
||||
else SET_STYLE_IF(grid_cell_y_align, lv_xml_grid_align_to_enum(value));
|
||||
else if(lv_streq(prop_name, "style_grid_column_dsc_array") ||
|
||||
lv_streq(prop_name, "style_grid_row_dsc_array")) {
|
||||
|
||||
uint32_t item_cnt = 0;
|
||||
uint32_t i;
|
||||
for(i = 0; value[i] != '\0'; i++) {
|
||||
if(value[i] == ' ') item_cnt++;
|
||||
}
|
||||
|
||||
int32_t * dsc_array = lv_malloc((item_cnt + 1) * sizeof(int32_t)); /*+1 for LV_GRID_TEMPLATE_LAST*/
|
||||
|
||||
char * value_buf = (char *)value;
|
||||
item_cnt = 0;
|
||||
const char * sub_value = lv_xml_split_str(&value_buf, ' ');
|
||||
while(sub_value) {
|
||||
if(sub_value[0] == 'f' && sub_value[1] == 'r') {
|
||||
dsc_array[item_cnt] = LV_GRID_FR(lv_xml_atoi(sub_value + 3)); /*+3 to skip "fr("*/
|
||||
}
|
||||
else {
|
||||
dsc_array[item_cnt] = lv_xml_atoi(sub_value);
|
||||
}
|
||||
|
||||
item_cnt++;
|
||||
sub_value = lv_xml_split_str(&value_buf, ' ');
|
||||
}
|
||||
|
||||
dsc_array[item_cnt] = LV_GRID_TEMPLATE_LAST;
|
||||
|
||||
lv_obj_add_event_cb(obj, lv_event_free_user_data_cb, LV_EVENT_DELETE, dsc_array);
|
||||
|
||||
if(lv_streq(prop_name, "style_grid_column_dsc_array")) {
|
||||
lv_obj_set_style_grid_column_dsc_array(obj, dsc_array, selector);
|
||||
}
|
||||
else {
|
||||
lv_obj_set_style_grid_row_dsc_array(obj, dsc_array, selector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -311,6 +311,9 @@
|
||||
<prop name="flex_track_place" type="enum:lv_flex_align"/>
|
||||
<prop name="flex_grow" type="int"/>
|
||||
|
||||
|
||||
<prop name="grid_column_dsc_array" type="grid_dsc[LV_GRID_TEMPLATE_LAST]"/>
|
||||
<prop name="grid_row_dsc_array" type="grid_dsc[LV_GRID_TEMPLATE_LAST]"/>
|
||||
<prop name="grid_column_align" type="enum:lv_grid_align"/>
|
||||
<prop name="grid_row_align" type="enum:lv_grid_align"/>
|
||||
<prop name="grid_cell_column_pos" type="int"/>
|
||||
|
||||
@@ -296,6 +296,8 @@ Example
|
||||
<prop name="style_flex_track_place" type="enum:lv_flex_align"/>
|
||||
<prop name="style_flex_grow" type="int"/>
|
||||
|
||||
<prop name="style_grid_column_dsc_array" type="grid_dsc[LV_GRID_TEMPLATE_LAST]"/>
|
||||
<prop name="style_grid_row_dsc_array" type="grid_dsc[LV_GRID_TEMPLATE_LAST]"/>
|
||||
<prop name="style_grid_column_align" type="enum:lv_grid_align"/>
|
||||
<prop name="style_grid_row_align" type="enum:lv_grid_align"/>
|
||||
<prop name="style_grid_cell_column_pos" type="int"/>
|
||||
|
||||
Reference in New Issue
Block a user