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

Hide anchored windows the first frame #1856

Merged
merged 4 commits into from Jul 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions egui/src/containers/area.rs
Expand Up @@ -172,6 +172,12 @@ pub(crate) struct Prepared {
pub(crate) movable: bool,
enabled: bool,
drag_bounds: Option<Rect>,
/// Set the first frame of new windows with anchors.
///
/// This is so that we use the first frame to calculate the window size,
/// and then can correctly position the window the next frame,
/// without having one frame where the window is positioned in the wrong place.
temporarily_invisible: bool,
}

impl Area {
Expand Down Expand Up @@ -214,11 +220,11 @@ impl Area {
});
state.pos = new_pos.unwrap_or(state.pos);
state.interactable = interactable;
let mut temporarily_invisible = false;

if let Some((anchor, offset)) = anchor {
if is_new {
// unknown size
ctx.request_repaint();
temporarily_invisible = true;
} else {
let screen = ctx.available_rect();
state.pos = anchor.align_size_within_rect(state.size, screen).min + offset;
Expand All @@ -233,6 +239,7 @@ impl Area {
movable,
enabled,
drag_bounds,
temporarily_invisible,
}
}

Expand Down Expand Up @@ -314,7 +321,7 @@ impl Prepared {
clip_rect,
);
ui.set_enabled(self.enabled);

ui.set_visible(!self.temporarily_invisible);
ui
}

Expand All @@ -326,6 +333,7 @@ impl Prepared {
movable,
enabled,
drag_bounds,
temporarily_invisible: _,
} = self;

state.size = content_ui.min_rect().size();
Expand Down