pub struct WindowBuilder<'a, R: Runtime, M: Manager<R>> { /* private fields */ }unstable only.Expand description
A builder for a window managed by Tauri.
Implementations§
Source§impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
Sourcepub fn new<L: Into<String>>(manager: &'a M, label: L) -> Self
pub fn new<L: Into<String>>(manager: &'a M, label: L) -> Self
Initializes a window builder with the given window label.
§Known issues
On Windows, this function deadlocks when used in a synchronous command or event handlers, see the Webview2 issue.
You should use async commands and separate threads when creating windows.
§Examples
- Create a window in the setup hook:
tauri::Builder::default()
.setup(|app| {
let window = tauri::window::WindowBuilder::new(app, "label")
.build()?;
Ok(())
});- Create a window in a separate thread:
tauri::Builder::default()
.setup(|app| {
let handle = app.handle().clone();
std::thread::spawn(move || {
let window = tauri::window::WindowBuilder::new(&handle, "label")
.build()
.unwrap();
});
Ok(())
});- Create a window in a command:
#[tauri::command]
async fn create_window(app: tauri::AppHandle) {
let window = tauri::window::WindowBuilder::new(&app, "label")
.build()
.unwrap();
}Sourcepub fn from_config(manager: &'a M, config: &WindowConfig) -> Result<Self>
pub fn from_config(manager: &'a M, config: &WindowConfig) -> Result<Self>
Initializes a window builder from a WindowConfig from tauri.conf.json.
Keep in mind that you can’t create 2 windows with the same label so make sure
that the initial window was closed or change the label of the new WindowBuilder.
§Known issues
On Windows, this function deadlocks when used in a synchronous command or event handlers, see the Webview2 issue.
You should use async commands and separate threads when creating windows.
§Examples
- Create a window in a command:
#[tauri::command]
async fn reopen_window(app: tauri::AppHandle) {
let window = tauri::window::WindowBuilder::from_config(&app, &app.config().app.windows.get(0).unwrap().clone())
.unwrap()
.build()
.unwrap();
}Available on desktop only.
desktop only.Registers a global menu event listener.
Note that this handler is called for any menu event, whether it is coming from this window, another window or from the tray icon menu.
Also note that this handler will not be called if the window used to register it was closed.
§Examples
use tauri::menu::{Menu, Submenu, MenuItem};
tauri::Builder::default()
.setup(|app| {
let handle = app.handle();
let save_menu_item = MenuItem::new(handle, "Save", true, None::<&str>)?;
let menu = Menu::with_items(handle, &[
&Submenu::with_items(handle, "File", true, &[
&save_menu_item,
])?,
])?;
let window = tauri::window::WindowBuilder::new(app, "editor")
.menu(menu)
.on_menu_event(move |window, event| {
if event.id == save_menu_item.id() {
// save menu item
}
})
.build()
.unwrap();
///
Ok(())
});Source§impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
Desktop APIs
impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
Desktop APIs
Available on desktop only.
desktop only.Sets the menu for the window.
Sourcepub fn prevent_overflow(self) -> Self
Available on desktop only.
pub fn prevent_overflow(self) -> Self
desktop only.Prevent the window from overflowing the working area (e.g. monitor size - taskbar size)
on creation, which means the window size will be limited to monitor size - taskbar size
NOTE: The overflow check is only performed on window creation, resizes can still overflow
§Platform-specific
- iOS / Android: Unsupported.
Sourcepub fn prevent_overflow_with_margin(self, margin: impl Into<Size>) -> Self
Available on desktop only.
pub fn prevent_overflow_with_margin(self, margin: impl Into<Size>) -> Self
desktop only.Prevent the window from overflowing the working area (e.g. monitor size - taskbar size)
on creation with a margin, which means the window size will be limited to monitor size - taskbar size - margin size
NOTE: The overflow check is only performed on window creation, resizes can still overflow
§Platform-specific
- iOS / Android: Unsupported.
Sourcepub fn maximizable(self, maximizable: bool) -> Self
Available on desktop only.
pub fn maximizable(self, maximizable: bool) -> Self
desktop only.Whether the window’s native maximize button is enabled or not. If resizable is set to false, this setting is ignored.
§Platform-specific
- macOS: Disables the “zoom” button in the window titlebar, which is also used to enter fullscreen mode.
- Linux / iOS / Android: Unsupported.
Sourcepub fn minimizable(self, minimizable: bool) -> Self
Available on desktop only.
pub fn minimizable(self, minimizable: bool) -> Self
desktop only.Whether the window’s native minimize button is enabled or not.
§Platform-specific
- Linux / iOS / Android: Unsupported.
Sourcepub fn closable(self, closable: bool) -> Self
Available on desktop only.
pub fn closable(self, closable: bool) -> Self
desktop only.Whether the window’s native close button is enabled or not.
§Platform-specific
- Linux: “GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible”
- iOS / Android: Unsupported.
Sourcepub fn fullscreen(self, fullscreen: bool) -> Self
Available on desktop only.
pub fn fullscreen(self, fullscreen: bool) -> Self
desktop only.Whether to start the window in fullscreen or not.
Sourcepub fn maximized(self, maximized: bool) -> Self
Available on desktop only.
pub fn maximized(self, maximized: bool) -> Self
desktop only.Whether the window should be maximized upon creation.
Sourcepub fn decorations(self, decorations: bool) -> Self
Available on desktop only.
pub fn decorations(self, decorations: bool) -> Self
desktop only.Whether the window should have borders and bars.
Sourcepub fn always_on_bottom(self, always_on_bottom: bool) -> Self
Available on desktop only.
pub fn always_on_bottom(self, always_on_bottom: bool) -> Self
desktop only.Whether the window should always be below other windows.
Sourcepub fn always_on_top(self, always_on_top: bool) -> Self
Available on desktop only.
pub fn always_on_top(self, always_on_top: bool) -> Self
desktop only.Whether the window should always be on top of other windows.
Sourcepub fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self
Available on desktop only.
pub fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self
desktop only.Whether the window will be visible on all workspaces or virtual desktops.
§Platform-specific
- Windows / iOS / Android: Unsupported.
Sourcepub fn icon(self, icon: Image<'a>) -> Result<Self>
Available on desktop only.
pub fn icon(self, icon: Image<'a>) -> Result<Self>
desktop only.Sets the window icon.
Sourcepub fn skip_taskbar(self, skip: bool) -> Self
Available on desktop only.
pub fn skip_taskbar(self, skip: bool) -> Self
desktop only.Sets whether or not the window icon should be hidden from the taskbar.
§Platform-specific
- macOS: Unsupported.
Sourcepub fn window_classname<S: Into<String>>(self, classname: S) -> Self
Available on desktop only.
pub fn window_classname<S: Into<String>>(self, classname: S) -> Self
desktop only.Sets custom name for Windows’ window class. Windows only.
Sourcepub fn shadow(self, enable: bool) -> Self
Available on desktop only.
pub fn shadow(self, enable: bool) -> Self
desktop only.Sets whether or not the window has shadow.
§Platform-specific
- Windows:
falsehas no effect on decorated window, shadows are always ON.truewill make undecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
- Linux: Unsupported.
Sourcepub fn parent(self, parent: &Window<R>) -> Result<Self>
Available on desktop only.
pub fn parent(self, parent: &Window<R>) -> Result<Self>
desktop only.Sets a parent to the window to be created.
§Platform-specific
- Windows: This sets the passed parent as an owner window to the window to be created.
From MSDN owned windows docs:
- An owned window is always above its owner in the z-order.
- The system automatically destroys an owned window when its owner is destroyed.
- An owned window is hidden when its owner is minimized.
- Linux: This makes the new window transient for parent, see https://docs.gtk.org/gtk3/method.Window.set_transient_for.html
- macOS: This adds the window as a child of parent, see https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc
Sourcepub fn transient_for(self, parent: &Window<R>) -> Result<Self>
Available on desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.
pub fn transient_for(self, parent: &Window<R>) -> Result<Self>
desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.Sets the window to be created transient for parent.
See https://docs.gtk.org/gtk3/method.Window.set_transient_for.html
Note: This is a low level API. See Self::parent for a higher level wrapper for Tauri windows.
Sourcepub fn transient_for_raw(self, parent: &impl IsA<Window>) -> Self
Available on desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.
pub fn transient_for_raw(self, parent: &impl IsA<Window>) -> Self
desktop and (Linux or DragonFly BSD or FreeBSD or NetBSD or OpenBSD) only.Sets the window to be created transient for parent.
See https://docs.gtk.org/gtk3/method.Window.set_transient_for.html
Note: This is a low level API. See Self::parent and Self::transient_for for higher level wrappers for Tauri windows.
Sourcepub fn effects(self, effects: WindowEffectsConfig) -> Self
Available on desktop only.
pub fn effects(self, effects: WindowEffectsConfig) -> Self
desktop only.Sets window effects.
Requires the window to be transparent.
§Platform-specific:
- Windows: If using decorations or shadows, you may want to try this workaround https://github.com/tauri-apps/tao/issues/72#issuecomment-975607891
- Linux: Unsupported
Source§impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
Window APIs.
impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>
Window APIs.
Sourcepub fn position(self, x: f64, y: f64) -> Self
pub fn position(self, x: f64, y: f64) -> Self
The initial position of the window in logical pixels.
Sourcepub fn inner_size(self, width: f64, height: f64) -> Self
pub fn inner_size(self, width: f64, height: f64) -> Self
Window size in logical pixels.
Sourcepub fn min_inner_size(self, min_width: f64, min_height: f64) -> Self
pub fn min_inner_size(self, min_width: f64, min_height: f64) -> Self
Window min inner size in logical pixels.
Sourcepub fn max_inner_size(self, max_width: f64, max_height: f64) -> Self
pub fn max_inner_size(self, max_width: f64, max_height: f64) -> Self
Window max inner size in logical pixels.
Sourcepub fn inner_size_constraints(self, constraints: WindowSizeConstraints) -> Self
pub fn inner_size_constraints(self, constraints: WindowSizeConstraints) -> Self
Window inner size constraints.
Sourcepub fn resizable(self, resizable: bool) -> Self
pub fn resizable(self, resizable: bool) -> Self
Whether the window is resizable or not. When resizable is set to false, native window’s maximize button is automatically disabled.
Sourcepub fn title<S: Into<String>>(self, title: S) -> Self
pub fn title<S: Into<String>>(self, title: S) -> Self
The title of the window in the title bar.
Sourcepub fn focus(self) -> Self
👎Deprecated since 1.2.0: The window is automatically focused by default. This function Will be removed in 3.0.0. Use focused instead.
pub fn focus(self) -> Self
The window is automatically focused by default. This function Will be removed in 3.0.0. Use focused instead.
Sets the window to be initially focused.
Sourcepub fn focused(self, focused: bool) -> Self
pub fn focused(self, focused: bool) -> Self
Whether the window will be initially focused or not.
Sourcepub fn visible(self, visible: bool) -> Self
pub fn visible(self, visible: bool) -> Self
Whether the window should be immediately visible upon creation.
Sourcepub fn theme(self, theme: Option<Theme>) -> Self
pub fn theme(self, theme: Option<Theme>) -> Self
Forces a theme or uses the system settings if None was provided.
§Platform-specific
- macOS: Only supported on macOS 10.14+.
Sourcepub fn transparent(self, transparent: bool) -> Self
Available on non-macOS or crate feature macos-private-api only.
pub fn transparent(self, transparent: bool) -> Self
macos-private-api only.Whether the window should be transparent. If this is true, writing colors
with alpha values different than 1.0 will produce a transparent window.
Sourcepub fn content_protected(self, protected: bool) -> Self
pub fn content_protected(self, protected: bool) -> Self
Prevents the window contents from being captured by other apps.