Skip to content

Windows & Native Services

Call Application::new().run(...) once from main. Its startup callback creates windows.

#Window lifetime

cx.open_window(WindowOptions::new("Title").size(width, height), view) creates a window with its own View. Closing the window drops that view. Handle the Dock icon with Application::on_reopen when has_visible_windows is false.

Application::new()
    .on_reopen(|has_visible_windows, cx| {
        if !has_visible_windows {
            cx.open_window(WindowOptions::new("My App").size(760.0, 520.0), App);
        }
    })
    .run(|cx| {
        cx.open_window(WindowOptions::new("My App").size(760.0, 520.0), App);
    })

#Commands and services

cx.prompt("Save changes?", ["Save", "Cancel"]);
cx.prompt_for_paths(PathPromptOptions::new().files(true));
cx.message_box(MessageBoxOptions::new("Replace this file?"));

Typed APIs cover dialogs, clipboard, shell, appearance, menus, and displays. Capture cx.window_handle() during a listener when later work needs that window. Tray icons are covered in Tray Icon.

#Events and file watching

Window events include focus, resize, appearance, minimize, fullscreen, and close. Application callbacks include reopen, activation, quit, and open URLs. Enable the file-watcher crate feature when you need filesystem events, and drop watchers with the owning view.