Redraw request events for multiwindow.
This commit is contained in:
parent
0a643287de
commit
367fea5dc8
3 changed files with 20 additions and 6 deletions
|
|
@ -89,7 +89,7 @@ impl Application for SolarSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
window::frames().map(Message::Tick)
|
window::frames().map(|frame| Message::Tick(frame.at))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,18 @@ use crate::time::Instant;
|
||||||
///
|
///
|
||||||
/// In any case, this [`Subscription`] is useful to smoothly draw application-driven
|
/// In any case, this [`Subscription`] is useful to smoothly draw application-driven
|
||||||
/// animations without missing any frames.
|
/// animations without missing any frames.
|
||||||
pub fn frames() -> Subscription<Instant> {
|
pub fn frames() -> Subscription<Frame> {
|
||||||
subscription::raw_events(|event, _status| match event {
|
subscription::raw_events(|event, _status| match event {
|
||||||
crate::Event::Window(_, Event::RedrawRequested(at)) => Some(at),
|
crate::Event::Window(id, Event::RedrawRequested(at)) => {
|
||||||
|
Some(Frame { id, at })
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The returned `Frame` for a framerate subscription.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Frame {
|
||||||
|
pub id: Id,
|
||||||
|
pub at: Instant,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ pub use iced_native::application::{Appearance, StyleSheet};
|
||||||
use iced_native::window::Action;
|
use iced_native::window::Action;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
pub use crate::Profiler;
|
pub use crate::Profiler;
|
||||||
|
|
@ -402,7 +403,7 @@ async fn run_instance<A, E, C>(
|
||||||
let (filtered, remaining): (Vec<_>, Vec<_>) =
|
let (filtered, remaining): (Vec<_>, Vec<_>) =
|
||||||
events.iter().cloned().partition(
|
events.iter().cloned().partition(
|
||||||
|(window_id, _event): &(
|
|(window_id, _event): &(
|
||||||
Option<crate::window::Id>,
|
Option<window::Id>,
|
||||||
iced_native::event::Event,
|
iced_native::event::Event,
|
||||||
)| {
|
)| {
|
||||||
*window_id == Some(id) || *window_id == None
|
*window_id == Some(id) || *window_id == None
|
||||||
|
|
@ -410,10 +411,14 @@ async fn run_instance<A, E, C>(
|
||||||
);
|
);
|
||||||
|
|
||||||
events.retain(|el| remaining.contains(el));
|
events.retain(|el| remaining.contains(el));
|
||||||
let filtered: Vec<_> = filtered
|
let mut filtered: Vec<_> = filtered
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_id, event)| event)
|
.map(|(_id, event)| event)
|
||||||
.collect();
|
.collect();
|
||||||
|
filtered.push(iced_native::Event::Window(
|
||||||
|
id,
|
||||||
|
window::Event::RedrawRequested(Instant::now()),
|
||||||
|
));
|
||||||
|
|
||||||
let cursor_position =
|
let cursor_position =
|
||||||
states.get(&id).unwrap().cursor_position();
|
states.get(&id).unwrap().cursor_position();
|
||||||
|
|
@ -450,7 +455,7 @@ async fn run_instance<A, E, C>(
|
||||||
user_interface::State::Outdated,
|
user_interface::State::Outdated,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
let state = &mut states.get_mut(&id).unwrap();
|
let state = states.get_mut(&id).unwrap();
|
||||||
let pure_states: HashMap<_, _> =
|
let pure_states: HashMap<_, _> =
|
||||||
ManuallyDrop::into_inner(interfaces)
|
ManuallyDrop::into_inner(interfaces)
|
||||||
.drain()
|
.drain()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue