File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ compliance.
42
42
* ` ui-sys ` now builds on modern macOS.
43
43
* ` inputs ` and ` inputs-grid ` examples no longer erroneously start at 0 for inputs starting at 1.
44
44
* Text no longer uses incorrect newlines per platform.
45
+ * ` UI::run_delay ` no longer spins on the callback, but actually calls it at the
46
+ appropriate interval
45
47
46
48
### Security
47
49
Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ use std::ffi::CStr;
8
8
use std:: marker:: PhantomData ;
9
9
use std:: mem;
10
10
use std:: rc:: Rc ;
11
- use std:: thread:: sleep ;
12
- use std:: time:: Duration ;
11
+ use std:: thread;
12
+ use std:: time:: { Duration , SystemTime } ;
13
13
14
14
use controls:: Window ;
15
15
@@ -222,11 +222,27 @@ impl<'s> EventLoop<'s> {
222
222
/// running the callback given with `on_tick` approximately every
223
223
/// `delay` milliseconds.
224
224
pub fn run_delay ( & mut self , ctx : & UI , delay_ms : u32 ) {
225
- loop {
226
- if !self . next_tick ( ctx) {
227
- break ;
225
+ if let Some ( ref mut c) = self . callback {
226
+ let delay_ms = delay_ms as u128 ;
227
+ let mut t0 = SystemTime :: now ( ) ;
228
+ ' event_loop: loop {
229
+ for _ in 0 ..5 {
230
+ if !unsafe { ui_sys:: uiMainStep ( false as c_int ) == 1 } {
231
+ break ' event_loop;
232
+ }
233
+ }
234
+ if let Ok ( duration) = t0. elapsed ( ) {
235
+ if duration. as_millis ( ) >= delay_ms {
236
+ c ( ) ;
237
+ t0 = SystemTime :: now ( ) ;
238
+ }
239
+ } else {
240
+ t0 = SystemTime :: now ( ) ;
241
+ }
242
+ thread:: sleep ( Duration :: from_millis ( 5 ) ) ;
228
243
}
244
+ } else {
245
+ self . run ( ctx)
229
246
}
230
- sleep ( Duration :: new ( 0 , delay_ms * 1000000 ) )
231
247
}
232
248
}
You can’t perform that action at this time.
0 commit comments