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

Have a border only around active widgets #4050

Closed
OverShifted opened this issue Apr 17, 2021 · 3 comments
Closed

Have a border only around active widgets #4050

OverShifted opened this issue Apr 17, 2021 · 3 comments
Labels
nav keyboard/gamepad navigation style

Comments

@OverShifted
Copy link

I am using Dear ImGui in my engine for about a year now and today I was spending some time with styles.
I made my UI look like this:
image
That border looks like macOS and IntelliJ's dark theme.

But it looks very bad when all widgets have that border.
I want the border to be only enabled (visible) around "active" (focused) widgets.
Can anyone help me with that?

Thanks for the awesome library btw.

@PathogenDavid
Copy link
Contributor

I do not believe this is something you can easily do today.

If you're willing to modify Dear ImGui slightly, you can get something close to this using the navigation highlights by removing these two lines from ImGui::RenderNavHighlight:

imgui/imgui.cpp

Lines 2858 to 2859 in 936f532

if (g.NavDisableHighlight && !(flags & ImGuiNavHighlightFlags_AlwaysDraw))
return;

(That ImGuiNavHighlightFlags_AlwaysDraw flag is not something you can specify anywhere externally. It's meant to support the range_select feature - #1861)

Here it is with the filter colors box active and a red highlight border:

image

If you want to eliminate that padding or change the thickness, you'd have to further modify ImGui::RenderNavHighlight since those distances are hard-coded.


Worth noting though that depending on how picky you are, the widget with navigation focus may not always match your expectation. For example, when you expect a dropdown the hovered item has navigation focus and the dropdown does not:

image

@ocornut ocornut added style nav keyboard/gamepad navigation labels Apr 26, 2021
@ocornut
Copy link
Owner

ocornut commented Apr 26, 2021

Hello,

Note that "Active" and "Focused" are very different concepts in dear imgui terminology.
Active = being clicked/held or being edited.
Focused = is closer to what is interesting to you.

NavHighlight color seems to be doing what you are looking for, but:

  • Exact thickness/sizing/rounding are not yet configurable (will likely be in Styling v2).
  • As pointed above, you might want to hack RenderNavHighlight() if you really want this soon.
  • Using the mouse currently disable the highlight (again, as pointed above).

For that later thing: the navigation system was originally introduced with the expectation that dear imgui is used as an overlay over an application that already has input going on. so there was a bias toward being able to relinguish keyboard capture (using ESC). Nowadays we have application types that may want to never disable navigation/capture keyboard and never lose that highlight, so those are options we should be adding provided the right design. I suspect it will still be crucial to allow people to unfocus a window and give inputs back to underlying application, but maybe the nav highlight will stay displayed just with a different "unfocused" color.

Ref #3200 #2048 #2009

@OverShifted
Copy link
Author

Thanks, @ocornut, and @PathogenDavid for your help.
I think the best option for me is to wait for "Styling v2" because I don't like making a mess in my code.
Closing this for now.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nav keyboard/gamepad navigation style
Projects
None yet
Development

No branches or pull requests

3 participants