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

(rustbasic) In Progress : Testing... #4182

Closed
wants to merge 321 commits into from
Closed
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
321 commits
Select commit Hold shift + click to select a range
49f45f4
Update context.rs
rustbasic Mar 23, 2024
90159d5
Update glow_integration.rs
rustbasic Mar 23, 2024
d9abe7e
Update wgpu_integration.rs
rustbasic Mar 23, 2024
1c9b09c
Update lib.rs
rustbasic Mar 23, 2024
5abcade
Update wgpu_integration.rs
rustbasic Mar 23, 2024
3187042
Update glow_integration.rs
rustbasic Mar 23, 2024
20d4abf
Update epi_integration.rs
rustbasic Mar 23, 2024
5edf7d7
Update wgpu_integration.rs
rustbasic Mar 23, 2024
9e8ad1c
Update epi_integration.rs
rustbasic Mar 23, 2024
29d6819
Update glow_integration.rs
rustbasic Mar 23, 2024
7a39d0f
Update wgpu_integration.rs
rustbasic Mar 23, 2024
f430c46
Update wgpu_integration.rs
rustbasic Mar 23, 2024
8d72844
Update wgpu_integration.rs
rustbasic Mar 24, 2024
96407f3
Update lib.rs
rustbasic Mar 24, 2024
39f00d3
Update lib.rs
rustbasic Mar 24, 2024
7370c33
Update wgpu_integration.rs
rustbasic Mar 24, 2024
05dbd56
Update input.rs
rustbasic Mar 24, 2024
f05353a
Update lib.rs
rustbasic Mar 24, 2024
4a06e3c
Update wgpu_integration.rs
rustbasic Mar 24, 2024
3ee88a3
Update glow_integration.rs
rustbasic Mar 24, 2024
84af08a
Update wgpu_integration.rs
rustbasic Mar 24, 2024
4cc2ca1
Update lib.rs
rustbasic Mar 24, 2024
c743c8a
Update wgpu_integration.rs
rustbasic Mar 24, 2024
0d7d47c
Update glow_integration.rs
rustbasic Mar 24, 2024
b74d54a
Update lib.rs
rustbasic Mar 24, 2024
c35ddd1
Update lib.rs
rustbasic Mar 24, 2024
141aa22
Update epi_integration.rs
rustbasic Mar 24, 2024
29d2699
Merge branch 'emilk:master' into patch22
rustbasic Mar 25, 2024
4230968
Merge branch 'emilk:master' into patch22
rustbasic Mar 25, 2024
c5a6bbb
Update input.rs
rustbasic Mar 25, 2024
3935248
Update lib.rs
rustbasic Mar 25, 2024
c9851a4
Update wgpu_integration.rs
rustbasic Mar 25, 2024
46860a5
Update glow_integration.rs
rustbasic Mar 25, 2024
64aeb3a
Update context.rs
rustbasic Mar 25, 2024
8ad2587
Update wgpu_integration.rs
rustbasic Mar 25, 2024
e0ed8cc
Update context.rs
rustbasic Mar 26, 2024
991b6d8
Update wgpu_integration.rs
rustbasic Mar 26, 2024
61021e0
Update glow_integration.rs
rustbasic Mar 26, 2024
7b2d8c1
Update glow_integration.rs
rustbasic Mar 26, 2024
84dc8be
Update builder.rs
rustbasic Mar 26, 2024
98f44cb
Update lib.rs
rustbasic Mar 26, 2024
6cc00c7
Update input.rs
rustbasic Mar 26, 2024
8f1b0c4
Update input.rs
rustbasic Mar 26, 2024
16acfde
Update context.rs
rustbasic Mar 26, 2024
de36c34
Update input_state.rs
rustbasic Mar 26, 2024
9c1467e
Update builder.rs
rustbasic Mar 27, 2024
4b1471c
Update style.rs
rustbasic Mar 27, 2024
892db9e
Update run.rs
rustbasic Mar 27, 2024
a87f985
Merge branch 'master' into patch22
rustbasic Mar 27, 2024
259f4c8
Update style.rs
rustbasic Mar 27, 2024
78ac4b7
Update glow_integration.rs
rustbasic Mar 27, 2024
77b72f3
Update input.rs
rustbasic Mar 27, 2024
5b5d30e
Update wgpu_integration.rs
rustbasic Mar 27, 2024
6216c86
Update lib.rs
rustbasic Mar 29, 2024
ebbc44c
Update wgpu_integration.rs
rustbasic Mar 29, 2024
1acb72c
Update glow_integration.rs
rustbasic Mar 29, 2024
2a71c43
Merge branch 'master' into patch22
rustbasic Mar 29, 2024
a91de70
Update visuals.rs
rustbasic Mar 29, 2024
d7b2a95
Update style.rs
rustbasic Mar 29, 2024
04d95a2
Update visuals.rs
rustbasic Mar 29, 2024
ebc3564
Update visuals.rs
rustbasic Mar 29, 2024
2a1c65a
Update style.rs
rustbasic Mar 29, 2024
53e63f0
Merge branch 'emilk:master' into patch22
rustbasic Mar 29, 2024
fe570ac
Update input.rs
rustbasic Mar 29, 2024
76c4fa9
Update lib.rs
rustbasic Mar 29, 2024
c9b443d
Update epi_integration.rs
rustbasic Mar 29, 2024
96c0d9f
Update glow_integration.rs
rustbasic Mar 29, 2024
bfa875b
Update wgpu_integration.rs
rustbasic Mar 29, 2024
51d8740
Update run.rs
rustbasic Mar 29, 2024
0766059
Update epi_integration.rs
rustbasic Mar 29, 2024
82cf39f
Update glow_integration.rs
rustbasic Mar 29, 2024
2584eb7
Update glow_integration.rs
rustbasic Mar 29, 2024
9965861
Update glow_integration.rs
rustbasic Mar 29, 2024
7b3255c
Update wgpu_integration.rs
rustbasic Mar 29, 2024
7cf707d
Update lib.rs
rustbasic Mar 30, 2024
f0a5ac2
Update epi_integration.rs
rustbasic Mar 30, 2024
839b99e
Update wgpu_integration.rs
rustbasic Mar 30, 2024
fdc33b7
Update glow_integration.rs
rustbasic Mar 30, 2024
464194b
Merge branch 'emilk:master' into patch22
rustbasic Mar 30, 2024
6a55087
Update wgpu_integration.rs
rustbasic Mar 30, 2024
42339cf
Update epi_integration.rs
rustbasic Mar 30, 2024
b3cfb9b
Merge branch 'emilk:master' into patch22
rustbasic Mar 30, 2024
27310a6
Update wgpu_integration.rs
rustbasic Mar 30, 2024
34688c4
Update epi_integration.rs
rustbasic Mar 30, 2024
eecb354
Merge branch 'emilk:master' into patch22
rustbasic Mar 30, 2024
cbb20f8
Update epi_integration.rs
rustbasic Mar 30, 2024
14f58c7
Update style.rs
rustbasic Mar 30, 2024
6d455b7
Update glow_integration.rs
rustbasic Mar 30, 2024
347ab08
Update wgpu_integration.rs
rustbasic Mar 30, 2024
b11bbf0
Merge branch 'master' into patch22
rustbasic Mar 31, 2024
b82dbed
Update style.rs
rustbasic Mar 31, 2024
d766d8d
Update builder.rs
rustbasic Mar 31, 2024
195d284
Update glow_integration.rs
rustbasic Mar 31, 2024
171efc4
Merge branch 'emilk:master' into patch22
rustbasic Apr 1, 2024
3b45436
Merge branch 'master' into patch22
rustbasic Apr 1, 2024
ac129e4
Update glow_integration.rs
rustbasic Apr 1, 2024
4dc77a3
Merge branch 'emilk:master' into patch22
rustbasic Apr 1, 2024
14eabb3
Update glow_integration.rs
rustbasic Apr 1, 2024
284c73e
Update wgpu_integration.rs
rustbasic Apr 1, 2024
4f5a927
Update glow_integration.rs
rustbasic Apr 1, 2024
b26697a
Update epi_integration.rs
rustbasic Apr 1, 2024
2ee181d
Update epi_integration.rs
rustbasic Apr 1, 2024
8e4976b
Update epi_integration.rs
rustbasic Apr 1, 2024
064dcab
Update glow_integration.rs
rustbasic Apr 2, 2024
7b8c1e5
Update wgpu_integration.rs
rustbasic Apr 2, 2024
0d2ca19
Merge branch 'emilk:master' into patch22
rustbasic Apr 2, 2024
a378731
Update input.rs
rustbasic Apr 2, 2024
c7426c3
Update input.rs
rustbasic Apr 2, 2024
fe3c460
Merge branch 'emilk:master' into patch22
rustbasic Apr 2, 2024
3e7bc12
Update input.rs
rustbasic Apr 2, 2024
4a520db
Merge branch 'emilk:master' into patch22
rustbasic Apr 3, 2024
349a9f6
Update input.rs
rustbasic Apr 3, 2024
5e5243d
Update input.rs
rustbasic Apr 3, 2024
0f59d6c
Update input.rs
rustbasic Apr 3, 2024
b516f31
Merge branch 'emilk:master' into patch22
rustbasic Apr 3, 2024
79a85d4
Update builder.rs
rustbasic Apr 4, 2024
56931d8
Merge branch 'emilk:master' into patch22
rustbasic Apr 5, 2024
f6c50cc
Update input_state.rs
rustbasic Apr 5, 2024
6f1cd88
Update glow_integration.rs
rustbasic Apr 5, 2024
3e3aa1f
Update scroll_area.rs
rustbasic Apr 7, 2024
2c17ed1
Update input.rs
rustbasic Apr 7, 2024
20f1106
Update scroll_area.rs
rustbasic Apr 7, 2024
0d4bd0f
Update run.rs
rustbasic Apr 7, 2024
bbf615f
Update glow_integration.rs
rustbasic Apr 7, 2024
3a1d3af
Update wgpu_integration.rs
rustbasic Apr 7, 2024
f97c38b
Update input.rs
rustbasic Apr 7, 2024
3f5b106
Update epi.rs
rustbasic Apr 8, 2024
8616641
Update run.rs
rustbasic Apr 9, 2024
401da52
Update glow_integration.rs
rustbasic Apr 9, 2024
3f713f9
Update wgpu_integration.rs
rustbasic Apr 9, 2024
8ead7de
Update glow_integration.rs
rustbasic Apr 9, 2024
2638068
Update epi_integration.rs
rustbasic Apr 10, 2024
686e408
Update wgpu_integration.rs
rustbasic Apr 10, 2024
b5d2221
Update glow_integration.rs
rustbasic Apr 10, 2024
87c0042
Update wgpu_integration.rs
rustbasic Apr 10, 2024
8b1e728
Update glow_integration.rs
rustbasic Apr 10, 2024
f966274
Update epi_integration.rs
rustbasic Apr 10, 2024
480ec94
Update scroll_area.rs
rustbasic Apr 10, 2024
c5885e9
Update scroll_area.rs
rustbasic Apr 10, 2024
19b7c16
Update input_state.rs
rustbasic Apr 11, 2024
e46947f
Update scroll_area.rs
rustbasic Apr 11, 2024
29d5ce3
Update text_cursor_state.rs
rustbasic Apr 14, 2024
a0ae047
Update lib.rs
rustbasic Apr 14, 2024
af3befd
Update input.rs
rustbasic Apr 14, 2024
ff4e0b7
Update builder.rs
rustbasic Apr 14, 2024
d8af252
Update lib.rs
rustbasic Apr 14, 2024
b01e3f1
Update lib.rs
rustbasic Apr 14, 2024
0d4ec6b
Update id.rs
rustbasic Apr 17, 2024
ae8205b
Update state.rs
rustbasic Apr 17, 2024
70787d6
Update builder.rs
rustbasic Apr 17, 2024
d9f143e
Update state.rs
rustbasic Apr 17, 2024
a1d21f1
Update lib.rs
rustbasic Apr 19, 2024
07edf27
Update lib.rs
rustbasic Apr 19, 2024
76871af
Merge branch 'emilk:master' into patch22
rustbasic Apr 19, 2024
34587d4
Update resize.rs
rustbasic Apr 20, 2024
a2e2df2
Update window.rs
rustbasic Apr 20, 2024
704c96a
Update resize.rs
rustbasic Apr 20, 2024
6926536
Update resize.rs
rustbasic Apr 20, 2024
f4b1ebb
Update window.rs
rustbasic Apr 21, 2024
4c09339
Merge branch 'emilk:master' into patch22
rustbasic Apr 21, 2024
6167026
Update text_cursor_state.rs
rustbasic Apr 21, 2024
1509a87
Update text_cursor_state.rs
rustbasic Apr 22, 2024
ca43638
Update input.rs
rustbasic Apr 22, 2024
1f60ecd
Merge branch 'emilk:master' into patch22
rustbasic Apr 22, 2024
f5805ed
Merge branch 'master' into patch22
rustbasic Apr 22, 2024
22d9fdc
Update state.rs
rustbasic Apr 23, 2024
669b29a
Merge branch 'emilk:master' into patch22
rustbasic Apr 23, 2024
9d64e91
Merge branch 'emilk:master' into patch22
rustbasic Apr 24, 2024
13e9a89
Update epi_integration.rs
rustbasic Apr 25, 2024
f1bd710
Update epi_integration.rs
rustbasic Apr 25, 2024
a2f10b8
Update builder.rs
rustbasic Apr 25, 2024
b477242
Update input_state.rs
rustbasic Apr 25, 2024
992ef9d
Update context.rs
rustbasic Apr 25, 2024
7bb07f1
Update scroll_area.rs
rustbasic Apr 25, 2024
5d51b74
Update scroll_area.rs
rustbasic Apr 25, 2024
cd3908f
Update input_state.rs
rustbasic Apr 25, 2024
ee8882d
Update input_state.rs
rustbasic Apr 25, 2024
e2edc1d
Update input_state.rs
rustbasic Apr 25, 2024
240be43
Merge branch 'emilk:master' into patch22
rustbasic Apr 26, 2024
4afd36f
Update input_state.rs
rustbasic Apr 26, 2024
47f1ce5
Update epi_integration.rs
rustbasic Apr 27, 2024
32d6ec2
Update context.rs
rustbasic Apr 27, 2024
2ab1850
Update context.rs
rustbasic Apr 27, 2024
898d7e5
Update input_state.rs
rustbasic Apr 27, 2024
8a47702
Update context.rs
rustbasic Apr 27, 2024
2f54d63
Update input_state.rs
rustbasic Apr 28, 2024
aa82244
Update lib.rs
rustbasic Apr 29, 2024
257dc42
Merge branch 'emilk:master' into patch22
rustbasic Apr 29, 2024
294294d
Update glow_integration.rs
rustbasic May 1, 2024
ed436ba
Update viewport.rs
rustbasic May 1, 2024
fd14249
Update viewport.rs
rustbasic May 1, 2024
3c0e53a
Update lib.rs
rustbasic May 1, 2024
35349bc
Merge branch 'emilk:master' into patch22
rustbasic May 1, 2024
7f4b794
Update resize.rs
rustbasic May 2, 2024
53ba6b7
Merge branch 'master' into patch22
rustbasic May 3, 2024
d789c77
Update panel.rs
rustbasic May 3, 2024
ad4abc0
Update panel.rs
rustbasic May 3, 2024
d0ef558
Update ui.rs
rustbasic May 3, 2024
ea15b1a
Update ui.rs
rustbasic May 4, 2024
43d5430
Update placer.rs
rustbasic May 4, 2024
830b16e
Update ui.rs
rustbasic May 4, 2024
394afaf
Update window.rs
rustbasic May 4, 2024
77ef8ed
Update window.rs
rustbasic May 4, 2024
0a53ebf
Update viewport.rs
rustbasic May 4, 2024
5100d91
Update lib.rs
rustbasic May 5, 2024
745f4b6
Update lib.rs
rustbasic May 6, 2024
8e5a890
Update viewport.rs
rustbasic May 6, 2024
285fe72
Update viewport.rs
rustbasic May 7, 2024
ce383b0
Update viewport.rs
rustbasic May 7, 2024
62ba8cf
Update viewport.rs
rustbasic May 8, 2024
d9408aa
Update epi_integration.rs
rustbasic May 9, 2024
08e006a
Update wgpu_integration.rs
rustbasic May 11, 2024
4a5259c
Update glow_integration.rs
rustbasic May 11, 2024
2e02044
Merge branch 'master' into patch22
rustbasic May 11, 2024
1dd653a
Merge branch 'emilk:master' into patch22
rustbasic May 12, 2024
e454b32
Update epi_integration.rs
rustbasic May 12, 2024
fbd3c1b
Update viewport.rs
rustbasic May 15, 2024
70e6e70
Update viewport.rs
rustbasic May 15, 2024
ccbc9bf
Merge branch 'emilk:master' into patch22
rustbasic May 15, 2024
88828b0
Update placer.rs
rustbasic May 15, 2024
15d901a
Update Cargo.toml
rustbasic May 15, 2024
0068718
Update Cargo.toml
rustbasic May 15, 2024
a44b0d5
Update glow_integration.rs
rustbasic May 18, 2024
de664f7
Update glow_integration.rs
rustbasic May 18, 2024
398aa27
Merge branch 'emilk:master' into patch22
rustbasic May 18, 2024
41f93b1
Update builder.rs
rustbasic May 19, 2024
7325f86
Update builder.rs
rustbasic May 19, 2024
3c96a61
Update resize.rs
rustbasic May 20, 2024
d658166
Update window.rs
rustbasic May 20, 2024
d7850fa
Update builder.rs
rustbasic May 21, 2024
45a3d2c
Update resize.rs
rustbasic May 21, 2024
629b739
Update window.rs
rustbasic May 21, 2024
0e626d5
Update wgpu_integration.rs
rustbasic May 21, 2024
8e0749b
Update glow_integration.rs
rustbasic May 21, 2024
cfed618
Update builder.rs
rustbasic May 22, 2024
431561f
Merge branch 'emilk:master' into patch22
rustbasic May 22, 2024
a5b8f8d
Update builder.rs
rustbasic May 22, 2024
a711262
Update resize.rs
rustbasic May 22, 2024
d7c754e
Update window.rs
rustbasic May 22, 2024
19bf8c8
Merge branch 'master' into patch22
rustbasic May 23, 2024
e7f8ef4
Update input_state.rs
rustbasic May 23, 2024
70a070f
Merge branch 'emilk:master' into patch22
rustbasic May 25, 2024
dbb2f43
Update scroll_area.rs
rustbasic May 26, 2024
92062b1
Update resize.rs
rustbasic May 26, 2024
ce27c85
Update window.rs
rustbasic May 26, 2024
4a200b2
Update resize.rs
rustbasic May 26, 2024
6c6293f
Update window.rs
rustbasic May 27, 2024
6306fce
Update run.rs
rustbasic May 27, 2024
e0daba6
Update run.rs
rustbasic May 27, 2024
102c8df
Update run.rs
rustbasic May 27, 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
9 changes: 8 additions & 1 deletion crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,20 @@ impl EpiIntegration {

let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
if let Some(viewport_ui_cb) = viewport_ui_cb {
// Child viewport
// Child Deferred Viewport
crate::profile_scope!("viewport_callback");
viewport_ui_cb(egui_ctx);
} else {
// ROOT Viewport ( with Immediate Viewport )
crate::profile_scope!("App::update");
app.update(egui_ctx, &mut self.frame);
}

let viewport_id = egui_ctx.viewport_id();
// TODO : Do not recall until the next repaint.
// 1000 millis / 60 fps = 16.67 millis
self.egui_ctx
.request_repaint_after_for(std::time::Duration::from_millis(8), viewport_id);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will just cause a hot repaint loop

Suggested change
let viewport_id = egui_ctx.viewport_id();
// TODO : Do not recall until the next repaint.
// 1000 millis / 60 fps = 16.67 millis
self.egui_ctx
.request_repaint_after_for(std::time::Duration::from_millis(8), viewport_id);

});

