|
88 | 88 | #![allow(clippy::manual_range_contains)]
|
89 | 89 |
|
90 | 90 | pub mod painter;
|
91 |
| -#[cfg(feature = "winit")] |
92 |
| -use egui_winit::winit; |
93 | 91 | pub use glow;
|
94 | 92 | pub use painter::Painter;
|
95 |
| -#[cfg(feature = "winit")] |
96 |
| -mod epi_backend; |
97 | 93 | mod misc_util;
|
98 | 94 | mod post_process;
|
99 | 95 | mod shader_version;
|
100 | 96 | mod vao_emulate;
|
101 | 97 |
|
102 |
| -#[cfg(not(target_arch = "wasm32"))] |
103 |
| -#[cfg(feature = "egui_winit")] |
104 |
| -pub use egui_winit; |
| 98 | +#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))] |
| 99 | +pub mod winit; |
| 100 | +#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))] |
| 101 | +pub use winit::*; |
105 | 102 |
|
106 |
| -#[cfg(all(feature = "epi", feature = "winit"))] |
| 103 | +#[cfg(all( |
| 104 | + not(target_arch = "wasm32"), |
| 105 | + feature = "persistence", |
| 106 | + feature = "winit" |
| 107 | +))] |
| 108 | +mod epi_backend; |
| 109 | +#[cfg(all( |
| 110 | + not(target_arch = "wasm32"), |
| 111 | + feature = "persistence", |
| 112 | + feature = "winit" |
| 113 | +))] |
107 | 114 | pub use epi_backend::{run, NativeOptions};
|
108 |
| - |
109 |
| -// ---------------------------------------------------------------------------- |
110 |
| - |
111 |
| -/// Use [`egui`] from a [`glow`] app. |
112 |
| -#[cfg(feature = "winit")] |
113 |
| -pub struct EguiGlow { |
114 |
| - pub egui_ctx: egui::Context, |
115 |
| - pub egui_winit: egui_winit::State, |
116 |
| - pub painter: crate::Painter, |
117 |
| - |
118 |
| - shapes: Vec<egui::epaint::ClippedShape>, |
119 |
| - textures_delta: egui::TexturesDelta, |
120 |
| -} |
121 |
| - |
122 |
| -#[cfg(feature = "winit")] |
123 |
| -impl EguiGlow { |
124 |
| - pub fn new(window: &winit::window::Window, gl: &glow::Context) -> Self { |
125 |
| - let painter = crate::Painter::new(gl, None, "") |
126 |
| - .map_err(|error| { |
127 |
| - tracing::error!("error occurred in initializing painter:\n{}", error); |
128 |
| - }) |
129 |
| - .unwrap(); |
130 |
| - |
131 |
| - Self { |
132 |
| - egui_ctx: Default::default(), |
133 |
| - egui_winit: egui_winit::State::new(painter.max_texture_side(), window), |
134 |
| - painter, |
135 |
| - shapes: Default::default(), |
136 |
| - textures_delta: Default::default(), |
137 |
| - } |
138 |
| - } |
139 |
| - |
140 |
| - /// Returns `true` if egui wants exclusive use of this event |
141 |
| - /// (e.g. a mouse click on an egui window, or entering text into a text field). |
142 |
| - /// For instance, if you use egui for a game, you want to first call this |
143 |
| - /// and only when this returns `false` pass on the events to your game. |
144 |
| - /// |
145 |
| - /// Note that egui uses `tab` to move focus between elements, so this will always return `true` for tabs. |
146 |
| - pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) -> bool { |
147 |
| - self.egui_winit.on_event(&self.egui_ctx, event) |
148 |
| - } |
149 |
| - |
150 |
| - /// Returns `true` if egui requests a repaint. |
151 |
| - /// |
152 |
| - /// Call [`Self::paint`] later to paint. |
153 |
| - pub fn run( |
154 |
| - &mut self, |
155 |
| - window: &winit::window::Window, |
156 |
| - run_ui: impl FnMut(&egui::Context), |
157 |
| - ) -> bool { |
158 |
| - let raw_input = self.egui_winit.take_egui_input(window); |
159 |
| - let egui::FullOutput { |
160 |
| - platform_output, |
161 |
| - needs_repaint, |
162 |
| - textures_delta, |
163 |
| - shapes, |
164 |
| - } = self.egui_ctx.run(raw_input, run_ui); |
165 |
| - |
166 |
| - self.egui_winit |
167 |
| - .handle_platform_output(window, &self.egui_ctx, platform_output); |
168 |
| - |
169 |
| - self.shapes = shapes; |
170 |
| - self.textures_delta.append(textures_delta); |
171 |
| - needs_repaint |
172 |
| - } |
173 |
| - |
174 |
| - /// Paint the results of the last call to [`Self::run`]. |
175 |
| - pub fn paint(&mut self, window: &winit::window::Window, gl: &glow::Context) { |
176 |
| - let shapes = std::mem::take(&mut self.shapes); |
177 |
| - let mut textures_delta = std::mem::take(&mut self.textures_delta); |
178 |
| - |
179 |
| - for (id, image_delta) in textures_delta.set { |
180 |
| - self.painter.set_texture(gl, id, &image_delta); |
181 |
| - } |
182 |
| - |
183 |
| - let clipped_meshes = self.egui_ctx.tessellate(shapes); |
184 |
| - let dimensions: [u32; 2] = window.inner_size().into(); |
185 |
| - self.painter.paint_meshes( |
186 |
| - gl, |
187 |
| - dimensions, |
188 |
| - self.egui_ctx.pixels_per_point(), |
189 |
| - clipped_meshes, |
190 |
| - ); |
191 |
| - |
192 |
| - for id in textures_delta.free.drain(..) { |
193 |
| - self.painter.free_texture(gl, id); |
194 |
| - } |
195 |
| - } |
196 |
| - |
197 |
| - /// Call to release the allocated graphics resources. |
198 |
| - pub fn destroy(&mut self, gl: &glow::Context) { |
199 |
| - self.painter.destroy(gl); |
200 |
| - } |
201 |
| -} |
0 commit comments