Set GUI node's size to be same as its texture's size (SOLVED)

Hi All,

I want to change the GUI node’s texture in runtime. And I can use gui.play_flipbook to change it. The problem is when I changed the texture, the GUI node’s size didn’t change to the new texture’s size automatically. How can I know the texture size in runtime? Then I can set the GUI node’s size manually via gui.set_size.

I’m afraid you can’t.

It seems we should have different sizing modes on the nodes. An auto-sizing mode has been requested for a long time, which would make the node take on the size from the texture and thereby disable the size-fields in the editor. So far it has only come up from the fact that it’s very annoying to have to find the image and it’s original size and manually transfer this to the gui node in the editor. From your issue, it seems like there should also be different runtime behaviours as well. Here’s my idea:

  • Fixed - exactly like the current implementation
  • Auto - take on the size of the current animation frame. This would disable the size field in the editor to make it clear that it’s automatic. Any custom setting of the size at runtime would be overridden by the engine. Setting it to another value could also produce a warning in this mode.

“Fixed” could be called “Manual” or “Custom” as well, not sure which one is the most clear.

I was thinking if it would ever be useful to have a setting where the size is fetched from the first animation frame and then kept constant during the course of the animation, but I’m not sure there are any immediate use cases for that. That mode would also be really hard to name, which sort of speaks a bit against it. :smile:

By the way, I completely see “Auto” as being the default for any newly created nodes as that seems to be the common use case, rather than “Fixed”.

Added feature request in JIRA: DEF-1658

1 Like

Yes, “Auto” mode is what I really needed :smile:. I vote for “Manual” instead of “Fixed”. I think “Fixed” may causes a confusion which means it is impossible to set its size, it has been “Fixed”.

As a workaround for now, I have to have a lua table that map texture (flipbook) names and their sizes somewhere, then I can set gui nodes’s size to the correct size.

Thanks :smile:

How many different images are you using? If it’s only a few then maybe you could consider having one box node per image and simple disable the ones you’re not currently using.

This has actually been suggested for quite some time. Internally I found another ticket for this one (DEF-1168) created by Mikael Säker. DEF-1658 appears to supercede this.

You guys are talking about having an “auto mode” for this and while that’s great, I would wish for more control.
This functionality - if I’m not mistaken - is the same thing as what’s called “frame fitting” in Adobe InDesign. There are other layout/design programs as well, such as Quark Xpress and I believe this is called “frame fitting” there as well. Here is a video on how it works - it’s a bit long so you can forward to about 1/3 into the video:
https://helpx.adobe.com/indesign/how-to/indesign-fitting-graphics-to-frames.html

Key things that the user has control over:
-Sizing the container/frame - or in our case: node - to the size of the source image
-Sizing the image to the size of the container (node)
-Sizing the image to the X or Y size of the container, with cropping of the image.

DEF-1658 has been released in current stable, 1.2.78! :slight_smile: Marking this as solved.

1 Like