Scroll to me vs. show rows in scroll area #1789
-
Hi there, I am rather new to GUI programming and Egui. I really appreciate the ease of use! My issue is the following. I am using a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
You should be able to use |
Beta Was this translation helpful? Give feedback.
-
I managed to scroll to the label by calculating a |
Beta Was this translation helpful? Give feedback.
-
I found a solution by subtracting fn make_scroll_area(ui: &mut Ui, idx: usize, scroll_offset: f32) -> f32 {
let text_style = egui::TextStyle::Body;
let row_height = ui.text_style_height(&text_style);
let spacing_y = ui.spacing().item_spacing.y;
let area_offset = ui.cursor();
let y = area_offset.top() + idx as f32 * (row_height + spacing_y);
let target_rect = Rect {
min: Pos2 {
x: 0.0,
y: y - scroll_offset,
},
max: Pos2 {
x: 10.0,
y: y + row_height - scroll_offset,
},
};
ui.scroll_to_rect(target_rect, Some(Align::Center));
let scroll = egui::ScrollArea::vertical()
.show_rows(ui, row_height, n_rows, |ui, row_range| {
for filtered_idx in row_range {
// add labels
}
});
scroll.state.offset.y
} |
Beta Was this translation helpful? Give feedback.
I found a solution by subtracting
ScrollAreaOutput.state.offset.y
from the targetRect
to be used withscroll_to_rect
. Just for reference, I add the following snippet. I assume thatidx
is the index of the label I want to scroll to.