Skip to content

Fix UI overflow clipping#24073

Closed
chronicl wants to merge 4 commits intobevyengine:mainfrom
chronicl:fix_ui_overflow
Closed

Fix UI overflow clipping#24073
chronicl wants to merge 4 commits intobevyengine:mainfrom
chronicl:fix_ui_overflow

Conversation

@chronicl
Copy link
Copy Markdown
Contributor

@chronicl chronicl commented May 2, 2026

Objective

Overflow clipping currently doesn't respect the ui node's scale.

Solution

Multiply the clipping rectangle by the ui node's scale.

Testing

Added a new example overflow_scale.rs that tests this visually (The actual change is 4 lines, the rest is comments and the example).

Showcase

Before

overflow_scale_WT4F4ovWo4.mp4

After

overflow_scale_QuPQIkdzOn.mp4

@kfc35 kfc35 added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 2, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI May 2, 2026
@kfc35 kfc35 requested review from ickshonpe and kfc35 May 2, 2026 17:08
@kfc35 kfc35 added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label May 2, 2026
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

Works for me!

Copy link
Copy Markdown
Contributor

@ickshonpe ickshonpe left a comment

Choose a reason for hiding this comment

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

This isn't sufficient, the example breaks if the parent node is 200px wide for example. The problem are with the vertex calculations in the renderer.

@ickshonpe ickshonpe added D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged A-Rendering Drawing game state to the screen and removed D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 4, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering May 4, 2026
@chronicl
Copy link
Copy Markdown
Contributor Author

chronicl commented May 4, 2026

I see, I implemented the scaling inside of prepare_uinodes now and fixed the issue that you mentioned (only locally, not in this PR). It's not very complicated, but I saw that this code is duplicated in a lot of different places inside of bevy_ui_render and ideally rotations would be supported too.

I could make this a bandaid fix for only scaling, but I don't want to implement a proper fix that takes rotation into account and deduplicates the vertex attribute logic right now. I only made this PR, because I thought it might be an easy fix, I don't actually need it myself, I'm fine with closing it.

I believe borders are also broken when scaled.

@cart cart closed this May 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Rendering May 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in UI May 5, 2026
@cart cart reopened this May 5, 2026
@github-project-automation github-project-automation Bot moved this from Done to Needs SME Triage in UI May 5, 2026
@github-project-automation github-project-automation Bot moved this from Done to Needs SME Triage in Rendering May 5, 2026
@ickshonpe
Copy link
Copy Markdown
Contributor

I see, I implemented the scaling inside of prepare_uinodes now and fixed the issue that you mentioned (only locally, not in this PR). It's not very complicated, but I saw that this code is duplicated in a lot of different places inside of bevy_ui_render and ideally rotations would be supported too.

I could make this a bandaid fix for only scaling, but I don't want to implement a proper fix that takes rotation into account and deduplicates the vertex attribute logic right now. I only made this PR, because I thought it might be an easy fix, I don't actually need it myself, I'm fine with closing it.

I believe borders are also broken when scaled.

I've started on a full implementation doing CPU using the Sutherland-Hodgman algorithm that handles rotations and non-rectangular clipping regions:
image

clipping-test

(The choppiness and color artifacts are due to the conversion to GIF)

Mostly seems to work, but still needs incremental updates and caching etc. I held back on doing it because I was hoping someone with more rendering expertise would implement a GPU based solution using a stencil buffer, which should be more efficient and could support rounded corners. But after looking into this and #23520, I think it might not be too bad after all.

@chronicl
Copy link
Copy Markdown
Contributor Author

chronicl commented May 5, 2026

Perfect!

@chronicl chronicl closed this May 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Rendering May 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in UI May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants