How to scroll to a particular button from outside the scrollarea? #4698
Unanswered
UnknownSuperficialNight
asked this question in
Q&A
Replies: 1 comment
-
There is the method Response::scroll_to_me that does that. However, when using egui::CentralPanel::default().show(ctx, |ui| {
let total_rows = 10_000;
let text_style = egui::TextStyle::Body;
let row_height = ui.text_style_height(&text_style);
let spacing = ui.spacing().item_spacing.y;
// let row_height = ui.spacing().interact_size.y; // if you are adding buttons instead of labels.
let response = ui.add(egui::Slider::new(&mut self.scroll_to, 0..=total_rows));
let scroll_to = response.changed().then_some(self.scroll_to);
let mut scroll_area = ScrollArea::vertical();
if let Some(item) = scroll_to {
scroll_area = scroll_area.vertical_scroll_offset(
row_height * item as f32 + spacing * (item.saturating_sub(1) as f32),
);
}
scroll_area.show_rows(ui, row_height, total_rows, |ui, row_range| {
for row in row_range {
let text = format!("Row {}/{}", row + 1, total_rows);
let response = ui.label(text);
if scroll_to == Some(row) {
response.scroll_to_me(Some(egui::Align::Center));
}
}
});
}); Screencast.from.2024-06-24.19-24-09.mp4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this
I want to make a button outside of it that will scroll to a particular row. For example, click button scroll to row 200, etc. Is that possible?
Something like this:
Beta Was this translation helpful? Give feedback.
All reactions