Skip to content

Fix scroll handle extending outside of ScrollArea - #5286

Merged
lucasmerlin merged 9 commits into
emilk:masterfrom
gilbertoalexsantos:fix-scroll-handle-overlap
Mar 5, 2025
Merged

lucasmerlin merged 9 commits into
emilk:masterfrom
gilbertoalexsantos:fix-scroll-handle-overlap

Conversation

@gilbertoalexsantos

Copy link
Copy Markdown
Contributor

Info

This PR addresses an issue where resizing a scroll handle can lead to unwanted overlap.

It is also happening on the egui-demo.

Screenshot 2024-10-18 at 17 35 25

Cause

Note: The following explanation assumes a vertical scroll; however, the logic applies equally to horizontal scrolling.

When the scroll handle is positioned at the top or bottom of the scroll area and the handle is resized to fit the minimum handle size, there is a risk of overlap. This occurs if the handle’s new size extends beyond the bounds of the scroll area.

Proposed Solution

  1. Check whether increasing the handle size will cause it to overlap with the scroll area.
  2. If an overlap is detected, adjust the handle’s center position by the overlap amount, moving it towards the center of the scroll area.

@github-actions

Copy link
Copy Markdown

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

@lucasmerlin

Copy link
Copy Markdown
Collaborator

While this is a improvement, now it will look like you're at the top while already scrolled done by some amount:

Bildschirmaufnahme.2024-10-20.um.17.22.48.mov

Ideally, the scrollbar position would just be calculated correctly, taking the min size into account.

@lucasmerlin lucasmerlin added egui bug Something is broken labels Oct 20, 2024
@gilbertoalexsantos

Copy link
Copy Markdown
Contributor Author

@lucasmerlin

Oh, you're totally right. I didn't notice this behaviour 🥲

I'll work on a fix for this ☺️

@emilk
emilk marked this pull request as draft October 29, 2024 09:42
@gilbertoalexsantos

Copy link
Copy Markdown
Contributor Author

@lucasmerlin

I did an update to the PR.

1º - I extracted the handle_rect calculation to a function
2º - When calculating the handle position, I take into consideration the handle size (by subtracting it from scroll_bar size)

scroll_use.mp4

@lucasmerlin lucasmerlin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Awesome, it's working perfectly now, thank you for this! 🚀 I think we can merge this once the pipeline succeeds.

@lucasmerlin lucasmerlin changed the title Fix scroll handle overlap Fix scroll handle extending outside of ScrollArea Nov 6, 2024
@lucasmerlin
lucasmerlin marked this pull request as ready for review November 6, 2024 13:10
@gilbertoalexsantos

Copy link
Copy Markdown
Contributor Author

I did two more commits:
1º - Applying rustfmt (ops)
2º - Removing unused import

@lucasmerlin

Copy link
Copy Markdown
Collaborator

Seems like you'll need to do another format. Usually it makes more sense to run rustfmt last after any other changes

@gilbertoalexsantos

gilbertoalexsantos commented Nov 6, 2024

Copy link
Copy Markdown
Contributor Author

Indeed.

I'm using RusRover, and for some reason, the format is different than: cargo fmt. Maybe they are using some format of their own.

@lucasmerlin

Copy link
Copy Markdown
Collaborator

Assuming you mean RustRover, there is a setting to use rustfmt instead:

image

Not sure why they don't enable this by default 🤔

@gilbertoalexsantos

Copy link
Copy Markdown
Contributor Author

Oh... That is nice. I'll toggle it. Thank you ^^

@lucasmerlin

Copy link
Copy Markdown
Collaborator

Sorry, totally forgot about this. I'll merge it now, thank you again!

@lucasmerlin
lucasmerlin merged commit 1dea8fa into emilk:master Mar 5, 2025
@lucasmerlin lucasmerlin added this to the Next Patch Release milestone Mar 5, 2025
@gilbertoalexsantos
gilbertoalexsantos deleted the fix-scroll-handle-overlap branch March 5, 2025 15:23
darkwater pushed a commit to darkwater/egui that referenced this pull request Aug 24, 2025
* [x] I have followed the instructions in the PR template
* Closes emilk#3734

## Info

This PR addresses an issue where resizing a scroll handle can lead to
unwanted overlap.

It is also happening on the egui-demo.

![Screenshot 2024-10-18 at 17 35
25](https://github.com/user-attachments/assets/3a9527d9-fc46-4b25-b95a-9ba2fa54978e)

## Cause

*Note: The following explanation assumes a vertical scroll; however, the
logic applies equally to horizontal scrolling.*

When the scroll handle is positioned at the top or bottom of the scroll
area and the handle is resized to fit the minimum handle size, there is
a risk of overlap. This occurs if the handle’s new size extends beyond
the bounds of the scroll area.

## Proposed Solution

1. Check whether increasing the handle size will cause it to overlap
with the scroll area.
2. If an overlap is detected, adjust the handle’s center position by the
overlap amount, moving it towards the center of the scroll area.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is broken egui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScrollArea's scrollbar goes past frame's borders

2 participants