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

Features/treenode span only text #6937

Closed

Conversation

dimateos
Copy link
Contributor

Hello Omar!

Sometimes I use elements in the same line as treenodes, e.g. buttons or checkboxes.
But I find it a bit distractive how the tree hovering highlight overlaps with these.
Related to #6574, how selectable covering buttons seems intuitive.

2023-10-18_(093928)_viewer

So, I wanted to add a simple flag to treenodes to make the highlight limited to the text label.
After a while using it, I polished it and also updated to master branch.
Thought you might find it interesting for a merge :)

2023-10-18_(094029)_viewer

2023-10-18_(094213)_viewer

I named it, ImGuiTreeNodeFlags_SpanOnlyText, in line with the other span related flags ImGuiTreeNodeFlags_SpanAvailWidth and ImGuiTreeNodeFlags_SpanFullWidth

As described in imgui.h: Hovering highlight will only cover the label text and reduces the hitbox to wrap the text tighter (0.5f style.ItemSpacing.x instead of regular 2.0f). Does nothing when any of the following flags is set: ImGuiTreeNodeFlags_Framed, ImGuiTreeNodeFlags_SpanAvailWidth, ImGuiTreeNodeFlags_SpanFullWidth, ImGuiTreeNodeFlags_SpanAllColumns.

Rationale:

  • Tighter hitbox feels more intuitive when the highlight also wraps the text tightly, it also helps to avoid clicking on inline widgets.
  • Does not make much sense to allow smaller framed nodes, but opinionated.
  • There are more and older flags that increase span, so seems to make to give them preference

I added a few lines to the demo to add some inline buttons and showcase the flags.

Ofc, feel free to edit or suggest anything, thanks!

@ocornut ocornut added the tree tree nodes label Oct 18, 2023
@benblo
Copy link

benblo commented Dec 20, 2023

That looks great, I'd like to have that! Also the same SpanOnlyText for Selectable(), can't figure out how to have a selectable inline between two texts, like an hyperlink...

@ocornut
Copy link
Owner

ocornut commented Apr 24, 2024

That looks great, I'd like to have that! Also the same SpanOnlyText for Selectable(), can't figure out how to have a selectable inline between two texts, like an hyperlink...

For this specifically I believe it may be better to use a Markdown widget:
https://github.com/ocornut/imgui/wiki/Useful-Extensions#rich-text

@ocornut
Copy link
Owner

ocornut commented Apr 24, 2024

Hello,
I'll work on merging this PR (requires a bit of work as the code evolved a bit), but just to be sure are you also aware of the ImGuiTreeNodeFlags_AllowOverlap flag?

@ocornut
Copy link
Owner

ocornut commented Apr 24, 2024

I have slightly reworked and merged your commit as b8a44b1. Thank you!

@ocornut ocornut closed this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tree tree nodes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants