1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Quickly animate scroll when calling ui.scroll_to_cursor etc (#4119)

Uses ease-in-ease-out interpolation, with a time between 0.1s and 0.3s,
depending on the distance needed to scroll.


![smooth-scroll-to-target](https://github.com/emilk/egui/assets/1148717/c5c8556d-476b-4597-842b-aa0e5927fbb9)
This commit is contained in:
Emil Ernerfeldt
2024-03-04 20:00:13 +01:00
committed by GitHub
parent e29022efc4
commit 18eeb01f57
6 changed files with 141 additions and 22 deletions

View File

@@ -252,6 +252,8 @@ impl super::View for ScrollTo {
fn ui(&mut self, ui: &mut Ui) {
ui.label("This shows how you can scroll to a specific item or pixel offset");
let num_items = 500;
let mut track_item = false;
let mut go_to_scroll_offset = false;
let mut scroll_top = false;
@@ -260,7 +262,7 @@ impl super::View for ScrollTo {
ui.horizontal(|ui| {
ui.label("Scroll to a specific item index:");
track_item |= ui
.add(Slider::new(&mut self.track_item, 1..=50).text("Track Item"))
.add(Slider::new(&mut self.track_item, 1..=num_items).text("Track Item"))
.dragged();
});
@@ -304,7 +306,7 @@ impl super::View for ScrollTo {
ui.scroll_to_cursor(Some(Align::TOP));
}
ui.vertical(|ui| {
for item in 1..=50 {
for item in 1..=num_items {
if track_item && item == self.track_item {
let response =
ui.colored_label(Color32::YELLOW, format!("This is item {item}"));