Search Unity

Can I create my own DropdownMenu?

Discussion in 'UI Toolkit' started by diesoftgames, May 17, 2019.

  1. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    I want to create a drop down menu that shows up after dragging from one VisualElement to another, and I don't see anyway I can make that work with ContextualMenuManipulator, so I started looking into using DropdownMenu directly, but I'm not seeing anything about how to actually display it. Would love some tips on either how to create my own or how to hijack the context menu manipulator beyond what the activation filters can do.
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    57
    Unfortunately, there is a bug in the API that prevent you from displaying a contextual menu without using the
    ContextualMenuManipulator. Normally you would call

    panel.contextualMenuManger.DisplayMenu(triggerEvent, target);


    But contextualMenuManger is currently internal. We plan to fix this in the upcoming releases.
     
  3. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    Thanks, looking forward to that. I'm just working around it for now by having the menu pop up at the start of the action rather than the end. I wonder if this is maybe related to that bug or just this menu stuff being still in flight a bit, but this error randomly pops up (it doesn't always pop up and so I'm not sure of the cause):
    Validate Standard no implemented yet
    [sic]
     
  4. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    57
    Hi! I just searched Unity Editor source code and did not find this string (I searched for the whole string as well as for Validate Standard and no implemented yet.
     
  5. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,440
    I just saw your "Validate Standard no implemented yet" [sic] when playing around with Inspector Gadgets, which does a fair bit of inspector overrides with context menus. Maybe it can help you find a reproduceable case to study. (No, the Inspector Gadgets code doesn't have those strings either, it's somewhere in Unity.)

    Code (CSharp):
    1. [halley@halley14:/Applications/Unity/Unity.app]$ grep -ri "no implemented yet" .
    2. grep: ./Contents/Documentation: No such file or directory
    3. Binary file ./Contents/MacOS/Unity matches
    4.  
     
  6. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    57
    Hey! Last time I checked the current Unity code. I fetched the 2019.1 code and found the string in OSX related code. The output of this string is caused by the menu item validation process. In current code, logic remains the same but the error message was removed.
     
    diesoftgames likes this.