Search Unity

Inspectorelement - Broken Layout

Discussion in 'UI Toolkit' started by rastlin, Apr 12, 2019.

  1. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    I'm trying to write a simple window replacement for default inspector for the time being until whole inspector is using UIElements. I have following code:

    Code (CSharp):
    1. var root = this.GetRootVisualContainer();
    2.             root.Clear();
    3.  
    4.             if (Selection.activeGameObject != null)
    5.             {
    6.                 var allComponents = Selection.activeGameObject.GetComponents<Component>();
    7.  
    8.                 for (int i = 0; i < allComponents.Length; i++)
    9.                 {
    10.                     Label lbl = new Label(allComponents[i].GetType().Name);
    11.                     lbl.style.fontStyleAndWeight = FontStyle.Bold;
    12.                     lbl.style.borderLeftWidth = 2;
    13.                     lbl.style.borderRightWidth = 2;
    14.                     lbl.style.borderTopWidth = 2;
    15.                     lbl.style.borderBottomWidth = 2;
    16.                     lbl.style.borderColor = Color.black;
    17.                     root.Add(lbl);
    18.  
    19.                     InspectorElement inspector = new InspectorElement(allComponents[i]);
    20.                     root.Add(inspector);
    21.                 }
    22.             }
    The layout of controls generated by this code looks a follows:
    upload_2019-4-12_16-59-53.png

    As outlined is the inspector element. We can clearly see that is has flex-grow set to 1. If I set this parameter to 0 via code or using the Debuger I end up with this:
    upload_2019-4-12_17-2-41.png

    This is incorrect, as according to the flex box specification, container should take at least the height of it's children.

    Is this know issue? (Unity 2018.3.9f)
     
  2. etienne_phil_unity

    etienne_phil_unity

    Unity Technologies

    Joined:
    Jan 15, 2019
    Posts:
    16
    Hello, could you please log a bug with a repro project? We may want to look at how Yoga (layout engine) conforms to the flex box specification
     
  3. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    Hello, this is the case link: 1145937 .

    It does not looks like a yoga problem, but similar to good old float: left and clear: both problem in html - maybe InspectorElement is not recalculating it's child controls layout in "proper" moment, after controls has been generated, so it ends up having initial height of 0.
     
  4. rastlin

    rastlin

    Joined:
    Jun 5, 2017
    Posts:
    127
    I can confirm it works correctly now in 2019.1.0f2

    Cheers!