WindowBuilder

Struct WindowBuilder 

Source
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

Source

pub fn new() -> Self

Create a new window builder with default settings.

Source

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

Set the window title.

Source

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

Set the window size in points.

Source

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

Set the window position in screen coordinates. This is mutually exclusive with centered().

Source

pub fn centered(self) -> Self

Center the window on the selected screen. This is mutually exclusive with position().

Source

pub fn on_screen(self, screen: Screen) -> Self

Select which screen to place the window on. Defaults to Screen::Main.

Source

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)
Source

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

Source

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

Source

pub fn style(self, style: WindowStyle) -> Self

Configure window style.

Source

pub fn borderless(self) -> Self

Make the window borderless (no title bar, not resizable).

Source

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

Set whether the window has a title bar.

Source

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

Set whether the window is closable.

Source

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

Set whether the window is resizable.

Source

pub fn activation_policy(self, policy: NSApplicationActivationPolicy) -> Self

Set the application activation policy. Defaults to Accessory (no dock icon, no menu bar).

Source

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();
Source

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();
Source

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();
Source

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();
Source

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 focus
Source

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();
Source

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 layer
  • configure - 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();
Source

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 layer
  • configure - 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();
Source

pub fn build(self) -> Window

Build the window.

§Panics

Panics if not called from the main thread.

Trait Implementations§

Source§

impl Default for WindowBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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,