Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set default focus when using ImGui::BeginMainMenuBar and navigating using gamepad controller #2352

Closed
PaulSES opened this issue Feb 16, 2019 · 2 comments
Labels
focus menus menu bars, menu items nav keyboard/gamepad navigation

Comments

@PaulSES
Copy link

PaulSES commented Feb 16, 2019

segross/UnrealImGui
Version: 1.65
UE4 Windows 64 bit
Operating System: Windows 10 64bit

If using a gamepad to navigate main menu bar there seems to be no way to set focus to the first selection on the menu bar. Other items seem to accept focus correctly.

Have checked the demos and have noticed that the only way to navigate, initially, to the menu bar is to use mouse. Once there it is possible to continue to navigate the menu bar using gamepad again correctly, until it looses focus.

	if (ImGui::BeginMainMenuBar())
	{
		if (ImGui::BeginMenu("Level"))
		{
			// Focus here
			ImGui::SetKeyboardFocusHere();

			if (ImGui::MenuItem("Restart Level"))
			{
				AGameModeBase* ourGameMode = Cast<AGameModeBase>(GetWorld()->GetAuthGameMode());
				checkf(ourGameMode, TEXT("Failed to get the game mode"));
				ourGameMode->RestartGame();
			}

			// Level menu
			ImGui::EndMenu();
		}

		// Pawns
		if (ImGui::BeginMenu("Pawns"))
		{
			if (ImGui::MenuItem("Change Player 0 Pawn"))
			{
				// To be implemented
			}

			if (ImGui::MenuItem("Change Player 1 Pawn"))
			{
				// To be implemented
			} 

			// Pawns
			ImGui::EndMenu();
		}

		// Completed menu bar
		ImGui::EndMainMenuBar();
	}

@ocornut ocornut added nav keyboard/gamepad navigation menus menu bars, menu items focus labels Feb 18, 2019
@ocornut
Copy link
Owner

ocornut commented Feb 18, 2019

(A)
There is indeed currently no way to forward Alt/Square tap from one regular window to the main menu bar which is another window, so you are right you cannot tap Square button to access the main menu bar, only a local menu bar within current window. This is something that I'd like to implement. However you can currently use Ctrl+Tab (hold Square+L/R) to focus another window and access the menu bar this way.

(B)
I think your issue could be related to the bug #343 due to clipping.
You may use an if (IsWindowAppearing()) { ... } block to run the code on the second frame.

However I don't see the use for SetKeyboardFocusHere() on a MenuItem, this function activate the item (e.g. InputText). What you want to use is SetItemDefaultFocus() instead, but your example is confusing because it would be absolutely unnecessary to call SetItemDefaultFocus on the first item of a window since this is will be focused already when using navigation. So maybe I don't understand your issue properly?

(I am aware the focus/nav functions are currently a little bit of a mess pending a redesign/refactor of the API, please excuse it!)

@Tryum
Copy link

Tryum commented Nov 24, 2022

Hi,

Bumping this issue as it's almost 4 years old.

I'm having the same issue with UnrealImGui but could also reproduce on imgui_impl_win32 + imgui_impl_dx12.
The behaviour I'm aiming at is for the main menu bar to get focus at launch, without using X or ctrl+tab to gain focus.
Is it doable ?

Thanks,
Thibault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus menus menu bars, menu items nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

3 participants