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

Fix: egui::Window size recognition issue #4388

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
f0b7737
Update memory.rs
rustbasic Mar 23, 2024
3b98d7f
Update epi_integration.rs
rustbasic Mar 23, 2024
af5a7bb
Update memory.rs
rustbasic Mar 23, 2024
7f66b56
Update memory.rs
rustbasic Mar 23, 2024
6396c4a
Update epi_integration.rs
rustbasic Mar 23, 2024
9fe42ff
Merge branch 'emilk:master' into master
rustbasic Mar 25, 2024
d7673fe
Merge branch 'emilk:master' into master
rustbasic Mar 25, 2024
a7edc53
Merge branch 'emilk:master' into master
rustbasic Mar 26, 2024
2432784
Merge branch 'emilk:master' into master
rustbasic Mar 27, 2024
9b6209b
Merge branch 'emilk:master' into master
rustbasic Mar 27, 2024
f3687f6
Merge branch 'emilk:master' into master
rustbasic Mar 28, 2024
78880de
Merge branch 'emilk:master' into master
rustbasic Mar 29, 2024
01ba2ec
Merge branch 'emilk:master' into master
rustbasic Mar 29, 2024
0ae2451
Merge branch 'emilk:master' into master
rustbasic Mar 29, 2024
e6c84ce
Merge branch 'emilk:master' into master
rustbasic Mar 30, 2024
821dff0
Update epi_integration.rs
rustbasic Mar 30, 2024
eecfafd
Merge branch 'emilk:master' into master
rustbasic Mar 30, 2024
cbb5ac7
Merge branch 'emilk:master' into master
rustbasic Mar 30, 2024
07b5143
Merge branch 'emilk:master' into master
rustbasic Mar 31, 2024
3313633
Update epi_integration.rs
rustbasic Mar 31, 2024
90b968c
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
13af44f
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
5d95f09
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
4be440a
Merge branch 'emilk:master' into master
rustbasic Apr 1, 2024
1ef0e10
Merge branch 'emilk:master' into master
rustbasic Apr 2, 2024
6541324
Merge branch 'emilk:master' into master
rustbasic Apr 2, 2024
8abc161
Merge branch 'emilk:master' into master
rustbasic Apr 3, 2024
1b21742
Merge branch 'emilk:master' into master
rustbasic Apr 4, 2024
052bb68
Merge branch 'emilk:master' into master
rustbasic Apr 5, 2024
a9398c9
Merge branch 'emilk:master' into master
rustbasic Apr 19, 2024
d54ae43
Merge branch 'emilk:master' into master
rustbasic Apr 21, 2024
6cd7dcf
Merge branch 'emilk:master' into master
rustbasic Apr 21, 2024
be42b87
Update resize.rs
rustbasic Apr 21, 2024
89dddeb
Update window.rs
rustbasic Apr 21, 2024
482ed24
Update window.rs
rustbasic Apr 21, 2024
3119911
Merge branch 'emilk:master' into patch46
rustbasic Apr 22, 2024
bda265e
Merge branch 'emilk:master' into patch46
rustbasic Apr 22, 2024
15ecf8a
Merge branch 'emilk:master' into patch46
rustbasic Apr 23, 2024
fb260b7
Merge branch 'emilk:master' into patch46
rustbasic Apr 26, 2024
f040769
Update resize.rs
rustbasic May 2, 2024
94c1564
Update window.rs
rustbasic May 4, 2024
d586b35
Update window.rs
rustbasic May 4, 2024
31326e0
Update resize.rs
rustbasic May 20, 2024
fa321f5
Update window.rs
rustbasic May 20, 2024
ce1986e
Update window.rs
rustbasic May 20, 2024
3916136
Merge branch 'emilk:master' into patch46
rustbasic May 20, 2024
91df0ac
Update resize.rs
rustbasic May 21, 2024
7e6cdf5
Update window.rs
rustbasic May 21, 2024
881bfaf
Update resize.rs
rustbasic May 22, 2024
1edbaa1
Update window.rs
rustbasic May 22, 2024
befcec2
Update window.rs
rustbasic May 22, 2024
f4fd1a7
Update window.rs
rustbasic May 22, 2024
10fcf24
Update window.rs
rustbasic May 22, 2024
aa7106f
Update window.rs
rustbasic May 22, 2024
fa4cc85
Update window.rs
rustbasic May 22, 2024
d289144
Update window.rs
rustbasic May 22, 2024
64177c0
Update resize.rs
rustbasic May 22, 2024
b714c26
Update window.rs
rustbasic May 23, 2024
ba7ab26
Update resize.rs
rustbasic May 23, 2024
6d9e912
Update window.rs
rustbasic May 25, 2024
15ee758
Update window.rs
rustbasic May 25, 2024
78adcc6
Update resize.rs
rustbasic May 25, 2024
73c4670
Merge branch 'master' into patch46
rustbasic Jun 1, 2024
a8ba6aa
Update window.rs
rustbasic Jun 1, 2024
f8226a6
Update window.rs
rustbasic Jun 2, 2024
5001c25
Update window.rs
rustbasic Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions crates/egui/src/containers/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) struct State {
pub(crate) desired_size: Vec2,

/// Actual size of content last frame
last_content_size: Vec2,
pub(crate) last_content_size: Vec2,

/// Externally requested size (e.g. by Window) for the next frame
pub(crate) requested_size: Option<Vec2>,
Expand Down Expand Up @@ -38,6 +38,7 @@ pub struct Resize {

pub(crate) min_size: Vec2,
pub(crate) max_size: Vec2,
pub(crate) margins: Vec2,

default_size: Vec2,

Expand All @@ -52,6 +53,7 @@ impl Default for Resize {
resizable: Vec2b::TRUE,
min_size: Vec2::splat(16.0),
max_size: Vec2::splat(f32::INFINITY),
margins: Vec2::ZERO,
default_size: vec2(320.0, 128.0), // TODO(emilk): preferred size of [`Resize`] area.
with_stroke: true,
}
Expand Down Expand Up @@ -205,25 +207,18 @@ impl Resize {
let mut state = State::load(ui.ctx(), id).unwrap_or_else(|| {
ui.ctx().request_repaint(); // counter frame delay

let default_size = self
.default_size
.at_least(self.min_size)
.at_most(self.max_size)
.at_most(
ui.ctx().screen_rect().size() - ui.spacing().window_margin.sum(), // hack for windows
);

State {
desired_size: default_size,
last_content_size: vec2(0.0, 0.0),
desired_size: self.default_size,
last_content_size: Vec2::ZERO,
requested_size: None,
}
});

state.desired_size = state
.desired_size
.at_least(self.min_size)
.at_most(self.max_size);
.at_most(self.max_size)
.at_most(ui.ctx().screen_rect().size() - self.margins);

let mut user_requested_size = state.requested_size.take();

Expand Down Expand Up @@ -306,13 +301,14 @@ impl Resize {
// We show how large we are,
// so we must follow the contents:

state.desired_size[d] = state.desired_size[d].max(state.last_content_size[d]);
state.desired_size[d] = state.desired_size[d].at_least(state.last_content_size[d]);

// We are as large as we look
size[d] = state.desired_size[d];
} else {
// Probably a window.
size[d] = state.last_content_size[d];
state.desired_size[d] = state.last_content_size[d];
size[d] = state.desired_size[d];
}
}
ui.advance_cursor_after_rect(Rect::from_min_size(content_ui.min_rect().min, size));
Expand Down Expand Up @@ -369,8 +365,6 @@ impl Resize {
}
}

use epaint::Stroke;

pub fn paint_resize_corner(ui: &Ui, response: &Response) {
let stroke = ui.style().interact(response).fg_stroke;
paint_resize_corner_with_style(ui, &response.rect, stroke.color, Align2::RIGHT_BOTTOM);
Expand Down
44 changes: 25 additions & 19 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl<'open> Window<'open> {
open,
area,
frame,
resize,
mut resize,
scroll,
collapsible,
default_open,
Expand Down Expand Up @@ -452,12 +452,6 @@ impl<'open> Window<'open> {
let is_collapsed = with_title_bar && !collapsing.is_open();
let possible = PossibleInteractions::new(&area, &resize, is_collapsed);

let resize = resize.resizable(false); // We resize it manually
let mut resize = resize.id(resize_id);

let on_top = Some(area_layer_id) == ctx.top_layer_id();
let mut area = area.begin(ctx);

// Calculate roughly how much larger the window size is compared to the inner rect
let (title_bar_height, title_content_spacing) = if with_title_bar {
let style = ctx.style();
Expand All @@ -470,34 +464,45 @@ impl<'open> Window<'open> {
(0.0, 0.0)
};

let margins = window_frame.outer_margin.sum()
+ window_frame.inner_margin.sum()
+ vec2(0.0, title_bar_height);
resize.margins = margins;

let resize = resize.resizable(false); // We resize it manually
let mut resize = resize.id(resize_id);

if let Some(mut resize_state) = resize::State::load(ctx, resize_id) {
resize_state.desired_size = Vec2::ZERO;
resize_state.store(ctx, resize_id);
}

let mut prepared_area = area.begin(ctx);
let last_frame_outer_rect = prepared_area.state().rect();

{
// Prevent window from becoming larger than the constrain rect.
let constrain_rect = area.constrain_rect();
let constrain_rect = prepared_area.constrain_rect();
let max_width = constrain_rect.width();
let max_height = constrain_rect.height() - title_bar_height;
resize.max_size.x = resize.max_size.x.min(max_width);
resize.max_size.y = resize.max_size.y.min(max_height);
}

// First check for resize to avoid frame delay:
let last_frame_outer_rect = area.state().rect();
let resize_interaction =
resize_interaction(ctx, possible, area_layer_id, last_frame_outer_rect);

let margins = window_frame.outer_margin.sum()
+ window_frame.inner_margin.sum()
+ vec2(0.0, title_bar_height);

resize_response(
resize_interaction,
ctx,
margins,
resize,
area_layer_id,
&mut area,
&mut prepared_area,
resize_id,
);

let mut area_content_ui = area.content_ui(ctx);
let mut area_content_ui = prepared_area.content_ui(ctx);
if is_open {
// `Area` already takes care of fade-in animations,
// so we only need to handle fade-out animations here.
Expand Down Expand Up @@ -571,6 +576,7 @@ impl<'open> Window<'open> {
},
);

let on_top = Some(area_layer_id) == ctx.top_layer_id();
title_rect = area_content_ui.painter().round_rect_to_pixels(title_rect);

if on_top && area_content_ui.visuals().window_highlight_topmost {
Expand Down Expand Up @@ -612,7 +618,7 @@ impl<'open> Window<'open> {
content_inner
};

let full_response = area.end(ctx, area_content_ui);
let full_response = prepared_area.end(ctx, area_content_ui);

let inner_response = InnerResponse {
inner: content_inner,
Expand Down Expand Up @@ -765,7 +771,7 @@ impl ResizeInteraction {
fn resize_response(
resize_interaction: ResizeInteraction,
ctx: &Context,
margins: Vec2,
resize: Resize,
area_layer_id: LayerId,
area: &mut area::Prepared,
resize_id: Id,
Expand All @@ -784,7 +790,7 @@ fn resize_response(

if resize_interaction.any_dragged() {
if let Some(mut state) = resize::State::load(ctx, resize_id) {
state.requested_size = Some(new_rect.size() - margins);
state.requested_size = Some(new_rect.size() - resize.margins);
state.store(ctx, resize_id);
}
}
Expand Down
Loading