Skip to content

ScrollArea scroll state modified by sibling textedit #1531

@sphaerophoria

Description

@sphaerophoria

Describe the bug
If I add a text edit, then a scroll area, typing in the text edit moves the position of the scroll area.
E.g.
scroll_on_text_entry

To Reproduce
Sample program...

use eframe::egui::{self, ScrollArea};

fn main() {
    let native_options = eframe::NativeOptions::default();
    eframe::run_native("My egui App", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))));
}

#[derive(Default)]
struct MyEguiApp {
    input: String,
}

impl MyEguiApp {
    fn new(cc: &eframe::CreationContext<'_>) -> Self {
        // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
        // Restore app state using cc.storage (requires the "persistence" feature).
        // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
        // for e.g. egui::PaintCallback.
        Self::default()
    }
}

impl eframe::App for MyEguiApp {
   fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
       egui::CentralPanel::default().show(ctx, |ui| {
           ui.text_edit_singleline(&mut self.input);
           ScrollArea::vertical()
               .show(ui, |ui| {
                   for i in 0..100 {
                       ui.label(format!("test{}", i));
                   }
               });
       });
   }
}

Expected behavior
Scroll area stays fixed when typing in adjacent boxes

Desktop (please complete the following information):

  • OS: Linux, observed on both Ubuntu 20.04 and Arch Linux

Additional context

  • Typing when the text edit is not selected does not move the scroll area
  • I tried a few workarounds thinking that it might be related to internal state from the text edit leaking into the scroll area
    • Adding id sources to the text edit or the scroll area didn't seem to help
    • Wrapping the text edit within a sub-ui with ui.allocate_rect also doesn't resolve the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions