Nested toolbar / dropdown menus

Hello I’m using UIElements in editor only on 2019.4.11f.

I’ve searched through the forums and git UIElements examples and everywhere else I can find. What’s the procedure for nested toolbar items like we see in the main Unity toolbar and context menus?

As in I could select [File] → [Recent Items] in the main menu item and then recent items on hover would open up a new menu to the right of the other menu.

It seems like I can only add string actions.

I don’t think it should be so bad to write my own custom toolbar menus through VisualElements and manage my own positions and states but I feel like this should be somewhere in the default toolbar elements?

Oh hey nice I found it. Turns out it’s just a nice hidden feature that I should have guessed since it’s used in other Unity dropdown patterns.

Perhaps this could be added to examples somewhere?

 var recentlyOpened = Workspace.GetRecent();

            foreach(var graph in recentlyOpened) {
                fileMenu.menu.AppendAction("Recent/" + graph.name, (a) => { }, DropdownMenuAction.Status.Normal);
            }

To do nested menus just put slashses in the path. “Recent/Graph 1”

1 Like