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

Fix scroll handle extending outside of ScrollArea #5286

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

gilbertoalexsantos
Copy link

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.

Copy link

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
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
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
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

Copy link
Collaborator

@lucasmerlin lucasmerlin left a comment

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
Author

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

@lucasmerlin
Copy link
Collaborator

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

@gilbertoalexsantos
Copy link
Author

gilbertoalexsantos commented Nov 6, 2024

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
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
Author

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

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