mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Fix Ui::scroll_with_delta only scrolling if the ScrollArea is focused (#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 <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -236,6 +236,7 @@ struct ScrollTo {
|
||||
track_item: usize,
|
||||
tack_item_align: Option<Align>,
|
||||
offset: f32,
|
||||
delta: f32,
|
||||
}
|
||||
|
||||
impl Default for ScrollTo {
|
||||
@@ -244,6 +245,7 @@ impl Default for ScrollTo {
|
||||
track_item: 25,
|
||||
tack_item_align: Some(Align::Center),
|
||||
offset: 0.0,
|
||||
delta: 64.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,6 +260,7 @@ impl super::View for ScrollTo {
|
||||
let mut go_to_scroll_offset = false;
|
||||
let mut scroll_top = false;
|
||||
let mut scroll_bottom = false;
|
||||
let mut scroll_delta = None;
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Scroll to a specific item index:");
|
||||
@@ -294,6 +297,20 @@ impl super::View for ScrollTo {
|
||||
scroll_bottom |= ui.button("Scroll to bottom").clicked();
|
||||
});
|
||||
|
||||
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)
|
||||
}
|
||||
});
|
||||
|
||||
let mut scroll_area = ScrollArea::vertical().max_height(200.0).auto_shrink(false);
|
||||
if go_to_scroll_offset {
|
||||
scroll_area = scroll_area.vertical_scroll_offset(self.offset);
|
||||
@@ -305,6 +322,10 @@ impl super::View for ScrollTo {
|
||||
if scroll_top {
|
||||
ui.scroll_to_cursor(Some(Align::TOP));
|
||||
}
|
||||
if let Some(scroll_delta) = scroll_delta {
|
||||
ui.scroll_with_delta(scroll_delta);
|
||||
}
|
||||
|
||||
ui.vertical(|ui| {
|
||||
for item in 1..=num_items {
|
||||
if track_item && item == self.track_item {
|
||||
|
||||
Reference in New Issue
Block a user