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

Permit to highlight selectable programmatically #7820

Closed
wants to merge 3 commits into from
Closed

Permit to highlight selectable programmatically #7820

wants to merge 3 commits into from

Conversation

rherilier
Copy link
Contributor

@rherilier rherilier commented Jul 26, 2024

Hello,

This PR aims to permit rendering a selectable item as it was hovered even if the mouse cursor is not over it. My own use is as follow:

  • a listbox (showing a set of 3D objects) which behave as normal;
  • a rendering view which triggers the highlighting in the listbox when the mouse cursor is over an object.

It is done by adding a new parameter to ImGui:::Selectable(const char*, bool, ...) to control the highlighting and by making this function handles the hovered state as highlighted because the mouse cursor is over it. The 2 new overloaded functions are only there to avoid breaking the public API (or so I hope)

Here is a video taken from the list boxes demo where the first list box triggers the highlighting in the second one:

highlighting-selectable.mp4

Any correction/feedback are welcome.

Best regards.

Edit: the video was not displayed...

@ocornut
Copy link
Owner

ocornut commented Jul 26, 2024

Hello,

I don't quite understand this. The bool selected parameter is already designed to do this.
If you really need to use the Hovered color vs the Active one, you can use bool selected and use PushStyleCol() to alter the color.

The change of API is unfortunately unacceptable: bool already tend to be a major API issue, let alone bool with default values, let alone new signatures introducing new bools in the middle of existing bools.

However, we could consider introducing new flags e.g. ImGuiSelectableFlags_SelectedUseHoveredColor, that would solve the problem with signature and facilitate this use case.

@rherilier
Copy link
Contributor Author

Thank for the fast reply.

Sorry, I had understood selected as in others GUI's semantic, not a way to simply highlight items. And using a new flag is way way more simple... my bad (twice).

Do I close this PR and create a new one or can I recycle it for a whole new commit set?

What about the first commit, do I keep it?

best regards

@rherilier
Copy link
Contributor Author

About your idea of a ImGuiSelectableFlags_SelectedUseHoveredColor, a ImGuiSelectableFlags_ForceHovered would be more meaningful according to ImGui's internals but from a user point of view, ImGuiSelectableFlags_ForceHighlight would be far better.

@ocornut
Copy link
Owner

ocornut commented Jul 26, 2024

You are right, it might be a ImGuiSelectableFlags_Highlight flag as well.

Sorry, I had understood selected as in others GUI's semantic

In most cases until now _Selected doesn't have any other effect than drawing with this color.
However, with multi-select feature enabled it does have a stronger meaning, and for this case only it makes sense to say that using _Selected+pushing a color change is perhaps not desirable. So _Highlight seems needed.

@rherilier
Copy link
Contributor Author

updated to use the proposed flag ImGuiSelectableFlags_Highlight

ocornut pushed a commit that referenced this pull request Jul 29, 2024
…ems independently from the hovered state. (#7820)

Demo: Make the Widget/List boxes show how to use forced highlighting.
@ocornut
Copy link
Owner

ocornut commented Jul 29, 2024

Thank you, merged as c7b9256 with minor changes (const bool highlighted = declaration closer to usage, made the highlight demo optional with a checkbox).

@ocornut ocornut closed this Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants