pub struct WindowBuilder { /* private fields */ }Expand description
Builder for test windows.
let window = WindowBuilder::new()
.title("Demo")
.size(640.0, 480.0)
.centered()
.background_color(Color::gray(0.1))
.build();
window.container().add_sublayer(&my_layer);
window.show_for(5.seconds());Implementations§
Source§impl WindowBuilder
impl WindowBuilder
Sourcepub fn position(self, x: f64, y: f64) -> Self
pub fn position(self, x: f64, y: f64) -> Self
Set the window position in screen coordinates.
This is mutually exclusive with centered().
Sourcepub fn centered(self) -> Self
pub fn centered(self) -> Self
Center the window on the selected screen.
This is mutually exclusive with position().
Sourcepub fn on_screen(self, screen: Screen) -> Self
pub fn on_screen(self, screen: Screen) -> Self
Select which screen to place the window on.
Defaults to Screen::Main.
Sourcepub fn background_color(self, color: impl Into<Color>) -> Self
pub fn background_color(self, color: impl Into<Color>) -> Self
Set the background color of the root container layer.
Accepts any type that implements Into<Color>, including:
Color::RED,Color::rgb(0.1, 0.1, 0.2)Color::WHITE.with_alpha(0.5)
Sourcepub fn background_rgba(self, r: f64, g: f64, b: f64, a: f64) -> Self
pub fn background_rgba(self, r: f64, g: f64, b: f64, a: f64) -> Self
Set the background color of the root container layer (RGBA, 0.0-1.0).
Sourcepub fn background_rgb(self, r: f64, g: f64, b: f64) -> Self
pub fn background_rgb(self, r: f64, g: f64, b: f64) -> Self
Set the background color of the root container layer (RGB with alpha=1.0).
Sourcepub fn style(self, style: WindowStyle) -> Self
pub fn style(self, style: WindowStyle) -> Self
Configure window style.
Sourcepub fn borderless(self) -> Self
pub fn borderless(self) -> Self
Make the window borderless (no title bar, not resizable).
Sourcepub fn activation_policy(self, policy: NSApplicationActivationPolicy) -> Self
pub fn activation_policy(self, policy: NSApplicationActivationPolicy) -> Self
Set the application activation policy.
Defaults to Accessory (no dock icon, no menu bar).
Sourcepub fn transparent(self) -> Self
pub fn transparent(self) -> Self
Make the window fully transparent for overlay effects.
When enabled, this sets the NSWindow to be non-opaque with a clear background, allowing the content to be drawn on a fully transparent background. This is useful for creating floating overlay windows.
§Example
use core_animation::prelude::*;
let window = WindowBuilder::new()
.size(200.0, 200.0)
.transparent()
.borderless()
.build();Sourcepub fn corner_radius(self, radius: f64) -> Self
pub fn corner_radius(self, radius: f64) -> Self
Set the corner radius on the container layer.
This applies rounded corners to the container layer that holds your content.
Combine with .background_color() for a rounded panel effect.
§Arguments
radius- The corner radius in points
§Example
use core_animation::prelude::*;
let window = WindowBuilder::new()
.size(200.0, 200.0)
.transparent()
.borderless()
.corner_radius(20.0)
.background_color(Color::gray(0.1).with_alpha(0.85))
.build();Sourcepub fn level(self, level: WindowLevel) -> Self
pub fn level(self, level: WindowLevel) -> Self
Set the window level (z-order).
Controls where the window appears in the window stack relative to other windows. Higher levels appear above lower levels.
§Arguments
level- The window level to set
§Example
use core_animation::prelude::*;
// Create an overlay that floats above all windows
let window = WindowBuilder::new()
.size(200.0, 200.0)
.level(WindowLevel::AboveAll)
.build();
// Or use a custom level
let window = WindowBuilder::new()
.level(WindowLevel::Custom(500))
.build();Sourcepub fn border_color(self, color: impl Into<Color>) -> Self
pub fn border_color(self, color: impl Into<Color>) -> Self
Set the border color on the container layer.
When set, this also applies a border width of 1.0 to the container layer. This creates a subtle visible border around the window content.
§Arguments
color- The border color
§Example
use core_animation::prelude::*;
// Create a window with a subtle gray border
let window = WindowBuilder::new()
.size(200.0, 200.0)
.transparent()
.borderless()
.corner_radius(20.0)
.background_color(Color::gray(0.1).with_alpha(0.85))
.border_color(Color::rgba(0.3, 0.3, 0.35, 0.5))
.build();Sourcepub fn non_activating(self) -> Self
pub fn non_activating(self) -> Self
Make the window non-activating (won’t steal focus from other apps).
When enabled, showing the window will not make it the key window or activate the application. The previously focused app remains focused.
This is ideal for OSD-style overlays that should appear above other windows without interrupting the user’s workflow.
§Example
use core_animation::prelude::*;
// Create an OSD that doesn't steal focus
let osd = WindowBuilder::new()
.size(200.0, 80.0)
.transparent()
.borderless()
.level(WindowLevel::ScreenSaver)
.non_activating()
.build();
osd.show_for(2.seconds()); // Shows without stealing focusSourcepub fn ignores_mouse_events(self) -> Self
pub fn ignores_mouse_events(self) -> Self
Make the window ignore mouse events (click-through).
When enabled, mouse clicks pass through the window to whatever is behind it. Useful for pure display overlays.
§Example
use core_animation::prelude::*;
// Create a click-through overlay
let overlay = WindowBuilder::new()
.size(200.0, 80.0)
.transparent()
.borderless()
.non_activating()
.ignores_mouse_events()
.build();Sourcepub fn layer<F>(self, name: &str, configure: F) -> Self
pub fn layer<F>(self, name: &str, configure: F) -> Self
Add a shape layer to the window.
The closure receives a CAShapeLayerBuilder for configuration.
The built layer will be added to Window::container() when build() is called.
This allows configuring shape layers inline in the fluent API, creating a fully fluent flow from window to layers to animations.
§Arguments
name- A unique identifier for this layerconfigure- A closure that configures the layer builder
§Examples
use core_animation::prelude::*;
let window = WindowBuilder::new()
.title("Animation Demo")
.size(400.0, 400.0)
.centered()
.transparent()
.borderless()
.background_color(Color::rgba(0.1, 0.1, 0.15, 0.85))
.layer("circle", |s| {
s.circle(80.0)
.position(CGPoint::new(200.0, 200.0))
.fill_color(Color::CYAN)
.animate("pulse", KeyPath::TransformScale, |a| {
a.values(0.85, 1.15)
.duration(2.seconds())
.autoreverses()
.repeat(Repeat::Forever)
})
})
.build();
window.show_for(10.seconds());Multiple layers can be added:
WindowBuilder::new()
.size(400.0, 400.0)
.layer("background_ring", |s| {
s.circle(200.0)
.position(CGPoint::new(200.0, 200.0))
.fill_color(Color::TRANSPARENT)
.stroke_color(Color::WHITE.with_alpha(0.3))
.line_width(2.0)
})
.layer("main_circle", |s| {
s.circle(80.0)
.position(CGPoint::new(200.0, 200.0))
.fill_color(Color::CYAN)
})
.build();Sourcepub fn text_layer<F>(self, name: &str, configure: F) -> Self
pub fn text_layer<F>(self, name: &str, configure: F) -> Self
Add a text layer to the window.
The closure receives a CATextLayerBuilder for configuration.
The built layer will be added to Window::container() when build() is called.
§Arguments
name- A unique identifier for this layerconfigure- A closure that configures the text layer builder
§Examples
use core_animation::prelude::*;
let window = WindowBuilder::new()
.title("Text Demo")
.size(400.0, 200.0)
.centered()
.transparent()
.borderless()
.background_color(Color::rgba(0.1, 0.1, 0.15, 0.85))
.text_layer("label", |t| {
t.text("Hello, World!")
.font_size(24.0)
.foreground_color(Color::WHITE)
.alignment(TextAlign::Center)
.position(CGPoint::new(200.0, 100.0))
})
.build();
window.show_for(5.seconds());Combining text with shape layers:
WindowBuilder::new()
.size(200.0, 100.0)
.layer("background", |s| {
s.circle(80.0)
.position(CGPoint::new(50.0, 50.0))
.fill_color(Color::BLUE)
})
.text_layer("label", |t| {
t.text("85%")
.font_size(16.0)
.foreground_color(Color::WHITE)
.position(CGPoint::new(150.0, 50.0))
})
.build();