How do I get the size of a widget when its size depends on the child contents?

I’m making a pop-up window describing the properties of an item, and its size depends on the information. It ended up looking like this one, using both Horizontal and Vertical boxes so it automatically adjusts its size around the inner texts.

However, the “Size” value of this widget remains constant, as you can see in the green rectangle, and I cannot anchor and align this other than the top-left-based. If I try to align it against the bottom right, it will end up like this.

Is there any way to do this properly?

1 Like

What are you adding pop-ups to? Viewport or parent them to another widget container?

It’s directly under a canvas panel.

A bit vague, heh. To clarify, let’s assume we dynamically create and add a new widget to a canvas panel. If so:

This would be the equivalent of the canvas’ Size To Content. The slot will utilise the Desired Size of the hosted widget.


Btw, have you explored the actual tooltips feature the engine comes with:

image

While not without flaws and its own somewhat rigid ecosystem, It is one way to automate the process. Afair, it handles pop-ups going off-screen automagically.


Yet another way to handle pop-ups is via a menu anchor widget:

image

The widget is a part of other BP (a widget manages Inventory UI), since only one of them is displayed at a time. So the widget is indirectly created.

And when I get Desired Size of the widget, it just returned (0,0).

But your suggested built-in tooltip feature works on it. I’d still like to have control of it, but this is nice to know. Thanks!

small note: getting DesiredSize get calculated on the next tick, so you need to either add a delay or use of ForceLayoutPass(a bit expensive) if you want it to be in the same execution/tick.

2 Likes

If it’s already sitting in the canvas, flag it as Size To Content. And yes, Force Layout Prepass should work well here. But use it only when the widget is glitching as its size is adjusting. Or you see text spilling out of containers.

2 Likes

Ahh, I didn’t know a such thing as Size to Content, this is the answer! Thank you very much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.