mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-27 20:57:01 +08:00
fix grid layot. Fixes #1442
This commit is contained in:
+8
-22
@@ -551,19 +551,10 @@ static void lv_cont_layout_pretty(lv_obj_t * cont)
|
|||||||
*/
|
*/
|
||||||
static void lv_cont_layout_grid(lv_obj_t * cont)
|
static void lv_cont_layout_grid(lv_obj_t * cont)
|
||||||
{
|
{
|
||||||
lv_obj_t * child;
|
|
||||||
const lv_style_t * style = lv_obj_get_style(cont);
|
const lv_style_t * style = lv_obj_get_style(cont);
|
||||||
lv_coord_t w_tot = lv_obj_get_width(cont);
|
|
||||||
lv_coord_t w_obj = lv_obj_get_width(lv_obj_get_child(cont, NULL));
|
|
||||||
lv_coord_t w_fit = lv_obj_get_width_fit(cont);
|
lv_coord_t w_fit = lv_obj_get_width_fit(cont);
|
||||||
lv_coord_t h_obj = lv_obj_get_height(lv_obj_get_child(cont, NULL));
|
lv_coord_t h_obj = lv_obj_get_height(lv_obj_get_child(cont, NULL));
|
||||||
uint16_t obj_row = (w_fit) / (w_obj + style->body.padding.inner); /*Obj. num. in a row*/
|
|
||||||
lv_coord_t x_ofs;
|
|
||||||
if(obj_row > 1) {
|
|
||||||
x_ofs = w_obj + (w_fit - (obj_row * w_obj)) / (obj_row - 1);
|
|
||||||
} else {
|
|
||||||
x_ofs = w_tot / 2 - w_obj / 2;
|
|
||||||
}
|
|
||||||
lv_coord_t y_ofs = h_obj + style->body.padding.inner;
|
lv_coord_t y_ofs = h_obj + style->body.padding.inner;
|
||||||
|
|
||||||
/* Disable child change action because the children will be moved a lot
|
/* Disable child change action because the children will be moved a lot
|
||||||
@@ -573,24 +564,19 @@ static void lv_cont_layout_grid(lv_obj_t * cont)
|
|||||||
/* Align the children */
|
/* Align the children */
|
||||||
lv_coord_t act_x = style->body.padding.left;
|
lv_coord_t act_x = style->body.padding.left;
|
||||||
lv_coord_t act_y = style->body.padding.top;
|
lv_coord_t act_y = style->body.padding.top;
|
||||||
uint16_t obj_cnt = 0;
|
lv_obj_t * child;
|
||||||
LV_LL_READ_BACK(cont->child_ll, child)
|
LV_LL_READ_BACK(cont->child_ll, child)
|
||||||
{
|
{
|
||||||
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
|
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
|
||||||
|
lv_coord_t obj_w = lv_obj_get_width(child);
|
||||||
|
|
||||||
if(obj_row > 1) {
|
if(act_x + style->body.padding.inner + obj_w > w_fit) {
|
||||||
lv_obj_set_pos(child, act_x, act_y);
|
act_x = style->body.padding.left;
|
||||||
act_x += x_ofs;
|
|
||||||
} else {
|
|
||||||
lv_obj_set_pos(child, x_ofs, act_y);
|
|
||||||
}
|
|
||||||
obj_cnt++;
|
|
||||||
|
|
||||||
if(obj_cnt >= obj_row) {
|
|
||||||
obj_cnt = 0;
|
|
||||||
act_x = style->body.padding.left;
|
|
||||||
act_y += y_ofs;
|
act_y += y_ofs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lv_obj_set_pos(child, act_x, act_y);
|
||||||
|
act_x += style->body.padding.inner + obj_w;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
|
lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
|
||||||
|
|||||||
Reference in New Issue
Block a user