Skip to content

DRAFT: Popups being clipped bug fix - #989

Draft
rswinkle wants to merge 6 commits into
Immediate-Mode-UI:masterfrom
rswinkle:popup_offscreen_bug_fix
Draft

DRAFT: Popups being clipped bug fix#989
rswinkle wants to merge 6 commits into
Immediate-Mode-UI:masterfrom
rswinkle:popup_offscreen_bug_fix

Conversation

@rswinkle

@rswinkle rswinkle commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This was an idea I had months ago to deal with tooltips going off screen. Basically we add a member to the context to track the window size (requires changes to backends but everything is backward compatible so the backends that I didn't update get the old behavior). With that being updated by the backend, most things follow a relatively obvious sane policy (drop downs flip upward if they don't fit below, menus align with the right edge if they get clipped on the right, scrollbars get introduced only if there's not enough space total, user popups (nk_popup_begin) are fixed etc.) but tooltips are actually the hardest to decide. Right now they behave non-symmetrically.

First place it according to origin and offset. If it overflows on the right/bottom align the cursor with the right/bottom of the tooltip unless that would cause overflow on the left/top. If it's still overflowing the right/bottom, slide it left/up till it lines up with the edge. If x/y < 0 then slide right/down to x/y = 0. So if there's insufficient space for the tooltip, it will always clip the right/bottom rather than the left/top.

This asymmetry is easiest to see using the "Hover for magic" orbiting tooltip:

tooltip_asymmetry.mp4

Honestly it's probably fine as it is, especially since the alternative is losing the content entirely to clipping, but there are arguments to be made for many other policies, symmetric, trying more to take into account the original origin specification, etc. I think this is probably the simplest policy that makes sense though.

Here's a longer video demonstrating the state of everything. I think I covered every type of popup and multiple edges for many, if not insufficient space for all of them:

popup_clipping_bug_fix.mp4

...for determining whether a popup will fit as a dropdown vs needing to
drop "up".

Additionally, pin the direction so a popup menu won't flip back and
forth as you expand/collapse a tree inside of it.
When user given height is less than content height, use that (will have
a scrollbar) so we don't flip unnecessarily

Opposite of Menu example of larger than needed requested height, in
which case we use real content height to determine whether to flip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant