Get size 0 from object

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Read the

Delete this section if you read and applied the mentioned points.


I’m new to lvgl and tried to do some modification on the demo files. And this fits. Now I’m tried to do some more modification and run in a problem.
I generate just an object and set values for height, width and position. For simualtion is set display size 240x320. In simulation I can see an empty “body” at the expected position and with the expected size.
But when I read back the width and height of the object, I get 0 as height and width.
In cause of the “right looking” in simulation, I would expect to see the values in the object by debugger. But there is nothing to see. So I’m confused.
The nearly same code is used in lvgl-academy in the widget-base-object

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

WindowsSimulation, VisualStudio22

What do you want to achieve?

I would expect to see the setted values, if I use the lv_obj_get_height or _width

What have you tried so far?

Code to reproduce

    lv_obj_t* obj1 = lv_obj_create(lv_scr_act());
    lv_obj_set_width(obj1, 50);
    lv_obj_set_height(obj1, 50);
    lv_obj_set_pos(obj1, 100, 100);

    lv_coord_t w = lv_obj_get_width(obj1);
    lv_coord_t h = lv_obj_get_height(obj1);
    printf("width = %d, height = %d\n", w,h);

The output:
width = 0, height = 0

Screenshot and/or video


It’s the expected behavior. See

Hi @kisvegabor,
thank you for your evidence. I wasn’t aware of this mechanism. This tip works.
Thank you

By this I have second question:
This “update” is triggered always topdown. If i would resize parent-object, all child-objects will recalculated/reordered/… . Right?

Actually the whole screen of obj will be updated as the position and size of an object can depend on both its children an parents.


ok. That’s what I understand.

Thank you

The problem here, is that pair of set/get APIs is used to access what are actually two different variables: the requested width/height/x/y, and the actual computed values.

It’s documented, but the behaviour is wrong and should be fixed.