let is_root_viewport = viewport_ui_cb.is_none();
Expand Down
144 changes: 85 additions & 59 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ impl WinitApp for GlowWinitApp {
fn is_focused(&self, window_id: WindowId) -> bool {
if let Some(running) = &self.running {
let glutin = running.glutin.borrow();
if let Some(window_id) = glutin.viewport_from_window.get(&window_id) {
return glutin.focused_viewport == Some(*window_id);
if let Some(viewport_id) = glutin.viewport_from_window.get(&window_id) {
return glutin.focused_viewport == Some(*viewport_id);
}
}

Expand Down Expand Up @@ -463,7 +463,7 @@ impl WinitApp for GlowWinitApp {
}

if let Some(window) = viewport.window.as_ref() {
EventResult::RepaintNext(window.id())
EventResult::RepaintNow(window.id())
} else {
EventResult::Wait
}
Expand Down Expand Up @@ -509,7 +509,7 @@ impl GlowWinitRunning {
) -> EventResult {
crate::profile_function!();

let Some(viewport_id) = self
let Some(mut viewport_id) = self
.glutin
.borrow()
.viewport_from_window
Expand All @@ -525,32 +525,44 @@ impl GlowWinitRunning {
let mut frame_timer = crate::stopwatch::Stopwatch::new();
frame_timer.start();

{
let glutin = self.glutin.borrow();
let viewport = &glutin.viewports[&viewport_id];
let is_immediate = viewport.viewport_ui_cb.is_none();
let (raw_input, viewport_ui_cb) = {
crate::profile_scope!("Prepare");

let mut glutin = self.glutin.borrow_mut();
let original_viewport = &glutin.viewports[&viewport_id];
let is_immediate = original_viewport.viewport_ui_cb.is_none();

// This will only happens when a Immediate Viewport.
if is_immediate && viewport_id != ViewportId::ROOT {
// This will only happen if this is an immediate viewport.
// That means that the viewport cannot be rendered by itself and needs his parent to be rendered.
if let Some(parent_viewport) = glutin.viewports.get(&viewport.ids.parent) {
if let Some(window) = parent_viewport.window.as_ref() {
return EventResult::RepaintNext(window.id());
if let Some(parent_viewport) = glutin.viewports.get(&original_viewport.ids.parent) {
let is_deferred_parent = parent_viewport.viewport_ui_cb.is_some();
if is_deferred_parent {
// This will only happens when the parent is a Deferred Viewport.
viewport_id = parent_viewport.ids.this;
} else if let Some(root_viewport) = glutin.viewports.get(&ViewportId::ROOT) {
// This will only happen when the parent is a Immediate Viewport.
// That means that the viewport cannot be rendered by itself and needs his parent to be rendered.
viewport_id = root_viewport.ids.this;
} else {
// Not actually used. Because there is always a `Some()` value.
return EventResult::Wait;
}
}
return EventResult::Wait;
}
}

let (raw_input, viewport_ui_cb) = {
let mut glutin = self.glutin.borrow_mut();
let egui_ctx = glutin.egui_ctx.clone();
let viewport = glutin.viewports.get_mut(&viewport_id).unwrap();
let Some(viewport) = glutin.viewports.get_mut(&viewport_id) else {
return EventResult::Wait;
};

let Some(window) = viewport.window.as_ref() else {
return EventResult::Wait;
};
egui_winit::update_viewport_info(&mut viewport.info, &egui_ctx, window);

let egui_winit = viewport.egui_winit.as_mut().unwrap();
let Some(egui_winit) = viewport.egui_winit.as_mut() else {
return EventResult::Wait;
};
let mut raw_input = egui_winit.take_egui_input(window);
let viewport_ui_cb = viewport.viewport_ui_cb.clone();

Expand Down Expand Up @@ -628,13 +640,18 @@ impl GlowWinitRunning {
viewport_output,
} = full_output;

glutin.active_viewports_retain(viewport_output.clone());

let GlutinWindowContext {
viewports,
current_gl_context,
..
} = &mut *glutin;

let viewport = viewports.get_mut(&viewport_id).unwrap();
let Some(viewport) = viewports.get_mut(&viewport_id) else {
return EventResult::Wait;
};

viewport.info.events.clear(); // they should have been processed
let window = viewport.window.clone().unwrap();
let gl_surface = viewport.gl_surface.as_ref().unwrap();
Expand Down Expand Up @@ -707,15 +724,19 @@ impl GlowWinitRunning {

integration.maybe_autosave(app.as_mut(), Some(&window));

if window.is_minimized() == Some(true) {
// On Mac, a minimized Window uses up all CPU:
// https://github.com/emilk/egui/issues/325
crate::profile_scope!("minimized_sleep");
std::thread::sleep(std::time::Duration::from_millis(10));
let is_windows = cfg!(target_os = "windows");
if !is_windows {
let is_minimized = window.is_minimized().unwrap_or(false);
if is_minimized {
// On Mac, a minimized Window uses up all CPU:
// https://github.com/emilk/egui/issues/325
crate::profile_scope!("minimized_sleep");
std::thread::sleep(std::time::Duration::from_millis(10));
}
}

if integration.should_close() {
EventResult::Exit
EventResult::Exit(window_id)
} else {
EventResult::Wait
}
Expand Down Expand Up @@ -744,22 +765,16 @@ impl GlowWinitRunning {
// to resizes anyway, as doing so avoids dropping frames.
//
// See: https://github.com/emilk/egui/issues/903
let mut repaint_asap = false;

match event {
winit::event::WindowEvent::Focused(new_focused) => {
glutin.focused_viewport = new_focused.then(|| viewport_id).flatten();
}

winit::event::WindowEvent::Resized(physical_size) => {
// Resize with 0 width and height is used by winit to signal a minimize event on Windows.
// See: https://github.com/rust-windowing/winit/issues/208
// This solves an issue where the app would panic when minimizing on Windows.
if 0 < physical_size.width && 0 < physical_size.height {
if let Some(viewport_id) = viewport_id {
repaint_asap = true;
glutin.resize(viewport_id, *physical_size);
}
if let Some(viewport_id) = viewport_id {
glutin.resize(viewport_id, *physical_size);
return EventResult::RepaintNext(window_id);
}
}

Expand All @@ -768,7 +783,7 @@ impl GlowWinitRunning {
log::debug!(
"Received WindowEvent::CloseRequested for main viewport - shutting down."
);
return EventResult::Exit;
return EventResult::Exit(window_id);
}

log::debug!("Received WindowEvent::CloseRequested for viewport {viewport_id:?}");
Expand All @@ -782,9 +797,17 @@ impl GlowWinitRunning {
// and perhaps twice (once to notice the close-event, once again to enforce it).
// `request_repaint_of` does a double-repaint though:
self.integration.egui_ctx.request_repaint_of(viewport_id);
self.integration
.egui_ctx
.request_repaint_of(viewport.ids.parent);
if viewport_id != ViewportId::ROOT {
self.integration
.egui_ctx
.request_repaint_of(viewport.ids.parent);
}

if viewport_id == ViewportId::ROOT {
return EventResult::Wait;
} else {
return EventResult::ViewportExit(window_id);
}
}
}
}
Expand All @@ -793,7 +816,7 @@ impl GlowWinitRunning {
}

if self.integration.should_close() {
return EventResult::Exit;
return EventResult::Exit(window_id);
}

let mut event_response = egui_winit::EventResponse {
Expand All @@ -815,11 +838,7 @@ impl GlowWinitRunning {
}

if event_response.repaint {
if repaint_asap {
EventResult::RepaintNow(window_id)
} else {
EventResult::RepaintNext(window_id)
}
EventResult::RepaintNow(window_id)
} else {
EventResult::Wait
}
Expand Down Expand Up @@ -976,8 +995,7 @@ impl GlutinWindowContext {
if let Some(window) = &window {
viewport_from_window.insert(window.id(), ViewportId::ROOT);
window_from_viewport.insert(ViewportId::ROOT, window.id());
info.minimized = window.is_minimized();
info.maximized = Some(window.is_maximized());
info = egui_winit::get_update_viewport_info(&ViewportInfo::default(), window, None);
}

let mut viewports = ViewportIdMap::default();
Expand Down Expand Up @@ -1068,8 +1086,8 @@ impl GlutinWindowContext {
&window,
&viewport.builder,
);
viewport.info.minimized = window.is_minimized();
viewport.info.maximized = Some(window.is_maximized());

viewport.info = egui_winit::get_update_viewport_info(&viewport.info, &window, None);
viewport.window.insert(Arc::new(window))
};

Expand Down Expand Up @@ -1168,6 +1186,22 @@ impl GlutinWindowContext {
.expect("winit window doesn't exist")
}

#[allow(clippy::needless_pass_by_value)]
pub(crate) fn active_viewports_retain(
&mut self,
viewport_output: ViewportIdMap<ViewportOutput>,
) {
let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect();

// GC old viewports
self.viewports
.retain(|id, _| active_viewports_ids.contains(id));
self.viewport_from_window
.retain(|_, id| active_viewports_ids.contains(id));
self.window_from_viewport
.retain(|id, _| active_viewports_ids.contains(id));
}

fn resize(&mut self, viewport_id: ViewportId, physical_size: winit::dpi::PhysicalSize<u32>) {
let width_px = std::num::NonZeroU32::new(physical_size.width.at_least(1)).unwrap();
let height_px = std::num::NonZeroU32::new(physical_size.height.at_least(1)).unwrap();
Expand Down Expand Up @@ -1206,8 +1240,6 @@ impl GlutinWindowContext {
) {
crate::profile_function!();

let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect();

for (
viewport_id,
ViewportOutput {
Expand All @@ -1218,7 +1250,7 @@ impl GlutinWindowContext {
commands,
repaint_delay: _, // ignored - we listened to the repaint callback instead
},
) in viewport_output
) in viewport_output.clone()
{
let ids = ViewportIdPair::from_self_and_parent(viewport_id, parent);

Expand Down Expand Up @@ -1248,13 +1280,7 @@ impl GlutinWindowContext {
// Create windows for any new viewports:
self.initialize_all_windows(event_loop);

// GC old viewports
self.viewports
.retain(|id, _| active_viewports_ids.contains(id));
self.viewport_from_window
.retain(|_, id| active_viewports_ids.contains(id));
self.window_from_viewport
.retain(|id, _| active_viewports_ids.contains(id));
self.active_viewports_retain(viewport_output);
}
}

Expand Down
Loading
Loading