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

Anchored windows - first show draw misplacement #1852

Closed
zapp88 opened this issue Jul 25, 2022 · 1 comment
Closed

Anchored windows - first show draw misplacement #1852

zapp88 opened this issue Jul 25, 2022 · 1 comment

Comments

@zapp88
Copy link
Contributor

zapp88 commented Jul 25, 2022

When using .anchor on window - the first time the window is rendered results in window showing in "default" position for a brief moment and then jumping to proper anchor position. I belive this is caused by the way the anchor is implemented. We force the paint of the window since we dont know the size of its area - and as a result can't find where the "center" is. Maybe a sollution would be a "dry run" - that would result in size calculation but would not paint the window (resulting in flicker).

if let Some((anchor, offset)) = anchor {
    if is_new {
        // unknown size
        ctx.request_repaint();
    } else {
        let screen = ctx.available_rect();
        state.pos = anchor.align_size_within_rect(state.size, screen).min + offset;
    }
}

Video sample showing issue (the video is slowed down - since the effect last only a second):

Issue.mp4

Code to reproduce issue :

use eframe::{egui, emath::Align2};

fn main() {
    let options = eframe::NativeOptions::default();
    eframe::run_native(
        "Egui issue",
        options,
        Box::new(|_cc| Box::new(IssueApp { open: false })),
    );
}

struct IssueApp {
    open: bool,
}

impl eframe::App for IssueApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::Window::new("Issue window")
            .anchor(Align2::CENTER_CENTER, [0., 0.])
            .open(&mut self.open)
            .show(ctx, |ui| {
                ui.label("Some content");
            });

        egui::CentralPanel::default().show(ctx, |ui| {
            if ui.button("Show window").clicked() {
                self.open = true;
            }
        });
    }
}
emilk pushed a commit that referenced this issue Jul 29, 2022
* Add dry run feature for anchor calculation. (#1)

This PR resolves issue: #1852
We introduce dry_run flag which makes component invisible until we do second pass of rendering - which allows us to properly calculate position for anchor. (This removes rapid flicker when new window is drawn for the first time).

* Change naming convention and add description
@zapp88
Copy link
Contributor Author

zapp88 commented Jul 29, 2022

Resolved via: #1856

@zapp88 zapp88 closed this as completed Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant