Skip to content

Commit 29bc50e

Browse files
committed
examples: winit simplifications
* Since we can rely on `Resumed` events for all platforms with Winit 0.27 we can remove the alternative `NewEvents` path for initializing state. * Removes some unnecessary abstraction for the app state. * Bumps agdk-egui to egui 0.19 (Winit 0.27)
1 parent d0e7170 commit 29bc50e

File tree

4 files changed

+323
-408
lines changed

4 files changed

+323
-408
lines changed

agdk-egui/Cargo.toml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ log = "0.4"
1111
winit = "0.27"
1212
wgpu = "0.13.0"
1313
pollster = "0.2"
14-
egui = "0.18"
15-
egui-wgpu = { version = "0.18", features = [ "winit" ] }
16-
egui-winit = { version = "0.18", default-features = false }
17-
egui_demo_lib = "0.18"
14+
egui = "0.19"
15+
egui-wgpu = { version = "0.19", features = [ "winit" ] }
16+
egui-winit = { version = "0.19", default-features = false }
17+
egui_demo_lib = "0.19"
1818

1919
[patch.crates-io]
2020
winit = { git = "https://github.com/rib/winit", branch = "android-activity-0.27" }
2121
#winit = { path="../../../winit" }
2222

23-
egui = { git = "https://github.com/budde25/egui", branch = "bump-winit" }
24-
egui-wgpu = { git = "https://github.com/budde25/egui", branch = "bump-winit" }
25-
egui-winit = { git = "https://github.com/budde25/egui", branch = "bump-winit" }
26-
egui_extras = { git = "https://github.com/budde25/egui", branch = "bump-winit" }
27-
egui_demo_lib = { git = "https://github.com/budde25/egui", branch = "bump-winit" }
28-
2923
#egui = { git = "https://github.com/emilk/egui" }
3024
#egui-wgpu = { git = "https://github.com/emilk/egui" }
3125
#egui-winit = { git = "https://github.com/emilk/egui" }

agdk-egui/src/lib.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
use log::Level;
21
use winit::event_loop::{EventLoop, EventLoopBuilder, EventLoopWindowTarget};
32

43
#[cfg(target_os = "android")]
54
use android_activity::AndroidApp;
6-
#[cfg(target_os = "android")]
7-
use winit::platform::android::EventLoopBuilderExtAndroid;
85

96
use winit::event_loop::ControlFlow;
107

@@ -87,15 +84,7 @@ fn _main(event_loop: EventLoop<Event>) {
8784
let mut window: Option<winit::window::Window> = None;
8885
let mut egui_demo_windows = egui_demo_lib::DemoWindows::default();
8986

90-
// On most platforms we can immediately create a winit window. On Android we manage
91-
// window + surface state according to Resumed/Paused events.
92-
#[cfg(not(target_os = "android"))]
93-
{
94-
window = Some(create_window(&event_loop, &mut state, &mut painter));
95-
}
96-
9787
event_loop.run(move |event, event_loop, control_flow| match event {
98-
#[cfg(target_os = "android")]
9988
Resumed => match window {
10089
None => {
10190
window = Some(create_window(event_loop, &mut state, &mut painter));
@@ -105,12 +94,9 @@ fn _main(event_loop: EventLoop<Event>) {
10594
window.request_redraw();
10695
}
10796
},
108-
109-
#[cfg(target_os = "android")]
11097
Suspended => {
11198
window = None;
11299
}
113-
114100
RedrawRequested(..) => {
115101
if let Some(window) = window.as_ref() {
116102
let raw_input = state.take_egui_input(window);
@@ -154,17 +140,21 @@ fn _main(event_loop: EventLoop<Event>) {
154140
});
155141
}
156142

143+
#[allow(dead_code)]
157144
#[cfg(target_os = "android")]
158145
#[no_mangle]
159146
fn android_main(app: AndroidApp) {
160-
android_logger::init_once(android_logger::Config::default().with_min_level(Level::Trace));
147+
use winit::platform::android::EventLoopBuilderExtAndroid;
148+
149+
android_logger::init_once(android_logger::Config::default().with_min_level(log::Level::Trace));
161150

162151
let event_loop = EventLoopBuilder::with_user_event()
163152
.with_android_app(app)
164153
.build();
165154
_main(event_loop);
166155
}
167156

157+
#[allow(dead_code)]
168158
#[cfg(not(target_os = "android"))]
169159
fn main() {
170160
env_logger::builder()

0 commit comments

Comments
 (0)