Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing window makes it move #3074

Open
TimonPost opened this issue Jun 12, 2023 · 2 comments
Open

Resizing window makes it move #3074

TimonPost opened this issue Jun 12, 2023 · 2 comments
Labels
bug Something is broken

Comments

@TimonPost
Copy link
Contributor

When resizing a window it can move the window also.

This can be reproduced with egui here https://www.egui.rs/ :

244389019-c7388936-8666-4ee7-9e5d-fbd7ce42c625.mp4
@TimonPost TimonPost added the bug Something is broken label Jun 12, 2023
@Skgland
Copy link

Skgland commented Mar 6, 2024

The effect is even weirder when dragging the right/bottom edge below/right outside the OS/Root Window.

Egui-Window-Resizing.mp4
Program
/* Cargo.toml
[dependencies]
eframe = "0.26.2"
egui = "0.26.2"
*/

fn main() {
    _ = eframe::run_native(
        "Test",
        eframe::NativeOptions::default(),
        Box::new(move |_cc| {
            Box::new(MyApp{})
        }),
    );
}

struct MyApp {}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        
        egui::Window::new("Test").show(ctx, |ui| {
            ui.label("Egui Window")
        });

        egui::CentralPanel::default().show(ctx, |ui| {
            ui.label("OS/WM Window")
        });
    }
}

@MeGaGiGaGon
Copy link
Contributor

I dug into trying to fix this, and have found why it occurs, but am stumped on how to fix it. There are two separate problems at work, but they both stem from doing the resizing before layouting.

For the movement when resizing the top/left sides on a min sized window, this happens because:

  1. Resizing happens before layouting to prevent a 1 frame delay
  2. Thus the minimum size of the window isn't known, so the Area's top left point gets set to the new position
  3. The layouting then happens, putting the window back to the original size to fit the contents
  4. This ends up looking like a translation since it all happens in a single frame

This doesn't happen normally when resizing the bottom/right sides, since they don't touch the top left corner, and the window gets put back to the minimum size after layouting, so it looks like nothing happened.

When resizing the bottom/right side beyond the window, the weird movement happens because of the default window constraints. The constraint is applied to the new pre-layout Area rect, so the top left point is moved upwards to compensate. Then layouting happens, resizing the window back down since it doesn't use that space, making it look like a translation once again since it all happens in one frame. This can be verified by setting .constrain(false) on the window, which stops the bug.

I'm not sure how to fix either of these, at least while keeping the constraint of 0 delay resizing. If the previous frame's Area size is used, then the window could never be resized smaller. If the min possible size is used, then that would cause a frame of delay, or prevent the window from being resized if the possible min does change. A possible solution is using the new(ish) TSTransform to shift the window back into the correct position if the size didn't change after a resize and layouting is complete, but that feels very hacky. I'm also not sure if a good solution is even possible, since this seems like one of those issues inherent to immediate mode guis, so a compromise might have to be made. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

3 participants