Struct tauri::window::WindowBuilder

source ·
pub struct WindowBuilder<'a, R: Runtime, M: Manager<R>> { /* private fields */ }
Available on crate feature 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>

source

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, see the Webview2 issue. You should use async commands 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();
}
source

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, see the Webview2 issue. You should use async commands 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();
}
source

pub fn on_menu_event<F: Fn(&Window<R>, MenuEvent) + Send + Sync + 'static>( self, f: F ) -> Self

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

pub fn build(self) -> Result<Window<R>>

Creates a new window.

source§

impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M>

Desktop APIs.

source

pub fn menu(self, menu: Menu<R>) -> Self

Sets the menu for the window.

source

pub fn center(self) -> Self

Show window in the center of the screen.

source

pub fn position(self, x: f64, y: f64) -> Self

The initial position of the window’s.

source

pub fn inner_size(self, width: f64, height: f64) -> Self

Window size.

source

pub fn min_inner_size(self, min_width: f64, min_height: f64) -> Self

Window min inner size.

source

pub fn max_inner_size(self, max_width: f64, max_height: f64) -> Self

Window max inner size.

source

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.

source

pub fn maximizable(self, maximizable: bool) -> Self

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.
source

pub fn minimizable(self, minimizable: bool) -> Self

Whether the window’s native minimize button is enabled or not.

§Platform-specific
  • Linux / iOS / Android: Unsupported.
source

pub fn closable(self, closable: bool) -> Self

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.
source

pub fn title<S: Into<String>>(self, title: S) -> Self

The title of the window in the title bar.

source

pub fn fullscreen(self, fullscreen: bool) -> Self

Whether to start the window in fullscreen or not.

source

pub fn focus(self) -> Self

👎Deprecated since 1.2.0: The window is automatically focused by default. This function Will be removed in 2.0.0. Use focused instead.

Sets the window to be initially focused.

source

pub fn focused(self, focused: bool) -> Self

Whether the window will be initially focused or not.

source

pub fn maximized(self, maximized: bool) -> Self

Whether the window should be maximized upon creation.

source

pub fn visible(self, visible: bool) -> Self

Whether the window should be immediately visible upon creation.

source

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+.
source

pub fn transparent(self, transparent: bool) -> Self

Available on non-macOS or crate feature 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.

source

pub fn decorations(self, decorations: bool) -> Self

Whether the window should have borders and bars.

source

pub fn always_on_bottom(self, always_on_bottom: bool) -> Self

Whether the window should always be below other windows.

source

pub fn always_on_top(self, always_on_top: bool) -> Self

Whether the window should always be on top of other windows.

source

pub fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self

Whether the window will be visible on all workspaces or virtual desktops.

§Platform-specific
  • Windows / iOS / Android: Unsupported.
source

pub fn content_protected(self, protected: bool) -> Self

Prevents the window contents from being captured by other apps.

source

pub fn icon(self, icon: Icon) -> Result<Self>

Sets the window icon.

source

pub fn skip_taskbar(self, skip: bool) -> Self

Sets whether or not the window icon should be hidden from the taskbar.

§Platform-specific
  • macOS: Unsupported.
source

pub fn shadow(self, enable: bool) -> Self

Sets whether or not the window has shadow.

§Platform-specific
  • Windows:
    • false has no effect on decorated window, shadows are always ON.
    • true will make undecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
  • Linux: Unsupported.
source

pub fn parent(self, parent: &Window<R>) -> Result<Self>

Sets a parent to the window to be created.

§Platform-specific
source

pub fn transient_for(self, parent: &Window<R>) -> Result<Self>

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.

source

pub fn transient_for_raw(self, parent: &impl IsA<Window>) -> Self

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.

source

pub fn effects(self, effects: WindowEffectsConfig) -> Self

Sets window effects.

Requires the window to be transparent.

§Platform-specific:

Trait Implementations§

source§

impl<'a, R: Runtime, M: Manager<R>> Debug for WindowBuilder<'a, R, M>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, R, M> !RefUnwindSafe for WindowBuilder<'a, R, M>

§

impl<'a, R, M> Send for WindowBuilder<'a, R, M>

§

impl<'a, R, M> Sync for WindowBuilder<'a, R, M>

§

impl<'a, R, M> Unpin for WindowBuilder<'a, R, M>

§

impl<'a, R, M> !UnwindSafe for WindowBuilder<'a, R, M>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more