Context Menu
OSSIM provides a global context menu system for right-click interactions anywhere in the OS, including the desktop surface and within applications.
Showing a Context Menu
From C++
UContextMenuSubsystem* CM = GameInstance->GetSubsystem<UContextMenuSubsystem>();
TArray<FContextMenuItem> Items;
FContextMenuItem OpenItem;
OpenItem.Label = FText::FromString("Open");
OpenItem.OnSelected.BindLambda([]() { /* handle open */ });
Items.Add(OpenItem);
Items.Add(FContextMenuItem::Separator());
FContextMenuItem DeleteItem;
DeleteItem.Label = FText::FromString("Delete");
DeleteItem.OnSelected.BindLambda([]() { /* handle delete */ });
Items.Add(DeleteItem);
CM->ShowContextMenu(MousePosition, Items);
Context Menu Item (FContextMenuItem)
| Field | Type | Description |
|---|---|---|
Label | FText | Display text for the menu item |
Icon | UTexture2D* | Optional icon |
OnSelected | FOnContextMenuItemSelected | Delegate fired when clicked |
bIsEnabled | bool | Whether the item is clickable (default: true) |
bIsSeparator | bool | Render as a separator line (default: false) |
Static helper: FContextMenuItem::Separator() creates a separator item.
Subsystem API
UContextMenuSubsystem
| Method | Description |
|---|---|
ShowContextMenu(FVector2D, TArray<FContextMenuItem>) | Display menu at viewport position (Z-order: 9999) |
HideContextMenu() | Dismiss the active menu |
IsMenuOpen() | Query whether a menu is currently visible |
Set/GetContextMenuClass() | Configure the widget class used for menus |
Delegate: OnRequestCloseAllMenus() (dynamic/BP) — Broadcast to dismiss all open menus.
Widget Implementation
UContextMenuWidget
PopulateMenu(Items[])— Builds menu item rows.SetPosition(Pos)— Positions the menu at screen coordinates.- Auto-dismisses on focus loss or mouse leave.
UContextMenuItemWidget
Setup(FContextMenuItem)— Configures display and click handler.OnButtonClicked→ invokesOnSelecteddelegate.
Desktop Integration
The UDesktopSurfaceWidget provides a built-in desktop right-click menu with:
- "Change Wallpaper" — Opens wallpaper selection.
- "Open Desktop in Explorer" — Launches File Explorer at the user's desktop path.
