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 typeT: The panel type (must implementFromWindow<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>
impl<'a, R: Runtime + 'a, T: FromWindow<R> + 'static> PanelBuilder<'a, R, T>
Sourcepub fn new(handle: &'a AppHandle<R>, label: impl Into<String>) -> Self
pub fn new(handle: &'a AppHandle<R>, label: impl Into<String>) -> Self
Create a new PanelBuilder
Sourcepub fn resizable(self, resizable: bool) -> Self
pub fn resizable(self, resizable: bool) -> Self
Set whether the panel can be resized by the user.
Sourcepub fn resize_direction(self, direction: ResizeDirection) -> Self
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.
Sourcepub fn level(self, level: PanelLevel) -> Self
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()?;Sourcepub fn has_shadow(self, has_shadow: bool) -> Self
pub fn has_shadow(self, has_shadow: bool) -> Self
Set whether the panel has a shadow
Sourcepub fn alpha_value(self, alpha: f64) -> Self
pub fn alpha_value(self, alpha: f64) -> Self
Set the alpha value (transparency)
Sourcepub fn hides_on_deactivate(self, hides: bool) -> Self
pub fn hides_on_deactivate(self, hides: bool) -> Self
Set whether the panel hides when the app is deactivated
Sourcepub fn becomes_key_only_if_needed(self, value: bool) -> Self
pub fn becomes_key_only_if_needed(self, value: bool) -> Self
Set whether the panel becomes key window only if needed
Sourcepub fn accepts_mouse_moved_events(self, value: bool) -> Self
pub fn accepts_mouse_moved_events(self, value: bool) -> Self
Set whether the panel accepts mouse moved events
Sourcepub fn ignores_mouse_events(self, value: bool) -> Self
pub fn ignores_mouse_events(self, value: bool) -> Self
Set whether the panel ignores mouse events
Sourcepub fn movable_by_window_background(self, value: bool) -> Self
pub fn movable_by_window_background(self, value: bool) -> Self
Set whether the panel is movable by its background
Sourcepub fn released_when_closed(self, value: bool) -> Self
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.
Sourcepub fn works_when_modal(self, value: bool) -> Self
pub fn works_when_modal(self, value: bool) -> Self
Set whether the panel works when modal dialogs are displayed
Sourcepub fn content_size(self, size: Size) -> Self
pub fn content_size(self, size: Size) -> Self
Set the content size (inner size excluding window decorations)
Sourcepub fn style_mask(self, style_mask: StyleMask) -> Self
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()?;Sourcepub fn add_style_mask(self, style_mask: StyleMask) -> Self
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.
Sourcepub fn collection_behavior(self, behavior: CollectionBehavior) -> Self
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()?;Sourcepub fn no_activate(self, no_activate: bool) -> Self
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()?;Sourcepub fn corner_radius(self, radius: f64) -> Self
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()?;Sourcepub fn transparent(self, transparent: bool) -> Self
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()?;Sourcepub fn with_window<F>(self, f: F) -> Selfwhere
F: FnOnce(WebviewWindowBuilder<'a, R, AppHandle<R>>) -> WebviewWindowBuilder<'a, R, AppHandle<R>> + 'static,
pub fn with_window<F>(self, f: F) -> Selfwhere
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()?;