mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 22:54:36 +00:00
Change the window property update event to use a window id
This will hopefully enable the custom event to be sendable across threads.
This commit is contained in:
parent
f0bda6a3be
commit
b654646722
2 changed files with 25 additions and 9 deletions
|
@ -109,7 +109,7 @@ pub enum CustomEvent {
|
|||
/// request an animation frame.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
WakeUpAndPoll,
|
||||
UpdateWindowProperties(Weak<Window>),
|
||||
UpdateWindowProperties(winit::window::WindowId),
|
||||
Exit,
|
||||
}
|
||||
|
||||
|
@ -397,8 +397,14 @@ pub fn run() {
|
|||
});
|
||||
}
|
||||
|
||||
winit::event::Event::UserEvent(CustomEvent::UpdateWindowProperties(window)) => {
|
||||
window.upgrade().map(|window| window.update_window_properties());
|
||||
winit::event::Event::UserEvent(CustomEvent::UpdateWindowProperties(window_id)) => {
|
||||
ALL_WINDOWS.with(|windows| {
|
||||
if let Some(Some(window)) =
|
||||
windows.borrow().get(&window_id).map(|weakref| weakref.upgrade())
|
||||
{
|
||||
window.self_weak.upgrade().unwrap().update_window_properties();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
winit::event::Event::UserEvent(CustomEvent::Exit) => {
|
||||
|
|
|
@ -461,12 +461,22 @@ impl PlatformWindow for GraphicsWindow {
|
|||
}
|
||||
|
||||
fn request_window_properties_update(&self) {
|
||||
crate::eventloop::with_window_target(|event_loop| {
|
||||
event_loop.event_loop_proxy().send_event(
|
||||
crate::eventloop::CustomEvent::UpdateWindowProperties(self.self_weak.clone()),
|
||||
)
|
||||
})
|
||||
.ok();
|
||||
match &*self.map_state.borrow() {
|
||||
GraphicsWindowBackendState::Unmapped => {
|
||||
// Nothing to be done if the window isn't visible. When it becomes visible,
|
||||
// ComponentWindow::show() calls update_window_properties()
|
||||
}
|
||||
GraphicsWindowBackendState::Mapped(window) => {
|
||||
let backend = window.backend.borrow();
|
||||
let window_id = backend.window().id();
|
||||
crate::eventloop::with_window_target(|event_loop| {
|
||||
event_loop.event_loop_proxy().send_event(
|
||||
crate::eventloop::CustomEvent::UpdateWindowProperties(window_id),
|
||||
)
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_window_properties(&self, window_item: Pin<&sixtyfps_corelib::items::Window>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue