Skip to main content

PanelBuilder

Struct PanelBuilder 

Source
pub struct PanelBuilder<'a, R: Runtime, T: FromWindow<R> + 'static> { /* private fields */ }
Expand description

Builder for creating panels with Tauri-like API

PanelBuilder provides a fluent interface that creates a Tauri window, converts it to an NSPanel, and applies panel-specific configurations. It works with custom panel classes created with the panel! macro.

§Type Parameters

  • R: The Tauri runtime type
  • T: The panel type (must implement FromWindow<R>)

§Example

use tauri::{AppHandle, WebviewUrl};
use tauri_nspanel::{tauri_panel, PanelBuilder, PanelLevel};

tauri_panel! {
    panel!(ToolPanel {
        config: {
            can_become_key_window: false
        }
    })
}

let _panel = PanelBuilder::<_, ToolPanel>::new(app, "my-panel")
    .url(WebviewUrl::App("panel.html".into()))
    .title("Tool Panel")
    .level(PanelLevel::Floating)
    .build()?;

Implementations§

Source§

impl<'a, R: Runtime + 'a, T: FromWindow<R> + 'static> PanelBuilder<'a, R, T>

Source

pub fn new(handle: &'a AppHandle<R>, label: impl Into<String>) -> Self

Create a new PanelBuilder

Source

pub fn url(self, url: WebviewUrl) -> Self

Set the webview URL

Source

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

Set the window title

Source

pub fn position(self, position: Position) -> Self

Set the window position

Source

pub fn size(self, size: Size) -> Self

Set the window size

Source

pub fn min_size(self, size: Size) -> Self

Set the minimum content size of the panel.

Source

pub fn max_size(self, size: Size) -> Self

Set the maximum content size of the panel.

Source

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

Set whether the panel can be resized by the user.

Source

pub fn resize_direction(self, direction: ResizeDirection) -> Self

Limit resizing to one axis.

The dimension on the disabled axis is fixed to the panel’s content size after its minimum and maximum size constraints have been applied.

Source

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

Set whether the panel floats above other windows

Source

pub fn level(self, level: PanelLevel) -> Self

Set the window level

The window level determines the panel’s position in the window hierarchy. Higher levels appear above lower levels.

§Example
use tauri::AppHandle;
use tauri_nspanel::{tauri_panel, PanelBuilder, PanelLevel};

tauri_panel! {
    panel!(LevelPanel {})
}

// Create a panel that floats above normal windows
let _floating = PanelBuilder::<_, LevelPanel>::new(app, "floating")
    .level(PanelLevel::Floating)
    .build()?;

// Create a status-level panel (appears above floating panels)
let _status = PanelBuilder::<_, LevelPanel>::new(app, "status")
    .level(PanelLevel::Status)
    .build()?;
Source

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

Set whether the panel has a shadow

Source

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

Set whether the panel is opaque

Source

pub fn alpha_value(self, alpha: f64) -> Self

Set the alpha value (transparency)

Source

pub fn hides_on_deactivate(self, hides: bool) -> Self

Set whether the panel hides when the app is deactivated

Source

pub fn becomes_key_only_if_needed(self, value: bool) -> Self

Set whether the panel becomes key window only if needed

Source

pub fn accepts_mouse_moved_events(self, value: bool) -> Self

Set whether the panel accepts mouse moved events

Source

pub fn ignores_mouse_events(self, value: bool) -> Self

Set whether the panel ignores mouse events

Source

pub fn movable_by_window_background(self, value: bool) -> Self

Set whether the panel is movable by its background

Source

pub fn released_when_closed(self, value: bool) -> Self

Set whether AppKit releases the panel when it closes.

This should normally remain false for Tauri-managed panels. Panel::to_window restores it to false before returning ownership to Tauri.

Source

pub fn works_when_modal(self, value: bool) -> Self

Set whether the panel works when modal dialogs are displayed

Source

pub fn content_size(self, size: Size) -> Self

Set the content size (inner size excluding window decorations)

Source

pub fn style_mask(self, style_mask: StyleMask) -> Self

Replace the window style mask.

Style masks control the appearance and behavior of the window frame. AppKit may reject structural changes to a live window; Self::build returns that error instead of aborting the process. Prefer Self::add_style_mask when only enabling additional behavior.

§Example
use tauri::AppHandle;
use tauri_nspanel::{tauri_panel, PanelBuilder, StyleMask};

tauri_panel! {
    panel!(StyledPanel {})
}

// Create the native window without decorations before applying the exact mask.
let _borderless = PanelBuilder::<_, StyledPanel>::new(app, "borderless")
    .with_window(|window| window.decorations(false))
    .style_mask(StyleMask::empty().nonactivating_panel())
    .build()?;
Source

pub fn add_style_mask(self, style_mask: StyleMask) -> Self

Add flags to the window’s existing style mask.

This preserves the structural styles selected by Tauri and is the preferred way to enable panel behavior such as StyleMask::nonactivating_panel.

Source

pub fn collection_behavior(self, behavior: CollectionBehavior) -> Self

Set the collection behavior

Collection behaviors control how the panel participates in Spaces, Exposé, and fullscreen mode on macOS.

§Example
use tauri::AppHandle;
use tauri_nspanel::{tauri_panel, CollectionBehavior, PanelBuilder};

tauri_panel! {
    panel!(SpacesPanel {})
}

// Create a panel that appears on all spaces and doesn't participate in cycling
let _panel = PanelBuilder::<_, SpacesPanel>::new(app, "tool-panel")
    .collection_behavior(
        CollectionBehavior::new()
            .can_join_all_spaces()
            .ignores_cycle()
    )
    .build()?;
Source

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

Prevent focus stealing during window creation

Since PanelBuilder creates a regular window before converting it to a panel, the window creation phase can steal focus. When set to true, the application’s activation policy is temporarily set to Prohibited during window creation, preventing this focus interruption.

This works particularly well with apps that use ActivationPolicy::Accessory, ensuring the window is created silently before being converted to a panel.

§Example
use tauri::{AppHandle, WebviewUrl};
use tauri_nspanel::{tauri_panel, PanelBuilder, PanelLevel};

tauri_panel! {
    panel!(UtilityPanel {})
}

// Create a utility panel that doesn't steal focus
let _panel = PanelBuilder::<_, UtilityPanel>::new(app, "utility")
    .url(WebviewUrl::App("utility.html".into()))
    .no_activate(true)
    .level(PanelLevel::Floating)
    .build()?;
Source

pub fn corner_radius(self, radius: f64) -> Self

Set the corner radius for rounded corners

This enables the layer-backed view and sets the corner radius on the panel’s layer, giving the panel rounded corners with the specified radius.

§Example
use tauri::{AppHandle, WebviewUrl};
use tauri_nspanel::{tauri_panel, PanelBuilder};

tauri_panel! {
    panel!(RoundedPanel {})
}

let _panel = PanelBuilder::<_, RoundedPanel>::new(app, "rounded-panel")
    .url(WebviewUrl::App("index.html".into()))
    .corner_radius(10.0)  // 10pt corner radius
    .build()?;
Source

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

Set the panel background to be transparent

This sets the window background color to clear and makes the panel non-opaque, allowing content behind the panel to show through.

§Example
use tauri::{AppHandle, WebviewUrl};
use tauri_nspanel::{tauri_panel, PanelBuilder};

tauri_panel! {
    panel!(TransparentPanel {})
}

let _panel = PanelBuilder::<_, TransparentPanel>::new(app, "transparent-panel")
    .url(WebviewUrl::App("index.html".into()))
    .transparent(true)  // Transparent background
    .build()?;
Source

pub fn with_window<F>(self, f: F) -> Self
where F: FnOnce(WebviewWindowBuilder<'a, R, AppHandle<R>>) -> WebviewWindowBuilder<'a, R, AppHandle<R>> + 'static,

Apply a custom configuration function to the WebviewWindowBuilder

This allows access to any Tauri window configuration not exposed by the panel builder. The closure receives the WebviewWindowBuilder and should return it after applying any desired configurations.

§Example
use tauri::{AppHandle, WebviewUrl};
use tauri_nspanel::{tauri_panel, PanelBuilder};

tauri_panel! {
    panel!(ConfiguredPanel {})
}

let _panel = PanelBuilder::<_, ConfiguredPanel>::new(app, "my-panel")
    .url(WebviewUrl::App("index.html".into()))
    .with_window(|window| {
        window
            .min_inner_size(300.0, 200.0)
            .max_inner_size(800.0, 600.0)
            .resizable(false)
            .decorations(false)
            .always_on_top(true)
            .skip_taskbar(true)
    })
    .build()?;
Source

pub fn build(self) -> Result<Arc<dyn Panel<R>>>

Build the panel

Creates a Tauri window using the configured properties, converts it to an NSPanel, and applies all panel-specific settings.

Auto Trait Implementations§

§

impl<'a, R, T> !RefUnwindSafe for PanelBuilder<'a, R, T>

§

impl<'a, R, T> !Send for PanelBuilder<'a, R, T>

§

impl<'a, R, T> !Sync for PanelBuilder<'a, R, T>

§

impl<'a, R, T> !UnwindSafe for PanelBuilder<'a, R, T>

§

impl<'a, R, T> Freeze for PanelBuilder<'a, R, T>

§

impl<'a, R, T> Unpin for PanelBuilder<'a, R, T>
where T: Unpin,

§

impl<'a, R, T> UnsafeUnpin for PanelBuilder<'a, R, T>

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> AutoreleaseSafe for T
where T: ?Sized,

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.

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>,

Source§

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>,

Source§

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.