I am trying to make a menu bar outside of the editor for a game, and I have a solution for that. I did some more work and found an answer. Not a good answer, but an answer.
To start, good code practice say to either make your own class or a method to return a TSharedRef so you can put it in declarative slate code, like so:
ChildSlot
[
SNew(SBorder)
[
SNew(SOverlay)
+ SOverlay::Slot()
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
SMenu::MakeMenuBar()
]
]
]
];
Then you make the bar and pass it back in some manner.
All the following code is in a function called MakeMenuBar
We need to set a command list and an extender. In our case, we aren’t actually extending a menu since this is not a module. But you can put an actual extender here.
your command list doesn’t need to have anything it it, but I think I have seen people use a command list to like up the FNewMenuDelegates or function that fire after the buttons are pressed. In any case, this works.
FUICommandList FUICL = FUICommandList();
TSharedPtr<FUICommandList> TSPFUIC;
TSharedPtr<FExtender> TSPFE;
FMenuBarBuilder FMBB = FMenuBarBuilder(TSPFUIC,TSPFE,&FCoreStyle::Get(),FName("none"));
Then add the appropriate dropdowns or any other items you need.
FNewMenuDelegate FileDropDown = FNewMenuDelegate::CreateRaw(this, &SMenu::createFileDropDown);
FMBB.AddPullDownMenu(FText::FromString("File"), FText::FromString("File actions are done here"),FileDropDown);
FNewMenuDelegate EditDropDown = FNewMenuDelegate::CreateRaw(this, &SMenu::createEditDropDown);
FMBB.AddPullDownMenu(FText::FromString("Edit"), FText::FromString("Edit actions on the currently shown data"), EditDropDown);
FNewMenuDelegate ViewDropDown = FNewMenuDelegate::CreateRaw(this, &SMenu::createViewDropDown);
FMBB.AddPullDownMenu(FText::FromString("View"), FText::FromString("Change View info"), ViewDropDown);
Then return the TSharedRef
return FMBB.MakeWidget();
Pros of this method:
- I posted a response to this question.
- It works
Cons of this method:
-I wrote the thing and I’m not sure how it all works.
-FUICommandlist should do something.
-This probably should be it’s own class, or somehow better organized.
-We can only statically call functions, I don’t know how to call functions with arguments.
If you want to complain about this answer and you haven’t posted your own answer, please see Pro #1