components/core2forAWS/tft/lvgl/lvgl/src/lv_widgets/lv_cont.c
static void lv_cont_layout_pretty(lv_obj_t * cont)
{
    lv_layout_t type = lv_cont_get_layout(cont);

    lv_obj_t * child_rs;  /* Row starter child */
    lv_obj_t * child_rc;  /* Row closer child */
    lv_obj_t * child_tmp; /* Temporary child */
    lv_coord_t w_obj         = lv_obj_get_width(cont);
    lv_coord_t act_y         =  lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
    /* Disable child change action because the children will be moved a lot
     * an unnecessary child change signals could be sent*/

    child_rs = _lv_ll_get_tail(&cont->child_ll); /*Set the row starter child*/
    if(child_rs == NULL) return;                /*Return if no child*/

    lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
    lv_coord_t pleft          =  lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN);
    lv_coord_t pright         =  lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN);
    lv_coord_t pinner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);

    child_rc = child_rs; /*Initially the row starter and closer is the same*/
    while(child_rs != NULL) {
        lv_coord_t h_row = 0;
        lv_coord_t w_row = pleft + pright; /*The width is at least the left+right pad*/
        uint32_t obj_num = 0;

        /*Find the row closer object and collect some data*/
        do {
            if(lv_obj_get_hidden(child_rc) == false && lv_obj_is_protected(child_rc, LV_PROTECT_POS) == false) {
                /*If this object is already not fit then break*/
                lv_coord_t w = lv_obj_get_width(child_rc);
                w += lv_obj_get_style_margin_left(child_rc, LV_OBJ_PART_MAIN);
                w += lv_obj_get_style_margin_right(child_rc, LV_OBJ_PART_MAIN);
                if(w_row + w > w_obj) {
                    /*Step back one child because the last already not fit, so the previous is the
                     * closer*/
                    if(child_rc != NULL && obj_num != 0) {
                        child_rc = _lv_ll_get_next(&cont->child_ll, child_rc);
                    }
                    break;
                }
                w_row += w + pinner; /*Add the object width + inner padding*/

                lv_coord_t h = lv_obj_get_height(child_rc);
                h += lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN);
                h += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN);
                h_row = LV_MATH_MAX(h_row, h);         /*Search the highest object*/
                obj_num++;
                if(lv_obj_is_protected(child_rc, LV_PROTECT_FOLLOW))
                    break; /*If can not be followed by an other object then break here*/
            }
            child_rc = _lv_ll_get_prev(&cont->child_ll, child_rc); /*Load the next object*/
            if(obj_num == 0)
                child_rs = child_rc; /*If the first object was hidden (or too long) then set the
                                        next as first */
        } while(child_rc != NULL);

        /*If the object is too long then align it to the middle*/
        if(obj_num == 0) {
            if(child_rc != NULL) {
                lv_style_int_t mtop = lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN);

                lv_obj_align(child_rc, cont, LV_ALIGN_IN_TOP_MID, 0, act_y + mtop);
                h_row = lv_obj_get_height(child_rc); /*Not set previously because of the early break*/
                h_row += mtop;
                h_row += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN);
            }
        }
        /*If there is only one object in the row then align it to the middle*/
        else if(obj_num == 1) {
            lv_obj_align(child_rs, cont, LV_ALIGN_IN_TOP_MID,
                         0,
                         act_y + lv_obj_get_style_margin_top(child_rs, LV_OBJ_PART_MAIN));
        }
        /* Align the children (from child_rs to child_rc)*/
        else {
            w_row -= pinner * obj_num;
            lv_coord_t new_pinner = (w_obj - w_row) / (obj_num - 1);
            lv_coord_t act_x    = pleft; /*x init*/
            child_tmp           = child_rs;
            lv_align_t align;
            int32_t inv;
            if(lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL) {
                align = LV_ALIGN_IN_TOP_RIGHT;
                inv = -1;
            }
            else {
                align = LV_ALIGN_IN_TOP_LEFT;
                inv = 1;
            }
            while(child_tmp != NULL) {
                if(lv_obj_get_hidden(child_tmp) == false && lv_obj_is_protected(child_tmp, LV_PROTECT_POS) == false) {
                    lv_coord_t mleft = lv_obj_get_style_margin_left(child_tmp, LV_OBJ_PART_MAIN);
                    lv_coord_t mright = lv_obj_get_style_margin_right(child_tmp, LV_OBJ_PART_MAIN);
                    switch(type) {
                        case LV_LAYOUT_PRETTY_TOP:
                            lv_obj_align(child_tmp, cont, align,
                                         inv * (act_x + mleft),
                                         act_y + lv_obj_get_style_margin_top(child_tmp, LV_OBJ_PART_MAIN));
                            break;
                        case LV_LAYOUT_PRETTY_MID:
                            lv_obj_align(child_tmp, cont, align,
                                         inv * (act_x + mleft),
                                         act_y + (h_row - lv_obj_get_height(child_tmp)) / 2);

                            break;
                        case LV_LAYOUT_PRETTY_BOTTOM:
                            lv_obj_align(child_tmp, cont, align,
                                         inv * (act_x + mleft),
                                         act_y + h_row - lv_obj_get_height(child_tmp) - lv_obj_get_style_margin_bottom(child_tmp, LV_OBJ_PART_MAIN));
                            break;
                        default:
                            break;
                    }

                    act_x += lv_obj_get_width(child_tmp) + new_pinner + mleft + mright;
                }
                if(child_tmp == child_rc) break;
                child_tmp = _lv_ll_get_prev(&cont->child_ll, child_tmp);
            }
        }

        if(child_rc == NULL) break;
        act_y += pinner + h_row;           /*y increment*/
        child_rs = _lv_ll_get_prev(&cont->child_ll, child_rc); /*Go to the next object*/
        child_rc = child_rs;
    }
    lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
}
/**
 * Handle the pretty layout. Put as many object as possible in row
 * then begin a new row
 * @param cont pointer to an object which layout should be handled
 */
