UI Constraint: Size parent to children or text bounds extents

It’d be very burden-relieving to have constraints that set the size of their parent automatically based on content (e.g. Android’s wrap_content size setting in UI layout files):

  1. A UI constraint that automatically sets the size of its parent along a given axis to the total extent of its visible children along that given axis

  2. The above, but for updating ScrollingFrame.CanvasSize (such as in this suggestion UIGridLayout should automatically adjust the CanvasSize of a scrolling frame to suit it's needs)

  3. A TextLabel & TextButton constraint that automatically sets the size of its parent (along a given axis) to a given axis of the TextBounds


For example, the GUI below uses a UIListLayout to line all these items up:

However, since the number and the text inside the blue button change arbitrarily at times, the sizes of the orange and white TextLabels have to be updated to their new horizontal TextBounds (hence suggestion #3).

In the case of the blue button, it also has to update the button’s horizontal size to fit the change, and it has to take into account the button’s children: the ImageLabel for the little icon, the updated TextLabel, and the sizes of multiple Frames inserted for spacing, hence suggestion #1.

Currently this requires manual programming (although snippets of code can be reused most of the time), and it can be pretty annoying at times when you’re just trying to put together a GUI, since sometimes getting the right behavior can be tricky when you put together size changing, text sizing, & event-based triggering.

It’d be really really great if we could avoid these issues altogether so that building GUIs that seem pretty straightforward doesn’t take as long as it currently does :grinning:


Updated to include examples and clearer descriptions since the demand for this seems to be larger than myself and it’s pretty time-consuming after all :thumbsup:

22 Likes

As @GigsD4X already laid out: Having a constraint / layout object that can be parented to any UIElement which automatically resizes said element to encompass the total area which the contents occupy would be extremely helpful (this applies to TextLabels being resized to TextBounds and Frames being resized to fit their contents, etc.).

My reasons are fairly similar to those listed in the post;
Say I have a frame with a coloured background that would utilise a UIListLayout for its children, the frame doesn’t resize to accompany the total space recently taken by the elements within and thus the background is still set at the size prior to the UIListLayout making alterations to the childrens’ positions. If I would want this behaviour to take affect I would have to calculate the farthest left point and then the farthest right and get the distance between the two and THEN set the size of the frame to that distance. This process has to be done anytime the elements change (either being set via code, altered by a constraint / layout, or resolution changes).

I believe that several games suffer from having to do the same (although this process may have been streamlined / generalised already) and this feature should be added to the arsenal of pre-existing layouts / constraints: It would also be a VERY welcome addition.

5 Likes