Download

Obtaining widget size when filling space

I need to know the size of widget. If I use GetDesiredSize(), I get the size requested by the children of the widget. However, the widget has no children since the number of children will be determined by the available area in their parent widget. The parent has been told to fill the available space, but I need to know what that size is. Is there a way to do this?

That’s not the way Slate layout works. Desired size is used in the bottom-up size calculation pass and will affect how layout is done. Layout is done afterwards in the ArrangeChildren pass, which will react differently depending on what alignment is used, including the fill alignment.

It sounds like what you want is a panel with some custom child arrangement. But from what little you mention, have you looked at SWrapBox? It basically does what you say, arranges child widgets according to the available size of the panel. If anything, it can probably serve as inspiration to roll out your own panel.

-Camille

SWrap won’t do what I want. And yes, I understand that Slate works from the bottom up. My problem is that ‘the bottom’ children can’t be created until I know how much space is available from the parent.

The children can be created, they just can’t be arranged. I’m not sure what you’re trying to achieve, and it’s probably doable, but you’d be fighting Slate along every step of the way.

I needed something like this for a different reason.
In the end, I created a Blueprint of the widget I required and had it calculate its size on tick and call an event dispatcher if that changed.
It just meant I couldn’t create any children for one whole tick :slight_smile:

There’s another way to do it (though it does run a tick behind) and that’s to create an overload to the widget’s Paint() method. Paint() gets all the dimensions and placement info to the widget.

If you’re overloading Paint, you already have a custom widget/panel? It’d probably be better off using OnArrangeChildren than Paint. And if you need to know child geometries, there’s nothing wrong with calling an ArrangeChildren pass yourself… That’s how a lot of widgets work.

But hey, as long as it works. Dealing with locations and sizes in Slate can be a bit counterintuitive at times and there’s more than one way to do it. :slight_smile: