Search Unity

Bug DropdownField popup position

Discussion in 'UI Toolkit' started by Leslie-Young, Jun 24, 2021.

  1. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    Unity 202021.1.7 Preview 14. Runtime UI.

    Maybe this is not a bug and just a "feature" but when the DropDown is in a template and that template's instance is not aligned to 0x0 with the top-most parent then the popups will be out of alignment by that much.

    I have a settings panel for example which is reused in both the main menu and "in-game". In the main menu it works fine since the dropdown's popup is placed in the root which starts at 0x0. But in this scene the dropdown's popup ends up at an offset because it is in that template's "root" element which is centred on screen and thus at some offset from the left.

    I might not be explaining well so here is a screenshot.

    dropdown.png
     
    Last edited: Jun 24, 2021
  2. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    499
    Hi @Leslie-Young ! This looks like a bug to me. Could you please log a bug through the Unity bug reporter (Help/Report a bug...) ?

    Thanks for bringing this up!
     
  3. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    @hugobd I could not reproduce this problem in a simpler bug report project so there might be something more going on to cause this. I've created pretty much the same layout, minus the tabbed view I'm doing in the settings panel. So for all I know it could be related to that view. I'll report back when I figure this one out in case it helps someone else with same problem.
     

    Attached Files:

    HugoBD-Unity likes this.
  4. Leslie-Young

    Leslie-Young

    Joined:
    Dec 24, 2008
    Posts:
    1,148
    @hugobd I've found the problem and submitted a bug report (Case 1345802).

    It is because the "BlurPanel" element you see in first post screenshot is created in C# and then I use the override of "contentContainer" to make it the content container. Recreating that layout in UXML directly, so that the BlurPanel is added in UXML and not created via C#, prevents the DropdownField problem.

    Here is an extract from bug report for the code that leads to bug. In this case I used "VisualElement" for "mainPanel", rather than the "BlurPanel" class, to keep the bug report simpler; but it causes same problem.

    Code (CSharp):
    1. namespace Game.UI
    2. {
    3.     public class PopupPanel_1 : VisualElement
    4.     {
    5.         [UnityEngine.Scripting.Preserve]
    6.         public new class UxmlFactory : UxmlFactory<PopupPanel_1, UxmlTraits> { }
    7.  
    8.         public override VisualElement contentContainer => mainPanel;
    9.  
    10.         protected VisualElement mainPanel;
    11.  
    12.         private const string stylesResource = "GameUI/Styles/PopupPanelStyleSheet";
    13.         private const string ussClassName = "popup-panel";
    14.         private const string ussContainer = ussClassName + "__container";
    15.  
    16.         // ------------------------------------------------------------------------------------------------------------
    17.  
    18.         public PopupPanel_1()
    19.         {
    20.             // panel background
    21.             styleSheets.Add(Resources.Load<StyleSheet>(stylesResource));
    22.             AddToClassList(ussContainer);
    23.  
    24.             // panel (content container)
    25.             mainPanel = new VisualElement();
    26.             mainPanel.AddToClassList(ussClassName);
    27.             hierarchy.Add(mainPanel);
    28.         }
    29.     }
    30. }
     
    HugoBD-Unity likes this.