mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 04:48:27 +00:00
Resurrected create_winit_window
With a previous PR, I added a hook to enable the creation of a winit window, which necessitated accessing the winit event loop (https://github.com/slint-ui/slint/pull/7227). This hook was removed in `cd29bdd367` because the Slint event loop was moved to `SharedBackendData`.
I'm very open to the possibility that this is not the correct change, perhaps due to one or more of the following
- Making `shared_backend_data` public
- The `unwrap()` calls
- The possibility that exposing `with_event_loop()` may be a better solution
This commit is contained in:
parent
f669df913c
commit
a80e261d1d
2 changed files with 24 additions and 1 deletions
|
|
@ -645,6 +645,12 @@ pub trait WinitWindowAccessor: private::WinitWindowAccessorSealed {
|
|||
callback: impl FnMut(&i_slint_core::api::Window, &winit::event::WindowEvent) -> WinitWindowEventResult
|
||||
+ 'static,
|
||||
);
|
||||
|
||||
/// Creates a non Slint aware window with winit
|
||||
fn create_winit_window(
|
||||
&self,
|
||||
window_attributes: winit::window::WindowAttributes,
|
||||
) -> Result<winit::window::Window, winit::error::OsError>;
|
||||
}
|
||||
|
||||
impl WinitWindowAccessor for i_slint_core::api::Window {
|
||||
|
|
@ -682,6 +688,23 @@ impl WinitWindowAccessor for i_slint_core::api::Window {
|
|||
.set(Some(Box::new(move |window, event| callback(window, event))));
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a non Slint aware window with winit
|
||||
fn create_winit_window(
|
||||
&self,
|
||||
window_attributes: winit::window::WindowAttributes,
|
||||
) -> Result<winit::window::Window, winit::error::OsError> {
|
||||
i_slint_core::window::WindowInner::from_pub(self)
|
||||
.window_adapter()
|
||||
.internal(i_slint_core::InternalToken)
|
||||
.unwrap()
|
||||
.as_any()
|
||||
.downcast_ref::<WinitWindowAdapter>()
|
||||
.unwrap()
|
||||
.shared_backend_data
|
||||
.with_event_loop(|eli| Ok(eli.create_window(window_attributes)))
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl private::WinitWindowAccessorSealed for i_slint_core::api::Window {}
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ impl WinitWindowOrNone {
|
|||
/// GraphicsWindow is an implementation of the [WindowAdapter][`crate::eventloop::WindowAdapter`] trait. This is
|
||||
/// typically instantiated by entry factory functions of the different graphics back ends.
|
||||
pub struct WinitWindowAdapter {
|
||||
shared_backend_data: Rc<SharedBackendData>,
|
||||
pub shared_backend_data: Rc<SharedBackendData>,
|
||||
window: OnceCell<corelib::api::Window>,
|
||||
self_weak: Weak<Self>,
|
||||
pending_redraw: Cell<bool>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue