Skip to content

Clamp panel rects to visible bounds#8056

Open
enomado wants to merge 3 commits into
emilk:mainfrom
enomado:fix-panel-overflow-rect
Open

Clamp panel rects to visible bounds#8056
enomado wants to merge 3 commits into
emilk:mainfrom
enomado:fix-panel-overflow-rect

Conversation

@enomado
Copy link
Copy Markdown
Contributor

@enomado enomado commented Apr 2, 2026

Fixes #8055.

When panel contents overflow beyond the visible clamped bounds, the panel response can become larger than the actual visible panel. That oversized response was then reused by integrations for pointer hit-testing, and its rect was also reused internally for cursor advancement, stored panel state, separator painting, and top-level panel allocation.

This change clamps the outward-facing panel response back to the visible panel bounds with intersect(panel_rect), for both response.rect and response.interact_rect. The fix is applied to both SidePanel and TopBottomPanel, so callers using the returned panel response do not inherit oversized clipped-child bounds.

I verified this against a Bevy + bevy_egui integration where a resizable panel with clipped overflow content incorrectly blocked scene interaction and displaced its effective boundary. After this change, the panel hit area and boundary stay aligned with the visible panel edge.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

Preview available at https://egui-pr-preview.github.io/pr/8056-fix-panel-overflow-rect
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@emilk
Copy link
Copy Markdown
Owner

emilk commented Apr 7, 2026

Could you maybe make a regression test for this in tests/egui_tests?

enomado added a commit to enomado/egui that referenced this pull request Apr 7, 2026
Test that SidePanel and TopBottomPanel response.rect and
response.interact_rect are clamped to visible panel bounds
when content overflows.

See: emilk#8056

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@enomado enomado force-pushed the fix-panel-overflow-rect branch from 054cb04 to 3bc91e9 Compare April 7, 2026 09:21
@enomado enomado requested a review from lucasmerlin as a code owner April 7, 2026 09:21
enomado added a commit to enomado/egui that referenced this pull request Apr 7, 2026
Panel `response.rect` and `response.interact_rect` were not clamped to
visible panel bounds when content inside overflowed, causing callers to
receive an oversized rect that broke pointer hit-testing, separator
placement, and available_rect advancement (pushing CentralPanel off-screen).

Fix: intersect both rects with `panel_rect` in `show_inside_dyn`, and
intersect `response.rect` with `available_rect` in `show_dyn`.

Regression test + visual snapshot included.

See: emilk#8056

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@enomado enomado force-pushed the fix-panel-overflow-rect branch from 94c4623 to fa39354 Compare April 7, 2026 09:52
enomado and others added 2 commits April 7, 2026 12:54
Panel `response.rect` and `response.interact_rect` must be clamped to
visible panel bounds even when content inside overflows. Before the fix
callers received an oversized rect that broke pointer hit-testing,
separator placement, and available_rect advancement.

See: emilk#8056

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Intersect `response.rect` and `response.interact_rect` with `panel_rect`
in `show_inside_dyn`, so callers receive correctly-sized rects that match
the visible panel edge. Without this, overflowing content caused the
returned rect to exceed the panel bounds, breaking pointer hit-testing
and pushing CentralPanel off-screen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@enomado enomado force-pushed the fix-panel-overflow-rect branch from fa39354 to ffdf956 Compare April 7, 2026 09:54
@enomado
Copy link
Copy Markdown
Contributor Author

enomado commented Apr 7, 2026

Sorry for this mess with history. perhaps test is added. I checked up screenshots - sort of reproducing the ptoblem

@enomado
Copy link
Copy Markdown
Contributor Author

enomado commented Apr 7, 2026

Related issues that may benefit from or overlap with this fix:

@valadaptive
Copy link
Copy Markdown
Contributor

This is necessary to prevent a regression introduced in v0.34, where the left panel in my application starts growing automatically:

Peek.2026-04-09.02-18.mp4

@emilk emilk added this to the 0.34.2 milestone Apr 9, 2026
@emilk emilk added bug Something is broken layout Related to widget layout egui labels Apr 9, 2026
@emilk
Copy link
Copy Markdown
Owner

emilk commented Apr 9, 2026

This produced some regressions in some existing screenshot tests. I think we may need to dig a bit deeper here. Did anyone do a git bisect to see when this was introduced? Or is this because of a difference in behavior between Panel::show (Context) and Panel::show_inside (Ui)?


let inner_response = self.show_inside_dyn(&mut panel_ui, add_contents);
let rect = inner_response.response.rect;
let rect = inner_response.response.rect.intersect(available_rect);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part necessary? inner_response.response.rect is already clamped by show_inside_dyn, which we call directly above this line.

valadaptive added a commit to valadaptive/egui that referenced this pull request Apr 9, 2026
@lucasmerlin lucasmerlin modified the milestones: 0.34.2, 0.35.0 May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is broken egui layout Related to widget layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resizable Panel stores and paints using overflowed inner rect instead of clamped panel rect

4 participants