Trait WinitPlatformExt

Source
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,
    );
}

Required Methods§

Source

fn launch_window( &self, window_config: WindowConfig, ) -> impl Future<Output = WindowId>

Launch a new window with the given configuration.

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;
}
Source

fn close_window(&self, window_id: WindowId)

Close an existing window by its WindowId.

§Example
use freya::{
    prelude::*,
    winit::window::WindowId,
};

fn close_window(window_id: WindowId) {
    Platform::get().close_window(window_id);
}
Source

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);
}
Source

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.

§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);
    });
}

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.

Implementations on Foreign Types§

Source§

impl WinitPlatformExt for Platform

Source§

async fn launch_window(&self, window_config: WindowConfig) -> WindowId

Source§

fn close_window(&self, window_id: WindowId)

Source§

fn focus_window(&self, window_id: Option<WindowId>)

Source§

fn with_window( &self, window_id: Option<WindowId>, callback: impl FnOnce(&mut Window) + 'static, )

Implementors§