NAME

Chandra::Window - Multi-window management for Chandra applications

SYNOPSIS

use Chandra::Window;

# Create a child window
my $settings = Chandra::Window->new(
    title   => 'Settings',
    width   => 400,
    height  => 300,
    content => '<h1>Settings</h1>',
);

# Window operations
$settings->set_title('Preferences');
$settings->set_content('<h1>Updated</h1>');
$settings->set_size(500, 400);
$settings->set_position(200, 200);
$settings->show;
$settings->hide;
$settings->focus;
$settings->close;

# Lifecycle hooks
$settings->on_close(sub {
    my ($win) = @_;
    return 1;  # Allow close (return 0 to prevent)
});

# Cross-window communication
$settings->on('save', sub {
    my ($data) = @_;
    print "Settings saved\n";
});
$settings->emit('save', { theme => 'dark' });

DESCRIPTION

Chandra::Window provides multi-window support for Chandra applications. Each window is a separate native window with its own WKWebView (on macOS).

This module is implemented entirely in XS for maximum performance.

CONSTRUCTOR

new

my $win = Chandra::Window->new(%options);

Creates a new window. Options:

title

Window title (default: "Window")

width, height

Window dimensions in pixels (default: 400x300)

x, y

Window position (-1 for system default)

resizable

Whether window can be resized (default: 1)

frameless

Borderless window (default: 0)

content

Initial HTML content

url

Initial URL to navigate to

Modal window mode (default: 0)

parent

Parent window for modal

id

Custom window identifier

METHODS

Content

set_content($html)

Set HTML content

Navigate to URL

eval($js)

Execute JavaScript

Properties

set_title($title)
set_size($width, $height)
set_position($x, $y)
get_size()

Returns ($width, $height)

get_position()

Returns ($x, $y)

State

show(), hide(), focus(), minimize(), maximize(), close()
is_visible(), is_modal(), is_closed()
set_modal($parent)
end_modal()

Callbacks

on_close($coderef)
on_resize($coderef)
on_focus($coderef)
on_blur($coderef)

Events

on($event, $coderef)

Register event handler

emit($event, @args)

Emit event to handlers

Class Methods

windows()

Returns all active windows

window_by_id($id)

Find window by custom ID

window_by_wid($wid)

Find window by native window ID

window_count()

Number of active windows

Accessors

wid()

Native window ID

id()

Custom window identifier

parent()

Parent window (if any)

children()

Child windows

AUTHOR

Robert Acock

LICENSE

Same as Perl itself.

Chandra::Window->windows

Returns all active window instances.

Chandra::Window->window_by_id($id)

Find a window by its custom ID.

Chandra::Window->window_count

Returns the number of active windows.

SEE ALSO

Chandra, Chandra::App