Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Foldout layout bug when set it's label text to another

Discussion in 'UI Toolkit' started by ZetanHwang, May 29, 2022.

  1. ZetanHwang

    ZetanHwang

    Joined:
    Oct 11, 2016
    Posts:
    7
    As the gif shows, this happens when I change foldout's label in IMGUIContainer.onGUIHandler.
    The foldout has only a IMGUIContainer, here's the code I use to change label text:
    private void RefreshTitle()
    {
    text = ItemModule.GetName(userData.GetType()) + (errorBef ? "(Something)" : string.Empty);
    MarkDirtyRepaint();
    }
    I call this method in 'onGUIHandler' callback once the error states change.I don't know what to do next, it's this a bug?
     

    Attached Files:

  2. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    360
    Hi!
    Whenever you can check/uncheck the foldout, do you do anything particular regarding styles? Even with a bug, I would expect only the foldout itself to go in a broken state and not the whole thing.
    Thanks!
     
  3. ZetanHwang

    ZetanHwang

    Joined:
    Oct 11, 2016
    Posts:
    7
    I set IMGUIContainer's style by:
    inspector.style.flexGrow = 1;
    Is this the reason?But I don't remember why I write this, lol.And, when that bool property check/uncheck, I will show/hide another property to the right of it, like:
    EditorGUI.PropertyField(leftRect, boolProperty);
    if (boolProperty.boolValue)
    EditorGUI.PropertyField(rightRect, anotherProperty);
     
  4. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    360
    It could be, I don't have enough detail to confirm it.
    The IMGUIContainer should be able to size itself from its content, so unless
    flex-shrink
    is set to 1, the defaults should be enough.
     
  5. ZetanHwang

    ZetanHwang

    Joined:
    Oct 11, 2016
    Posts:
    7
    I have solved this by registering my RefreshTitle() method to EditorApplication.delayCall instead of invoke it immediately.
    So I guess the reason is, when I invoke it immediately, it has conflicts with some internal layout-calculate method and breaks them.
    Anyway, thanks for the reply.
     
    Last edited: Jun 2, 2022
    martinpa_unity likes this.