Handle the pretty layout. Put as many object as possible in row
then begin a new row
@param cont pointer to an object which layout should be handled
Handle the pretty layout . Put as many object as possible in row then begin a new row @param cont pointer to an object which layout should be handled
static void lv_cont_layout_pretty(lv_obj_t * cont)
{
    lv_layout_t type = lv_cont_get_layout(cont);
    lv_obj_t * child_rs;  
    lv_obj_t * child_rc;  
    lv_obj_t * child_tmp; 
    lv_coord_t w_obj         = lv_obj_get_width(cont);
    lv_coord_t act_y         =  lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
    child_rs = _lv_ll_get_tail(&cont->child_ll); 
    if(child_rs == NULL) return;                
    lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
    lv_coord_t pleft          =  lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN);
    lv_coord_t pright         =  lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN);
    lv_coord_t pinner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
    child_rc = child_rs; 
    while(child_rs != NULL) {
        lv_coord_t h_row = 0;
        lv_coord_t w_row = pleft + pright; 
        uint32_t obj_num = 0;
        do {
            if(lv_obj_get_hidden(child_rc) == false && lv_obj_is_protected(child_rc, LV_PROTECT_POS) == false) {
                lv_coord_t w = lv_obj_get_width(child_rc);
                w += lv_obj_get_style_margin_left(child_rc, LV_OBJ_PART_MAIN);
                w += lv_obj_get_style_margin_right(child_rc, LV_OBJ_PART_MAIN);
                if(w_row + w > w_obj) {
                    if(child_rc != NULL && obj_num != 0) {
                        child_rc = _lv_ll_get_next(&cont->child_ll, child_rc);
                    }
                    break;
                }
                w_row += w + pinner; 
                lv_coord_t h = lv_obj_get_height(child_rc);
                h += lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN);
                h += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN);
                h_row = LV_MATH_MAX(h_row, h);         
                obj_num++;
                if(lv_obj_is_protected(child_rc, LV_PROTECT_FOLLOW))
                    break; 
            }
            child_rc = _lv_ll_get_prev(&cont->child_ll, child_rc); 
            if(obj_num == 0)
                child_rs = child_rc; 
        } while(child_rc != NULL);
        if(obj_num == 0) {
            if(child_rc != NULL) {
                lv_style_int_t mtop = lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN);
                lv_obj_align(child_rc, cont, LV_ALIGN_IN_TOP_MID, 0, act_y + mtop);
                h_row = lv_obj_get_height(child_rc); 
                h_row += mtop;
                h_row += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN);
            }
        }
        else if(obj_num == 1) {
            lv_obj_align(child_rs, cont, LV_ALIGN_IN_TOP_MID,
                         0,
                         act_y + lv_obj_get_style_margin_top(child_rs, LV_OBJ_PART_MAIN));
        }
        else {
            w_row -= pinner * obj_num;
            lv_coord_t new_pinner = (w_obj - w_row) / (obj_num - 1);
            lv_coord_t act_x    = pleft; 
            child_tmp           = child_rs;
            lv_align_t align;
            int32_t inv;
            if(lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL) {
                align = LV_ALIGN_IN_TOP_RIGHT;
                inv = -1;
            }
            else {
                align = LV_ALIGN_IN_TOP_LEFT;
                inv = 1;
            }
            while(child_tmp != NULL) {
                if(lv_obj_get_hidden(child_tmp) == false && lv_obj_is_protected(child_tmp, LV_PROTECT_POS) == false) {
                    lv_coord_t mleft = lv_obj_get_style_margin_left(child_tmp, LV_OBJ_PART_MAIN);
                    lv_coord_t mright = lv_obj_get_style_margin_right(child_tmp, LV_OBJ_PART_MAIN);
                    switch(type) {
                        case LV_LAYOUT_PRETTY_TOP:
                            lv_obj_align(child_tmp, cont, align,
                                         inv * (act_x + mleft),
                                         act_y + lv_obj_get_style_margin_top(child_tmp, LV_OBJ_PART_MAIN));
                            break;
                        case LV_LAYOUT_PRETTY_MID:
                            lv_obj_align(child_tmp, cont, align,
                                         inv * (act_x + mleft),
                                         act_y + (h_row - lv_obj_get_height(child_tmp)) / 2);
                            break;
                        case LV_LAYOUT_PRETTY_BOTTOM:
                            lv_obj_align(child_tmp, cont, align,
                                         inv * (act_x + mleft),
                                         act_y + h_row - lv_obj_get_height(child_tmp) - lv_obj_get_style_margin_bottom(child_tmp, LV_OBJ_PART_MAIN));
                            break;
                        default:
                            break;
                    }
                    act_x += lv_obj_get_width(child_tmp) + new_pinner + mleft + mright;
                }
                if(child_tmp == child_rc) break;
                child_tmp = _lv_ll_get_prev(&cont->child_ll, child_tmp);
            }
        }
        if(child_rc == NULL) break;
        act_y += pinner + h_row;           
        child_rs = _lv_ll_get_prev(&cont->child_ll, child_rc); 
        child_rc = child_rs;
    }
    lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
}
static void lv_cont_layout_pretty ( lv_obj_t * cont ) { lv_layout_t type = lv_cont_get_layout ( cont ) ; lv_obj_t * child_rs ; lv_obj_t * child_rc ; lv_obj_t * child_tmp ; lv_coord_t w_obj = lv_obj_get_width ( cont ) ; lv_coord_t act_y = lv_obj_get_style_pad_top ( cont , LV_CONT_PART_MAIN ) ; child_rs = _lv_ll_get_tail ( & cont -> child_ll ) ; if ( child_rs == NULL ) return ; lv_obj_add_protect ( cont , LV_PROTECT_CHILD_CHG ) ; lv_coord_t pleft = lv_obj_get_style_pad_left ( cont , LV_CONT_PART_MAIN ) ; lv_coord_t pright = lv_obj_get_style_pad_right ( cont , LV_CONT_PART_MAIN ) ; lv_coord_t pinner = lv_obj_get_style_pad_inner ( cont , LV_CONT_PART_MAIN ) ; child_rc = child_rs ; while ( child_rs != NULL ) { lv_coord_t h_row = 0 ; lv_coord_t w_row = pleft + pright ; uint32_t obj_num = 0 ; do { if ( lv_obj_get_hidden ( child_rc ) == false && lv_obj_is_protected ( child_rc , LV_PROTECT_POS ) == false ) { lv_coord_t w = lv_obj_get_width ( child_rc ) ; w += lv_obj_get_style_margin_left ( child_rc , LV_OBJ_PART_MAIN ) ; w += lv_obj_get_style_margin_right ( child_rc , LV_OBJ_PART_MAIN ) ; if ( w_row + w > w_obj ) { if ( child_rc != NULL && obj_num != 0 ) { child_rc = _lv_ll_get_next ( & cont -> child_ll , child_rc ) ; } break ; } w_row += w + pinner ; lv_coord_t h = lv_obj_get_height ( child_rc ) ; h += lv_obj_get_style_margin_top ( child_rc , LV_OBJ_PART_MAIN ) ; h += lv_obj_get_style_margin_bottom ( child_rc , LV_OBJ_PART_MAIN ) ; h_row = LV_MATH_MAX ( h_row , h ) ; obj_num ++ ; if ( lv_obj_is_protected ( child_rc , LV_PROTECT_FOLLOW ) ) break ; } child_rc = _lv_ll_get_prev ( & cont -> child_ll , child_rc ) ; if ( obj_num == 0 ) child_rs = child_rc ; } while ( child_rc != NULL ) ; if ( obj_num == 0 ) { if ( child_rc != NULL ) { lv_style_int_t mtop = lv_obj_get_style_margin_top ( child_rc , LV_OBJ_PART_MAIN ) ; lv_obj_align ( child_rc , cont , LV_ALIGN_IN_TOP_MID , 0 , act_y + mtop ) ; h_row = lv_obj_get_height ( child_rc ) ; h_row += mtop ; h_row += lv_obj_get_style_margin_bottom ( child_rc , LV_OBJ_PART_MAIN ) ; } } else if ( obj_num == 1 ) { lv_obj_align ( child_rs , cont , LV_ALIGN_IN_TOP_MID , 0 , act_y + lv_obj_get_style_margin_top ( child_rs , LV_OBJ_PART_MAIN ) ) ; } else { w_row -= pinner * obj_num ; lv_coord_t new_pinner = ( w_obj - w_row ) / ( obj_num - 1 ) ; lv_coord_t act_x = pleft ; child_tmp = child_rs ; lv_align_t align ; int32_t inv ; if ( lv_obj_get_base_dir ( cont ) == LV_BIDI_DIR_RTL ) { align = LV_ALIGN_IN_TOP_RIGHT ; inv = -1 ; } else { align = LV_ALIGN_IN_TOP_LEFT ; inv = 1 ; } while ( child_tmp != NULL ) { if ( lv_obj_get_hidden ( child_tmp ) == false && lv_obj_is_protected ( child_tmp , LV_PROTECT_POS ) == false ) { lv_coord_t mleft = lv_obj_get_style_margin_left ( child_tmp , LV_OBJ_PART_MAIN ) ; lv_coord_t mright = lv_obj_get_style_margin_right ( child_tmp , LV_OBJ_PART_MAIN ) ; switch ( type ) { case LV_LAYOUT_PRETTY_TOP : lv_obj_align ( child_tmp , cont , align , inv * ( act_x + mleft ) , act_y + lv_obj_get_style_margin_top ( child_tmp , LV_OBJ_PART_MAIN ) ) ; break ; case LV_LAYOUT_PRETTY_MID : lv_obj_align ( child_tmp , cont , align , inv * ( act_x + mleft ) , act_y + ( h_row - lv_obj_get_height ( child_tmp ) ) / 2 ) ; break ; case LV_LAYOUT_PRETTY_BOTTOM : lv_obj_align ( child_tmp , cont , align , inv * ( act_x + mleft ) , act_y + h_row - lv_obj_get_height ( child_tmp ) - lv_obj_get_style_margin_bottom ( child_tmp , LV_OBJ_PART_MAIN ) ) ; break ; default : break ; } act_x += lv_obj_get_width ( child_tmp ) + new_pinner + mleft + mright ; } if ( child_tmp == child_rc ) break ; child_tmp = _lv_ll_get_prev ( & cont -> child_ll , child_tmp ) ; } } if ( child_rc == NULL ) break ; act_y += pinner + h_row ; child_rs = _lv_ll_get_prev ( & cont -> child_ll , child_rc ) ; child_rc = child_rs ; } lv_obj_clear_protect ( cont , LV_PROTECT_CHILD_CHG ) ; }
Handle the pretty layout.
Handle the pretty layout .
/* Row starter child */ /* Row closer child */ /* Temporary child */ /* Disable child change action because the children will be moved a lot
     * an unnecessary child change signals could be sent*/ /*Set the row starter child*/ /*Return if no child*/ /*Initially the row starter and closer is the same*/ /*The width is at least the left+right pad*/ /*Find the row closer object and collect some data*/ /*If this object is already not fit then break*/ /*Step back one child because the last already not fit, so the previous is the
                     * closer*/ /*Add the object width + inner padding*/ /*Search the highest object*/ /*If can not be followed by an other object then break here*/ /*Load the next object*/ /*If the first object was hidden (or too long) then set the
                                        next as first */ /*If the object is too long then align it to the middle*/ /*Not set previously because of the early break*/ /*If there is only one object in the row then align it to the middle*/ /* Align the children (from child_rs to child_rc)*/ /*x init*/ /*y increment*/ /*Go to the next object*/