MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / handle_thread_event

Method handle_thread_event

draw/src/glutin_runtime.rs:264–340  ·  view source on GitHub ↗

Handles one of our user events from the GlutinThreadEvent enum

(&mut self, event: GlutinThreadEvent, window_target: &EventLoopWindowTarget<GlutinThreadEvent>)

Source from the content-addressed store, hash-verified

262 /// Handles one of our user events from the GlutinThreadEvent enum
263 ///
264 fn handle_thread_event(&mut self, event: GlutinThreadEvent, window_target: &EventLoopWindowTarget<GlutinThreadEvent>) {
265 use GlutinThreadEvent::*;
266
267 match event {
268 CreateRenderWindow(actions, events, window_properties) => {
269 // Get the initial set of properties for the window
270 let title = window_properties.title().get();
271 let (size_x, size_y) = window_properties.size().get();
272 let fullscreen = window_properties.fullscreen().get();
273 let decorations = window_properties.has_decorations().get();
274
275 let fullscreen = if fullscreen { Some(Fullscreen::Borderless(None)) } else { None };
276
277 // Create a window
278 let window_builder = glutin::window::WindowBuilder::new()
279 .with_title(title)
280 .with_inner_size(glutin::dpi::LogicalSize::new(size_x as f64, size_y as _))
281 .with_fullscreen(fullscreen)
282 .with_decorations(decorations);
283 let windowed_context = glutin::ContextBuilder::new()
284 .with_gl(GlRequest::Specific(Api::OpenGl, (3, 3)))
285 .with_vsync(false)
286 .build_windowed(window_builder, &window_target)
287 .unwrap();
288
289 // Store the window context in a new glutin window
290 let window_id = windowed_context.window().id();
291 let size = windowed_context.window().inner_size();
292 let scale = windowed_context.window().scale_factor();
293 let window = GlutinWindow::new(windowed_context);
294
295 // Store the publisher for the events for this window
296 let mut initial_events = events.republish_weak();
297 self.window_events.insert(window_id, events);
298
299 // Run the window as a process on this thread
300 self.run_process(async move {
301 // Send the initial events for this window (set the size and the DPI)
302 initial_events.publish(DrawEvent::Resize(size.width as f64, size.height as f64)).await;
303 initial_events.publish(DrawEvent::Scale(scale)).await;
304 initial_events.publish(DrawEvent::Redraw).await;
305
306 let window_events = initial_events;
307
308 // Process the actions for the window
309 send_actions_to_window(window, actions, window_events, window_properties).await;
310
311 // Stop processing events for the window once there are no more actions
312 glutin_thread().send_event(GlutinThreadEvent::StopSendingToWindow(window_id));
313 });
314 }
315
316 StopSendingToWindow(window_id) => {
317 self.window_events.remove(&window_id);
318
319 if self.window_events.len() == 0 && self.will_stop_when_no_windows {
320 self.will_exit = true;
321 }

Callers 1

handle_eventMethod · 0.80

Calls 9

send_actions_to_windowFunction · 0.85
glutin_threadFunction · 0.85
titleMethod · 0.80
fullscreenMethod · 0.80
has_decorationsMethod · 0.80
run_processMethod · 0.80
send_eventMethod · 0.80
poll_futureMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected