Skip to content

Commit

Permalink
Improve scroll by example
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed May 27, 2024
1 parent f8c9592 commit f65eb51
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/egui_demo_lib/src/demo/scrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ struct ScrollTo {
track_item: usize,
tack_item_align: Option<Align>,
offset: f32,
delta: f32,
}

impl Default for ScrollTo {
Expand All @@ -244,6 +245,7 @@ impl Default for ScrollTo {
track_item: 25,
tack_item_align: Some(Align::Center),
offset: 0.0,
delta: 64.0,
}
}
}
Expand Down Expand Up @@ -293,8 +295,19 @@ impl super::View for ScrollTo {
ui.horizontal(|ui| {
scroll_top |= ui.button("Scroll to top").clicked();
scroll_bottom |= ui.button("Scroll to bottom").clicked();
if ui.button("Scroll down by 64px").clicked() {
scroll_delta = Some(64.0 * Vec2::UP); // move contents up
});

ui.horizontal(|ui| {
ui.label("Scroll by");
DragValue::new(&mut self.delta)
.speed(1.0)
.suffix("px")
.ui(ui);
if ui.button("⬇").clicked() {
scroll_delta = Some(self.delta * Vec2::UP); // scroll down (move contents up)
}
if ui.button("⬆").clicked() {
scroll_delta = Some(self.delta * Vec2::DOWN); // scroll up (move contents down)
}
});

Expand Down

0 comments on commit f65eb51

Please sign in to comment.