pub trait WinitPlatformExt {
// Required methods
fn launch_window(
&self,
window_config: WindowConfig,
) -> impl Future<Output = WindowId>;
fn close_window(&self, window_id: WindowId);
fn focus_window(&self, window_id: Option<WindowId>);
fn with_window(
&self,
window_id: Option<WindowId>,
callback: impl FnOnce(&mut Window) + 'static,
);
fn post_callback<F, T: 'static>(&self, f: F) -> Receiver<T>
where F: FnOnce(WindowId, &mut RendererContext<'_>) -> T + 'static;
}Expand description
Extension trait that adds winit-specific window management capabilities to Platform.
Required Methods§
Sourcefn launch_window(
&self,
window_config: WindowConfig,
) -> impl Future<Output = WindowId>
fn launch_window( &self, window_config: WindowConfig, ) -> impl Future<Output = WindowId>
Dynamically launch a new window at runtime with the given configuration.
This is meant to create windows on the fly after the application has started,
as opposed to the initial windows registered via crate::config::LaunchConfig.
Returns the WindowId of the newly created window once it has been created.
§Example
use freya::prelude::*;
async fn open_new_window() {
let window_id = Platform::get()
.launch_window(WindowConfig::new(my_app).with_title("New Window"))
.await;
}Sourcefn close_window(&self, window_id: WindowId)
fn close_window(&self, window_id: WindowId)
Sourcefn focus_window(&self, window_id: Option<WindowId>)
fn focus_window(&self, window_id: Option<WindowId>)
Focus a window by its WindowId.
If window_id is None, the current window will be focused.
§Example
use freya::{
prelude::*,
winit::window::WindowId,
};
fn focus_specific_window(window_id: WindowId) {
Platform::get().focus_window(Some(window_id));
}
fn focus_current_window() {
Platform::get().focus_window(None);
}Sourcefn with_window(
&self,
window_id: Option<WindowId>,
callback: impl FnOnce(&mut Window) + 'static,
)
fn with_window( &self, window_id: Option<WindowId>, callback: impl FnOnce(&mut Window) + 'static, )
Execute a callback with mutable access to a Window.
If window_id is None, the callback will be executed on the current window.
This allows direct manipulation of the underlying winit Window for advanced use cases.
To create new windows dynamically, see WinitPlatformExt::launch_window().
§Example
use freya::{
prelude::*,
winit::window::WindowId,
};
fn set_window_title(window_id: Option<WindowId>, title: &'static str) {
Platform::get().with_window(window_id, move |window| {
window.set_title(title);
});
}
fn minimize_current_window() {
Platform::get().with_window(None, |window| {
window.set_minimized(true);
});
}Sourcefn post_callback<F, T: 'static>(&self, f: F) -> Receiver<T>
fn post_callback<F, T: 'static>(&self, f: F) -> Receiver<T>
Queue a callback to be run on the renderer thread with access to a RendererContext.
The call dispatches an event to the winit event loop and returns right away; the
callback runs later, when the event loop picks it up. The WindowId passed to the
callback is the id of the window this Platform instance was bound to. The return
value is delivered through the returned oneshot
Receiver, which can be .awaited or dropped.
The callback runs outside any component scope, so you can’t call Platform::get or
consume context from inside it; use the RendererContext argument instead.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.