Make an object fill parent container

Description

What MCU/Processor/Board and compiler are you using?

Custom board with a STM32H753 MCU

What LVGL version are you using?

Latest v8.3 release

What do you want to achieve?

I want to make an object fill parent container.

What have you tried so far?

I tried using lv_obj_set_size(obj, lv_obj_get_width(obj), lv_obj_get_height(obj)); however the get_width and get_height functions return 0. If I can I’d like to avoid enabling flex to save on flash space.

Hey,guy! I met the same confusion. lv_obj_get_width(obj) and lv_obj_get_height(obj) return 0,:upside_down_face:. Like this:

    content_obj = lv_obj_create(parent);
    lv_coord_t content_obj_size = meter_width - scale_len * 2 - content_obj_padding * 2;
    lv_obj_set_size(content_obj, content_obj_size, content_obj_size);
    lv_obj_set_style_bg_opa(content_obj, LV_OPA_TRANSP, LV_PART_MAIN | LV_STATE_DEFAULT);

    lv_coord_t w = lv_obj_get_width(content_obj);
    lv_coord_t h = lv_obj_get_height(content_obj);
    char buf[256] = {0};
    lv_snprintf(buf, sizeof(buf), "CONTENT width = %d, height = %d",w, h);
    LV_LOG_INFO(buf);

Have you sloved it?

oh yeah! I found the solution!

It must be to call lv_obj_update_layout function to updata Attribute

https://github.com/lvgl/lvgl/issues/2480

Yeah unfortunately I completely forgot about asking this in the first place; during the last 12 months I’ve encountered this issue a lot of times and came up to the same conclusion but forgot to update this question. Thanks!