Get the absolute coordinates of the center of an object

Description

How do I get the center of an object ?

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

Any. I’m using Micropython, but I gather this applies also to C.

What do you want to achieve?

I would like to get the center coordinates of an object. As far as I can tell the get_x etc. method only gives coordinates relative to the enclosing object. Is there an API for that, or do I have to recurse through the objects until I get to the enclosing screen?

lv_obj_get_coords should give you the object’s area relative to the screen. If you want the center point you can then get the midpoint between x1 and x2, as well as y1 and y2.

Thank you. I had not quite understood how get_coords worked. Especially since I did not quite understand what was meant by area. So in Micropython someone could write something like:

ar = area_t()
obj.get_coords(ar)
x_mid = (ar.x1+ar.x2)//2
y_mid = (ar.y1+ar.y2)//2

One question though: are the two points described in area_t the upper left/lower right points of the object? So one would have obj.get_width() and ar.x2-ar.x1+1 equal?

That’s correct.