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

Add some way to specify whether scroll_to_rect etc.. should be animated #4295

Closed
lucasmerlin opened this issue Mar 31, 2024 · 1 comment · Fixed by #4305
Closed

Add some way to specify whether scroll_to_rect etc.. should be animated #4295

lucasmerlin opened this issue Mar 31, 2024 · 1 comment · Fixed by #4305

Comments

@lucasmerlin
Copy link
Collaborator

Egui should allow specifying whether scrolling in a ScrollArea should be animated (and also allow changing the animation duration, although that is not important for my problem)

Is your feature request related to a problem? Please describe.

After #4119 scrolling to a certain offset is always animated, this breaks egui_virtual_list, which relied on scroll_to_rect to instantly update the scroll position. This is necessary when the user scrolls up in a infinite scroll list that loads at the top and new content is added at the top (the scroll position is offset by the height of the new content). If the scroll is animated here, the list unexpectedly jumps for the user.

Describe the solution you'd like
Maybe add an additional parameter to the scroll functions, a bool or maybe a enum like

enum ScrollAnimation {
    None,
    Default,
    Custom(Duration, Easing),
}

I also saw a TODO comment saying this should be made configurable via Style, but that would cause an issue for my crate, if I set the scroll animation duration to zero the user might override this at a later point causing the infinite scroll to break. The user could work around this by only updating the style if scroll_to_* is actually called but this wouldn't be ideal.
Maybe there could be e.g. a scroll_to_rect() with the current signature which uses the value from Style and an additional funciton like scroll_to_rect_animated() that takes the enum from above as an additional argument.

Describe alternatives you've considered
My problem could also be solved by #2783, which would allow me to use scroll_with_delta, which curiously doesn't seem to have an animation (I'm not sure if this is intentional). But due to #2783, scroll_with_delta doesn't work reliably for me.

@lucasmerlin lucasmerlin changed the title Add some way to specify whether scroll_to etc.. should be animated Add some way to specify whether scroll_to_rect etc.. should be animated Mar 31, 2024
@rustbasic
Copy link
Contributor

rustbasic commented Apr 1, 2024

@lucasmerlin

Please also refer to the following:

settings_ui -> Style -> Always scroll the only enabled direction

     ui.style_mut().always_scroll_the_only_direction = false;

emilk added a commit that referenced this issue May 28, 2024
…used (#4303)

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

This introduces the boolean field force_current_scroll_area to
InputState which will be set when scroll_with_delta is called, causing
the ScrollArea to skip the check whether it is focused and always
consume the smooth scroll delta.

* Closes #2783 
* Related to #4295

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
@emilk emilk closed this as completed in c5bea31 Jul 31, 2024
486c pushed a commit to 486c/egui that referenced this issue Oct 9, 2024
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

* Closes emilk#4295

I based this on emilk#4303, I'll rebase once that one gets merged.
hacknus pushed a commit to hacknus/egui that referenced this issue Oct 30, 2024
…used (emilk#4303)

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

This introduces the boolean field force_current_scroll_area to
InputState which will be set when scroll_with_delta is called, causing
the ScrollArea to skip the check whether it is focused and always
consume the smooth scroll delta.

* Closes emilk#2783 
* Related to emilk#4295

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
hacknus pushed a commit to hacknus/egui that referenced this issue Oct 30, 2024
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo cranky`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

* Closes emilk#4295

I based this on emilk#4303, I'll rebase once that one gets merged.
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 a pull request may close this issue.

2 participants