From 530ff5420b6f6abba1cb5c1249d58398c91e48e2 Mon Sep 17 00:00:00 2001 From: simlay Date: Sat, 21 Dec 2019 16:35:18 -0800 Subject: [PATCH] Implement revamped `RedrawRequested` on iOS. (#1299) * Implement revamped `RedrawRequested` on iOS * Added RedrawEventsCleared to events_cleared logic * Fixed from comments * Added RedrawEventsCleared to draw_rect handler. * Fixed out of order `RedrawEventsCleared` events. * cargo fmt --- src/platform_impl/ios/app_state.rs | 22 ++++++++++------------ src/platform_impl/ios/view.rs | 8 ++++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/platform_impl/ios/app_state.rs b/src/platform_impl/ios/app_state.rs index 6009a26a..e1b82be1 100644 --- a/src/platform_impl/ios/app_state.rs +++ b/src/platform_impl/ios/app_state.rs @@ -12,7 +12,7 @@ use std::{ use objc::runtime::{BOOL, YES}; use crate::{ - event::{Event, StartCause, WindowEvent}, + event::{Event, StartCause}, event_loop::ControlFlow, platform_impl::platform::{ event_loop::{EventHandler, Never}, @@ -51,11 +51,7 @@ enum UserCallbackTransitionResult<'a> { impl Event { fn is_redraw(&self) -> bool { - if let Event::WindowEvent { - window_id: _, - event: WindowEvent::RedrawRequested, - } = self - { + if let Event::RedrawRequested(_) = self { true } else { false @@ -776,16 +772,18 @@ pub unsafe fn handle_main_events_cleared() { // User events are always sent out at the end of the "MainEventLoop" handle_user_events(); - handle_nonuser_event(Event::EventsCleared); + handle_nonuser_event(Event::MainEventsCleared); let mut this = AppState::get_mut(); - let redraw_events = this + let mut redraw_events: Vec> = this .main_events_cleared_transition() .into_iter() - .map(|window| Event::WindowEvent { - window_id: RootWindowId(window.into()), - event: WindowEvent::RedrawRequested, - }); + .map(|window| Event::RedrawRequested(RootWindowId(window.into()))) + .collect(); + + if !redraw_events.is_empty() { + redraw_events.push(Event::RedrawEventsCleared); + } drop(this); handle_nonuser_events(redraw_events); diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index f729299a..622b351b 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -102,10 +102,10 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { unsafe { let window: id = msg_send![object, window]; assert!(!window.is_null()); - app_state::handle_nonuser_event(Event::WindowEvent { - window_id: RootWindowId(window.into()), - event: WindowEvent::RedrawRequested, - }); + app_state::handle_nonuser_events( + std::iter::once(Event::RedrawRequested(RootWindowId(window.into()))) + .chain(std::iter::once(Event::RedrawEventsCleared)), + ); let superclass: &'static Class = msg_send![object, superclass]; let () = msg_send![super(object, superclass), drawRect: rect]; }