From e98b82323df0812c5785e2078b2931066a95d010 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 18 Nov 2020 12:57:11 +0100 Subject: [PATCH] refactor: flexbox, btnmatrix, chart refactoring --- src/lv_core/lv_flex.c | 16 ++++++++-------- src/lv_core/lv_flex.h | 19 +++++++++++++------ src/lv_core/lv_grid.c | 6 +++--- src/lv_widgets/lv_btnmatrix.c | 1 + src/lv_widgets/lv_checkbox.h | 2 +- src/lv_widgets/lv_table.c | 1 + 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/lv_core/lv_flex.c b/src/lv_core/lv_flex.c index b10f04c78..62ee7f78c 100644 --- a/src/lv_core/lv_flex.c +++ b/src/lv_core/lv_flex.c @@ -63,16 +63,16 @@ void lv_obj_set_flex_dir(lv_obj_t * obj, lv_flex_dir_t flex_dir) _lv_flex_refresh(obj); } -void lv_obj_set_flex_place(lv_obj_t * obj, lv_flex_place_t item_place, lv_flex_place_t track_place) +void lv_obj_set_flex_place(lv_obj_t * obj, lv_flex_place_t main_place, lv_flex_place_t cross_place) { lv_obj_allocate_spec_attr(obj); - if(obj->spec_attr->flex_cont.item_place == item_place && - obj->spec_attr->flex_cont.track_place == track_place) { + if(obj->spec_attr->flex_cont.main_place == main_place && + obj->spec_attr->flex_cont.cross_place == cross_place) { return; } - obj->spec_attr->flex_cont.item_place = item_place; - obj->spec_attr->flex_cont.track_place = track_place; + obj->spec_attr->flex_cont.main_place = main_place; + obj->spec_attr->flex_cont.cross_place = cross_place; _lv_flex_refresh(obj); } @@ -120,13 +120,13 @@ lv_flex_dir_t lv_obj_get_flex_dir(const lv_obj_t * obj) lv_flex_place_t lv_obj_get_flex_item_place(const lv_obj_t * obj) { - if(obj->spec_attr) return obj->spec_attr->flex_cont.item_place; + if(obj->spec_attr) return obj->spec_attr->flex_cont.main_place; else return LV_FLEX_PLACE_START; } lv_flex_place_t lv_obj_get_flex_track_place(const lv_obj_t * obj) { - if(obj->spec_attr) return obj->spec_attr->flex_cont.track_place; + if(obj->spec_attr) return obj->spec_attr->flex_cont.cross_place; else return LV_FLEX_PLACE_START; } @@ -157,7 +157,7 @@ void _lv_flex_refresh(lv_obj_t * cont) lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont, LV_OBJ_PART_MAIN) - lv_obj_get_scroll_x(cont); lv_flex_place_t cross_place = lv_obj_get_flex_track_place(cont); - lv_flex_place_t main_place = cont->spec_attr->flex_cont.item_place; + lv_flex_place_t main_place = cont->spec_attr->flex_cont.main_place; lv_ll_t * ll = _lv_obj_get_child_ll(cont); lv_coord_t * cross_pos = (row ? &abs_y : &abs_x); diff --git a/src/lv_core/lv_flex.h b/src/lv_core/lv_flex.h index a8c31e02f..05a102218 100644 --- a/src/lv_core/lv_flex.h +++ b/src/lv_core/lv_flex.h @@ -62,8 +62,8 @@ typedef struct { uint8_t dir :2; uint8_t wrap :1; uint8_t rev :1; - uint8_t item_place :3; - uint8_t track_place :3; + uint8_t main_place :3; + uint8_t cross_place :3; }lv_flex_cont_t; /********************** @@ -85,12 +85,19 @@ void lv_obj_set_flex_dir(struct _lv_obj_t * obj, lv_flex_dir_t flex_dir); /** * Set how to place the items and the tracks - * @param obj point to a flex container - * @param item_place tells how to distribute the free space among the items in the same track - * @param track_place tells how to distribute the free space among the tracks + * @param obj pointer to a flex container + * @param main_place tells how to distribute the free space among the items in the same track + * @param cross_place tells how to distribute the free space among the tracks * @note if the base direction is RTL and the direction is ROW, LV_FLEX_START means the right side */ -void lv_obj_set_flex_place(struct _lv_obj_t * obj, lv_flex_place_t item_place, lv_flex_place_t track_place); +void lv_obj_set_flex_place(struct _lv_obj_t * obj, lv_flex_place_t main_place, lv_flex_place_t cross_place); + +/** + * Set a minimal gap between items in the main direction. + * @param obj pointer to a flex container + * @param gap the gap in pixels + */ +void lv_obj_set_flex_gap(struct _lv_obj_t * obj, lv_coord_t gap); /** * Make an object flex item, i.e. allow setting it's coordinate according to the parent's flex settings. diff --git a/src/lv_core/lv_grid.c b/src/lv_core/lv_grid.c index f87c9e2e8..7b2bfcff8 100644 --- a/src/lv_core/lv_grid.c +++ b/src/lv_core/lv_grid.c @@ -131,7 +131,7 @@ void lv_obj_report_grid_change(const lv_grid_t * grid) */ void _lv_grid_calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out) { - lv_grid_t * g = lv_obj_get_grid(cont); + const lv_grid_t * g = lv_obj_get_grid(cont); if(g == NULL) return; if(g->col_dsc == NULL || g->row_dsc == NULL) return; if(g->col_dsc_len == 0 || g->row_dsc_len == 0) return; @@ -176,7 +176,7 @@ void _lv_grid_calc_free(_lv_grid_calc_t * calc) */ bool _lv_grid_has_fr_col(struct _lv_obj_t * obj) { - lv_grid_t * g = lv_obj_get_grid(obj); + const lv_grid_t * g = lv_obj_get_grid(obj); if(g->col_dsc == NULL) return false; uint32_t i; @@ -194,7 +194,7 @@ bool _lv_grid_has_fr_col(struct _lv_obj_t * obj) */ bool _lv_grid_has_fr_row(struct _lv_obj_t * obj) { - lv_grid_t * g = lv_obj_get_grid(obj); + const lv_grid_t * g = lv_obj_get_grid(obj); if(g == NULL) return false; if(g->row_dsc == NULL) return false; diff --git a/src/lv_widgets/lv_btnmatrix.c b/src/lv_widgets/lv_btnmatrix.c index 7205c61f2..7068ee6eb 100644 --- a/src/lv_widgets/lv_btnmatrix.c +++ b/src/lv_widgets/lv_btnmatrix.c @@ -15,6 +15,7 @@ #include "../lv_core/lv_refr.h" #include "../lv_themes/lv_theme.h" #include "../lv_misc/lv_txt.h" +#include "../lv_misc/lv_txt_ap.h" /********************* * DEFINES diff --git a/src/lv_widgets/lv_checkbox.h b/src/lv_widgets/lv_checkbox.h index a635dbf0d..1813dcf05 100644 --- a/src/lv_widgets/lv_checkbox.h +++ b/src/lv_widgets/lv_checkbox.h @@ -35,7 +35,7 @@ extern "C" { typedef struct { /*New data for this widget */ lv_style_list_t style_bullet; - char * txt; + const char * txt; uint32_t static_txt :1; } lv_checkbox_ext_t; diff --git a/src/lv_widgets/lv_table.c b/src/lv_widgets/lv_table.c index 77a0c67d3..7ea98c00e 100644 --- a/src/lv_widgets/lv_table.c +++ b/src/lv_widgets/lv_table.c @@ -12,6 +12,7 @@ #include "../lv_misc/lv_debug.h" #include "../lv_core/lv_indev.h" #include "../lv_misc/lv_txt.h" +#include "../lv_misc/lv_txt_ap.h" #include "../lv_misc/lv_math.h" #include "../lv_draw/lv_draw_label.h" #include "../lv_misc/lv_printf.h"