Skip to content
Discussion options

You must be logged in to vote

I found a solution by subtracting ScrollAreaOutput.state.offset.y from the target Rect to be used with scroll_to_rect. Just for reference, I add the following snippet. I assume that idx is the index of the label I want to scroll to.

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 {

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@paulrouget
Comment options

@bertiqwerty
Comment options

@philpax
Comment options

Answer selected by bertiqwerty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants