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 can work with both the default panel type or 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_nspanel::{panel, PanelBuilder, PanelLevel};

// Using default panel type
let panel = PanelBuilder::new(&app, "my-panel")
    .url(WebviewUrl::App("panel.html".into()))
    .title("Tool Panel")
    .level(PanelLevel::Floating)
    .build()?;

// Using custom panel type
panel!(CustomPanel {
    config: {
        can_become_key_window: false
    }
});

let custom = PanelBuilder::<_, CustomPanel>::new(&app, "custom")
    .url(WebviewUrl::App("custom.html".into()))
    .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 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_nspanel::{PanelBuilder, PanelLevel};
// Create a panel that floats above normal windows
PanelBuilder::new(&app, "floating")
    .level(PanelLevel::Floating)
    .build();

// Create a status-level panel (appears above floating panels)
PanelBuilder::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 the panel is released when closed

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

Set the window style mask

Style masks control the appearance and behavior of the window frame.

§Example
use tauri_nspanel::{PanelBuilder, StyleMask};
// Create a borderless panel
PanelBuilder::new(&app, "borderless")
    .style_mask(StyleMask::empty().borderless())
    .build();

// Create a HUD-style panel
PanelBuilder::new(&app, "hud")
    .style_mask(
        StyleMask::empty()
            .hud_window()
            .titled()
            .closable()
    )
    .build();
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_nspanel::{CollectionBehavior, PanelBuilder};
// Create a panel that appears on all spaces and doesn't participate in cycling
PanelBuilder::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_nspanel::{PanelBuilder, PanelLevel};
use tauri::WebviewUrl;
// Create a utility panel that doesn't steal focus
PanelBuilder::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_nspanel::PanelBuilder;
use tauri::WebviewUrl;
PanelBuilder::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_nspanel::PanelBuilder;
use tauri::WebviewUrl;
PanelBuilder::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_nspanel::PanelBuilder;
use tauri::WebviewUrl;
PanelBuilder::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> Freeze for PanelBuilder<'a, R, T>

§

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> Unpin for PanelBuilder<'a, R, T>
where T: Unpin,

§

impl<'a, R, T> !UnwindSafe 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> 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.
Source§

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

§

impl<T> ErasedDestructor for T
where T: 'static,