Better Width control for HorizontalGroup

Issue #137 resolved
Johannes P.
created an issue

It would be nice have have a bit more control over the sizing of HorizontalGroup elements

For example:

[ShowInInspector, HideLabel, DisplayAsString]
[HorizontalGroup("Demo"), PropertyOrder(0)]
public string DynamicInfo
{
    get { return /* Something Dynamically Calculated */ }
}
[HideLabel]
[HorizontalGroup("Demo"), PropertyOrder(1)]
public string SerializedInfo = "This is some serialized info";

Since DynamicInfo can change in size, setting a static width on its HorizontalGroupAttribute is not ideal.


Potential additions

  • HorizontalGroup(width: -1) : The element would try to automatically scale to as small as possible, while still showing the whole element.
  • HorizontalGroup(minWidth: 10, maxWidth: 100) : The element would scale as normal, but would not scale to be larger than maxWidth or smaller than minWidth.

So for DynamicInfo in the above example:

  • Using [HorizontalGroup("Demo", width: -1, minWidth:10, maxWidth: 100)]
    • scales it to the minimum required size, as long as that size is within range [10, 100].
  • Using [HorizontalGroup("Demo", minWidth:10, maxWidth: 100)]
    • scales it as normal (50% of the total width of the group since there is only one other element in the group), as long as that size is within the range [10, 100]
  • Using [HorizontalGroup("Demo", minWidth:10)]
    • scales it as normal, with no upper bound, but it would never become smaller than 10.
  • Using [HorizontalGroup("Demo", width: 20, minWidth: 80, maxWidth: 100)]
    • scales it to a locked size of 80 (min/max Width are respected over width).

Comments (7)

  1. Bjarke Elias Clauson-Kaas Ørrild

    f.png

    We've added MinWidth, MaxWidth, PaddingLeft, and PaddingRight. It'll be there in the next patch.

    Since the LabelWidth attribute is going to be introduced, I've changed it so the HorizontalGroup no longer sets the label width based on the width of the columns. This means that you can now do stuff like this, and still maintain a proper label width which you couldn't do before.

    ff.png

    I've also fixed it so that it no longer adds unwanted padding. (This was a nightmare btw)

    GUILayout.BeginVertical(new GUIStyle()) // Adds unwanted padding you can't get rid of in any pretty way.
    GUILayout.BeginVertical(GUIStyle.none) // Does not.
    

    On a related note, we've also added the InlineProperty attribute which is quite nice for some cases and works well with the HorizontalGroup attribute.

    a.jpg

  2. Log in to comment