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

Activate navigation by default #2048

Closed
blastrock opened this issue Aug 27, 2018 · 4 comments
Closed

Activate navigation by default #2048

blastrock opened this issue Aug 27, 2018 · 4 comments
Labels
nav keyboard/gamepad navigation

Comments

@blastrock
Copy link

Version/Branch of Dear ImGui:

master (73fa5c2)

Back-end file/Renderer/OS:

Back-ends: imgui_impl_opengl3.cpp and custom engine
OS: Linux
Compiler: Clang 6.0

My Issue/Question:

I may have diagnosed this wrong, but it seems to me that if the application just started and navigation has never been used (you never pressed up/down etc), SetItemDefaultFocus does nothing. I couldn't find a way to force navigation to initiate, as if the user had pressed a navigation key once.

Standalone, minimal, complete and verifiable example:

In example_sdl_opengl3/main.cpp

  io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard

// ...
      if (ImGui::Button("Button")) // Buttons return true when clicked (most
                                   // widgets return true when edited/activated)
        counter++;
      ImGui::SetItemDefaultFocus();

Start the application, and the button will not be focused. However, if I use the keyboard to open another window with similar code, it works, the button is focused.

@ocornut ocornut added focus nav keyboard/gamepad navigation and removed focus labels Aug 28, 2018
@ocornut ocornut changed the title SetItemDefaultFocus doesn't work right at the beginning Activate navigation by default Aug 28, 2018
@ocornut
Copy link
Owner

ocornut commented Aug 28, 2018

Hello,

Navigation visuals are activated when using the keyboard/gamepad keys and deactivated when using the mouse.
That is regardless of SetItemDefaultFocus() calls which should be setting the current navigation id but is navigation visuals are disabled you won't see them.

I think we need to design new function calls to alter those state.
They are internally represented by two internal fields in the imgui context:

bool NavDisableHighlight
bool NavDisableMouseHover

In most cases those fields are in opposite state (NavDisableHighlight is false when NavDisableMouseHover is true etc.) but there are a few situations where they aren't, so it's not a simple binary state. We need to clarify this further to be able to design a suitable api.

@blastrock
Copy link
Author

context->NavDisableHighlight = false seems to solve my problem for the moment, thanks!

I would love to have a public API to do that :)

@ice1000
Copy link
Contributor

ice1000 commented Aug 28, 2018

Me too. I have such API in my own imgui extension.

ocornut added a commit that referenced this issue Oct 18, 2024
ocornut added a commit that referenced this issue Oct 18, 2024
…(), ImGuiNavHighlightFlags to ImGuiNavRenderCursorFlags. (#1074, #2048, #7237, #8059, #1712, #7370, #787)

+ referenced in #8057, #3882, #3411, #2155, #3351, #4722, #1658, #4050.
ocornut added a commit that referenced this issue Oct 18, 2024
+ Further internal renaming for consistency.
ocornut added a commit that referenced this issue Oct 18, 2024
…ways. (#1074, #2048, #7237, #8059, #3200, #787)

Note: the NavCursorHideFrames addition is to support 88a3545 even though ConfigNavCursorVisibleAlways is set.
@ocornut
Copy link
Owner

ocornut commented Oct 18, 2024

I have added a few things related to those requests:

  • Nav: added io.ConfigNavCursorVisibleAuto and io.ConfigNavCursorVisibleAlways config options (ab9ce2a).
  • Nav: added SetNavCursorVisible() to override current state (634a7ed).

Technically I think the config options are sufficient for most people.

Other tangentially related options:

  • Nav: added io.ConfigNavEscapeClearFocusItem (7a56b41).
  • Nav: added io.ConfigNavEscapeClearFocusWindow (b001038).
  • And a couple of related fixes for all the above.

Also note, if you have mods using internals, that those two fields have been renamed internally:

  • Terminology has been changed to call this the "nav cursor" more consistently.
  • bool NavDisableHighlight -> became bool NavCursorVisible (with opposite value).
  • bool NavDisableMouseHover -> became bool NavDisableMouseHover

I'm closing this and other related issues as normally solved, but feel free to comment or open new issues if you have question or problem related to those.

@ocornut ocornut closed this as completed Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

3 participants