1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

fix(grid): fix grid positioning with RTL base diraction

This commit is contained in:
Gabor Kiss-Vamosi 2020-11-09 19:58:05 +01:00
parent fab5121ac5
commit cfd0968bfe
3 changed files with 9 additions and 42 deletions

View File

@ -400,7 +400,7 @@ static void item_repos(lv_obj_t * cont, lv_obj_t * item, _lv_grid_calc_t * calc,
x = calc->x[col_pos] + (col_w - (item_w + margin_left - margin_right)) / 2; x = calc->x[col_pos] + (col_w - (item_w + margin_left - margin_right)) / 2;
break; break;
case LV_GRID_END: case LV_GRID_END:
x = calc->x[col_pos + 1] - lv_obj_get_width(item) - margin_right; x = calc->x[col_pos] + col_w - lv_obj_get_width(item) - margin_right;
break; break;
} }
@ -417,7 +417,7 @@ static void item_repos(lv_obj_t * cont, lv_obj_t * item, _lv_grid_calc_t * calc,
y = calc->y[row_pos] + (row_h - (item_h + margin_top + margin_bottom)) / 2; y = calc->y[row_pos] + (row_h - (item_h + margin_top + margin_bottom)) / 2;
break; break;
case LV_GRID_END: case LV_GRID_END:
y = calc->y[row_pos + 1] - lv_obj_get_height(item) - margin_bottom; y = calc->y[row_pos] + row_h - lv_obj_get_height(item) - margin_bottom;
break; break;
} }
@ -504,6 +504,8 @@ static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t plac
pos_array[i + 1] = pos_array[i] + size_array[i] + gap; pos_array[i + 1] = pos_array[i] + size_array[i] + gap;
} }
lv_coord_t total_gird_size = pos_array[track_num - 1] + size_array[track_num - 1] - pos_array[0];
if(reverse) { if(reverse) {
for(i = 0; i < track_num; i++) { for(i = 0; i < track_num; i++) {
pos_array[i] = cont_size - pos_array[i] - size_array[i]; pos_array[i] = cont_size - pos_array[i] - size_array[i];
@ -512,7 +514,7 @@ static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t plac
} }
/*Return the full size of the grid*/ /*Return the full size of the grid*/
return pos_array[track_num - 1] + size_array[track_num - 1] - pos_array[0]; return total_gird_size;
} }

View File

@ -1986,17 +1986,6 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
if(obj->w_set == LV_SIZE_AUTO || obj->h_set == LV_SIZE_AUTO) { if(obj->w_set == LV_SIZE_AUTO || obj->h_set == LV_SIZE_AUTO) {
lv_obj_set_size(obj, obj->w_set, obj->h_set); lv_obj_set_size(obj, obj->w_set, obj->h_set);
} }
/*If the changed children was a grid item refresh this objects grid*/
if(lv_obj_get_grid(obj)) {
lv_obj_t * child = param;
if(child) {
if(_lv_obj_is_grid_item(child)) _lv_grid_full_refresh(obj);
} else {
_lv_grid_full_refresh(obj);
}
}
} }
else if(sign == LV_SIGNAL_SCROLL) { else if(sign == LV_SIGNAL_SCROLL) {
res = lv_event_send(obj, LV_EVENT_SCROLL, NULL); res = lv_event_send(obj, LV_EVENT_SCROLL, NULL);

View File

@ -575,7 +575,7 @@ bool _lv_obj_handle_self_size_chg(struct _lv_obj_t * obj)
} }
/** /**
* Calculate the "auto size". It's `auto_size = max(gird_size, children_size, self_size)` * Calculate the "auto size". It's `auto_size = max(children_size, self_size)`
* @param obj pointer to an object * @param obj pointer to an object
* @param w_out store the width here. NULL to not calculate width * @param w_out store the width here. NULL to not calculate width
* @param h_out store the height here. NULL to not calculate height * @param h_out store the height here. NULL to not calculate height
@ -583,42 +583,18 @@ bool _lv_obj_handle_self_size_chg(struct _lv_obj_t * obj)
void _lv_obj_calc_auto_size(lv_obj_t * obj, lv_coord_t * w_out, lv_coord_t * h_out) void _lv_obj_calc_auto_size(lv_obj_t * obj, lv_coord_t * w_out, lv_coord_t * h_out)
{ {
if(!w_out && !h_out) return; if(!w_out && !h_out) return;
/*Get the bounding box of the children*/
// printf("auto size\n");
/*If no other effect the auto-size of zero by default*/
if(w_out) *w_out = 0;
if(h_out) *h_out = 0;
/*Get the grid size of the object has a defined grid*/
lv_coord_t grid_w = 0;
lv_coord_t grid_h = 0;
if(lv_obj_get_grid(obj)) {
_lv_grid_calc_t calc;
_lv_grid_calc(obj, &calc);
grid_w = calc.grid_w + lv_obj_get_style_pad_left(obj, LV_OBJ_PART_MAIN) + lv_obj_get_style_pad_right(obj, LV_OBJ_PART_MAIN);
grid_h = calc.grid_h + lv_obj_get_style_pad_top(obj, LV_OBJ_PART_MAIN) + lv_obj_get_style_pad_bottom(obj, LV_OBJ_PART_MAIN);
_lv_grid_calc_free(&calc);
}
/*Get the children's most right and bottom position*/
lv_coord_t children_w = 0;
lv_coord_t children_h = 0;
if(w_out) { if(w_out) {
lv_coord_t scroll_right = lv_obj_get_scroll_right(obj); lv_coord_t scroll_right = lv_obj_get_scroll_right(obj);
lv_coord_t scroll_left = lv_obj_get_scroll_left(obj); lv_coord_t scroll_left = lv_obj_get_scroll_left(obj);
children_w = lv_obj_get_width(obj) + scroll_right + scroll_left; *w_out = lv_obj_get_width(obj) + scroll_right + scroll_left;
} }
if(h_out) { if(h_out) {
lv_coord_t scroll_bottom = lv_obj_get_scroll_bottom(obj); lv_coord_t scroll_bottom = lv_obj_get_scroll_bottom(obj);
lv_coord_t scroll_top = lv_obj_get_scroll_top(obj); lv_coord_t scroll_top = lv_obj_get_scroll_top(obj);
children_h = lv_obj_get_height(obj) + scroll_bottom + scroll_top; *h_out = lv_obj_get_height(obj) + scroll_bottom + scroll_top;
} }
/*auto_size = max(gird_size, children_size)*/
if(w_out) *w_out = LV_MATH_MAX(children_w, grid_w);
if(h_out) *h_out = LV_MATH_MAX(children_h, grid_h);
} }
/** /**