The launch() function is the entry point for all Freya applications. It initializes the event loop, sets up the renderer, and launches your application windows.
Function Signature
pub fn launch(launch_config: LaunchConfig)
Configuration object that defines windows, plugins, fonts, and other application settings.
LaunchConfig
Configuration builder for launching Freya applications.
Constructor
impl LaunchConfig {
pub fn new() -> LaunchConfig
}
Creates a new LaunchConfig with default settings.
Configuration Methods
with_window
pub fn with_window(self, window_config: WindowConfig) -> Self
Configuration for a window to create. You can call this multiple times to create multiple windows.
Registers a window configuration. Each call creates an additional window.
Example:
LaunchConfig::new()
.with_window(WindowConfig::new(app))
.with_window(WindowConfig::new(secondary_app))
with_plugin
pub fn with_plugin(self, plugin: impl FreyaPlugin + 'static) -> Self
A plugin instance that implements the FreyaPlugin trait.
Registers a Freya plugin for extending functionality.
Example:
LaunchConfig::new()
.with_window(WindowConfig::new(app))
.with_plugin(MyCustomPlugin::new())
with_font
pub fn with_font(
self,
font_name: impl Into<Cow<'static, str>>,
font: impl Into<Bytes>
) -> Self
font_name
impl Into<Cow<'static, str>>
required
The name to register the font under.
Embeds a custom font into the application.
Example:
const CUSTOM_FONT: &[u8] = include_bytes!("../assets/CustomFont.ttf");
LaunchConfig::new()
.with_window(WindowConfig::new(app))
.with_font("Custom Font", CUSTOM_FONT)
with_fallback_font
pub fn with_fallback_font(self, font_family: impl Into<Cow<'static, str>>) -> Self
font_family
impl Into<Cow<'static, str>>
required
Name of the fallback font family to use.
Registers a fallback font. Will be used if the default fonts are not available.
with_default_font
pub fn with_default_font(self, font_name: impl Into<Cow<'static, str>>) -> Self
font_name
impl Into<Cow<'static, str>>
required
Name of the default font to use.
Registers a default font. Will be used if found. This font takes precedence over fallback fonts.
with_future
pub fn with_future<F, Fut>(self, task: F) -> Self
where
F: FnOnce(LaunchProxy) -> Fut + 'static,
Fut: Future<Output = ()> + 'static,
A function that takes a LaunchProxy and returns a Future.
Registers a single-threaded launch task. The task receives a LaunchProxy that can be used to access the renderer context. The provided callback returns a 'static future which will be scheduled on the renderer thread and polled until completion.
Example:
LaunchConfig::new()
.with_window(WindowConfig::new(app))
.with_future(|proxy| async move {
// Background task that runs on the renderer thread
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
// Do something
}
})
with_tray (requires “tray” feature)
#[cfg(feature = "tray")]
pub fn with_tray(
self,
tray_icon: impl FnOnce() -> tray_icon::TrayIcon + 'static + Send,
tray_handler: impl FnMut(TrayEvent, RendererContext) + 'static
) -> Self
tray_icon
impl FnOnce() -> tray_icon::TrayIcon
required
Function that creates and returns a tray icon.
tray_handler
impl FnMut(TrayEvent, RendererContext)
required
Callback function to handle tray events.
Registers a system tray icon and its event handler.
Utility Methods
window_icon
pub fn window_icon(icon: &[u8]) -> Icon
Image data in a supported format (PNG, JPEG, etc.).
Creates a window icon from image bytes.
Returns: Icon - A window icon that can be used with WindowConfig::with_icon().
Example:
const ICON: &[u8] = include_bytes!("../assets/icon.png");
let icon = LaunchConfig::window_icon(ICON);
WindowConfig::new(app).with_icon(icon)
tray_icon (requires “tray” feature)
#[cfg(feature = "tray")]
pub fn tray_icon(icon: &[u8]) -> tray_icon::Icon
Image data in a supported format (PNG, JPEG, etc.).
Creates a tray icon from image bytes.
Returns: tray_icon::Icon - A tray icon that can be used with the tray feature.
Complete Example
use freya::prelude::*;
fn main() {
launch(
LaunchConfig::new()
.with_window(
WindowConfig::new(app)
.with_size(800., 600.)
.with_title("My Freya App")
)
.with_font("Custom Font", include_bytes!("../assets/font.ttf"))
.with_future(|_proxy| async {
// Background tasks
})
)
}
fn app() -> impl IntoElement {
rect()
.expanded()
.center()
.child("Hello, Freya!")
}
Location
Defined in: /home/daytona/workspace/source/crates/freya-winit/src/lib.rs:46