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 Display none not applying with margin

Discussion in 'UI Toolkit' started by DarkRewar, Jun 13, 2023.

  1. DarkRewar

    DarkRewar

    Joined:
    Jan 19, 2015
    Posts:
    18
    Hello,

    I found a bug about the layout calc when using margin auto. If an element inside a flex element is in margin auto, the margin still applying when display none.

    See my screenshots: I have a cell containing three elements, two first elements have a width and height, last element is margin auto.

    upload_2023-6-13_12-11-18.png

    But when I apply display none to the last element, its rect stay in layout calc.
    upload_2023-6-13_12-11-15.png

    You can find an exemple to reproduce the bug below (by disabling #Red):

    Code (JavaScript):
    1.  
    2. <ui:VisualElement style="flex-direction: row; justify-content: center;">
    3. <ui:VisualElement name="Blue" style="height: 150px; background-color: rgb(46, 75, 176); flex-grow: 0; width: 150px;" />
    4. <ui:VisualElement name="White" style="height: 150px; flex-grow: 0; background-color: rgb(255, 255, 255); width: 150px;" />
    5. <ui:VisualElement name="Red" style="flex-grow: 0; background-color: rgb(224, 41, 41); margin-left: auto; margin-right: auto; margin-top: 0; margin-bottom: 0; display: flex; width: 150px;" />
    6. </ui:VisualElement>
    7.  
     
  2. laila-chammaa

    laila-chammaa

    Unity Technologies

    Joined:
    May 10, 2022
    Posts:
    28
    Hello!

    Yeah, I see what you mean. Can you please report this bug inside Unity via the menu "Help > Report a bug" ?

    Thank you!
     
  3. DarkRewar

    DarkRewar

    Joined:
    Jan 19, 2015
    Posts:
    18