Can you combine the current UIConstraints / SizeFromContents etc in some clever way to get a GUI to expand to fill the “rest of the space” in a layout that isn’t taken by “fixed” size elements (Fixed for each instance of the GUI, but variable overall so I can’t hardcode an offset)?
For instance, if I have a GUI which is a list with a button underneath it (whose size may change depending on what text it’s created with), is there any way to make the list take up all the space that isn’t taken up by the “fixed” size buttons without using Lua to manually lay things out on a size change?
My first attempts say no, but there’s enough complexity in the UIConstraints system to leave me with a nagging suspicion that it’s actually possible.
Sorry, if you didn’t see the edits, I didn’t make it very clear at first.
What I want is basically to not have to hardcode the -FixedSize in this pattern, I want the FixedSize to be “read” from the size of another GUI element, like if I have button underneath the list that has 1 or 2 lines of text in it depending on how the dialogue is being used.
In that case, you can’t really do it without using a script to get the size of the ‘fixed’ element.
It’s not really ‘fixed’, you see. You’ll need to add in a Frame.Size = UDim2.new(1,0,1,-TextLabel.AbsoluteSize.Y).
You could solve this by using AnchorPoint and ClipsDescendants - anchor your label to whichever side is on the edge of the frame, the make the size extend far into the opposite direction. Set the ClipsDescendants of the parent frame to clip the bits that extend out of what it should be.
Oh lol, SizeFromContents isn’t actually released yet… it would sure be nice of studio hid it or the wiki told me that rather than it just not seeming to work in my test.
My suspicion was that there may actually be some way to do it with the right combination of UISizeConstraint + UIListLayout + SizeFromContents. For instance, create a UIListLayout for the two items, SizeFromContents it, and put a UISizeConstraint.MinimumSize on it, then in the inner items put some sort of UISizeConstraints on them. Without SizeFromContents it definitely doesn’t seem possible though.
It’s possible to do (pretty clunkily though) using UITableLayout. Set it to fill available space, then insert a UISizeConstraint/UIAspectRatioConstraint into every single cell except the last one, all in a single row.
It might be possible with the updated SizeFromContents API I’m hoping to ship in the next month or so.
Overall, it’s best to do it with scripts right now.
Update (July 2024)
This will be possible to do once flex layout comes out of beta.
To do it, insert a frame to serve as the spacer object, and set its size to zero. Set the correct LayoutOrder so it appears in the spot you want it. Now, add a UIFlexItem as a child of this frame, and set the FlexMode to Grow. As soon as you do that, it should fill up the rest of the space.
Nice. That’s exactly the kind of clever solution I was looking for. Though you’re right that that’s probably a bit too clever to actually use right now.
Is the SizeFromContents API going to include some way to make a TextLabel/Button shrink to fit its text? That’s one of the single most important layout features to have IMO, and it would save a lot of pain / nonsense like using the CalculateTextSize API when the layout engine already has to do that work internally.