Get real size of GUI node

When a Gui node is scaled because of the adjust mode the size and scale properties of the node does not change. I would like to have some way of getting the size of the node as it appears in different aspect ratios and screen sizes.

EDIT: This includes getting the width and height of the gui area because I only get the preset values there as well.

2 Likes

Maybe somebody know how to recive “real scale” or calculate zoom adjust mode scale for gui node?
I need to use spine animation in gui and I want send position and scale data from gui script to GO script.

As I understand the adjust mode “zoom” calculated as:

math.max(render.get_window_width()/render.get_width(), render.get_window_height()/ render.get_height())

Am I right?

Up! this post. (Do not ignore, pls.)

Recive real gui node size or gui scale is really useful thing.
and one more thisng:
Defold have no method to convert world coordinates to gui coordinates.

Please forgive me if this has been answered somewhere else, but this is something I’m also having trouble with.

When in stretch mode the width and height values are correct, but what about zoom and fit?

So after a bit of research the way to calculate the adjusted size of the GUI nodes is as follows:

for zoom:
zoom_factor = math.max(current_width / original_width, current_height / original_height)
size = size * zoom_factor

for stretch:
stretch_x = current_width / original_width
stretch_y = current_height / original_height
size.x = size.x * stretch_x
size.y = size.y * stretch_y

for fit:
fit_factor = math.min(current_width / original_width, current_height / original_height)
size = size * fit_factor

Of course, that’s using the default render

8 Likes