The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tickit::Window - a window for drawing operations

SYNOPSIS

DESCRIPTION

Provides coordination of widget drawing activities. A Window represents a region of the screen that a widget occupies.

Windows cannot directly be constructed. Instead they are obtained by sub-division of other windows, ultimately coming from the Tickit::RootWindow associated with the terminal.

METHODS

$cols = $win->cols

$lines = $win->lines

Obtain the size of the window

$win->resize( $lines, $cols )

Change the size of the window.

$win->reposition( $top, $left )

Move the window relative to its parent.

$win->change_geometry( $top, $left, $lines, $cols )

A combination of resize and reposition, to atomically change all the coordinates of the window. Will only invoke on_geom_changed once, rather than twice as would be the case calling the above methods individually.

$win->set_on_geom_changed( $on_geom_changed )

Set the callback to invoke whenever the window is resized or repositioned; i.e. whenever its geometry changes.

 $on_geom_changed->( $win )

$win->set_on_key( $on_key )

Set the callback to invoke whenever a key is pressed while this window, or one of its child windows, has the input focus.

 $handled = $on_key->( $win, $type, $str, $key )

$type will be text for normal unmodified Unicode, or key for special keys or modified Unicode. $str will be the UTF-8 string for text events, or the textual description of the key as rendered by Term::TermKey for key events. $key will be the underlying Term::TermKey::Key event structure.

The invoked code should return a true value if it considers the keypress dealt with, or false to pass it up to its parent window.

Before passing it to its parent, a window will also try any other non-focused sibling windows of the currently-focused window in order of creation (though note this order is not necessarily the order the child widgets that own those windows were created or added to their container).

If no window actually handles the keypress, then every window will eventually be consulted about it, preferring windows closer to the focused one.

This broadcast-like behaviour allows widgets to handle keypresses that should make sense even though their window does not actually have the keyboard focus. This feature should be used sparingly, to only capture one or two keypresses that really make sense; for example to capture the PageUp and PageDown keys in a scrolling list, or a numbered function key that performs some special action.

$win->set_on_mouse( $on_mouse )

Set the callback to invoke whenever a mouse event is received within the window's rectangle.

 $handled = $on_mouse->( $win, $ev, $buttons, $line, $col )

$ev will be press, drag or release. The button number will be in $button, though may not be present for release events. $line and $col are 0-based. Behaviour of events involving more than one mouse button is not well-specified by terminals.

The invoked code should return a true value if it considers the mouse event dealt with, or false to pass it up to its parent window. The mouse event is passed as defined by Tickit::Term's on_mouse event, except that the line and column counts will be relative to the window, not to the screen.

$parentwin = $win->parent

Returns the parent window; i.e. the window on which make_sub was called to create this one

$rootwin = $win->root

Returns the root window

$term = $win->term

Returns the Tickit::Term instance of the terminal on which this window lives.

$top = $win->top

$left = $win->left

Returns the coordinates of the start of the window, relative to the parent window.

$top = $win->abs_top

$left = $win->abs_left

Returns the coordinates of the start of the window, relative to the root window.

$pen = $win->pen

Returns the current Tickit::Pen object associated with this window

$win->set_pen( $pen )

Replace the current Tickit::Pen object for this window with a new one. The object reference will be stored, allowing it to be shared with other objects. If undef is set, then a new, blank pen will be constructed.

$val = $win->getpenattr( $attr )

Returns a single attribue from the current pen

%attrs = $win->getpenattrs

Retrieve the current pen settings for the window.

$val = $win->get_effective_penattr( $attr )

Returns the effective value of a pen attribute. This will be the value of this window's attribute if set, or the effective value of the attribute from its parent.

%attrs = $win->get_effective_penattrs

Retrieve the effective pen settings for the window. This will be the settings of the window and all its parents down to the root window, merged together.

$sub = $win->make_sub( $top, $left, $lines, $cols )

Constructs a new sub-window starting at the given coordinates of this window. It will be sized to the given limits.

$win->goto( $line, $col )

Moves the cursor to the given position within the window. Both $line and $col are 0-based.

$win->print( $text )

Print the given text to the terminal at the current cursor position using the pen of the window.

$win->penprint( $text, $pen )

$win->penprint( $text, %attrs )

Print the given text to the terminal at the current cursor position using the pen of the window, overridden by any extra attributes in the given Tickit::Pen instance, or directly in the given hash.

$win->erasech( $count, $moveend )

Erase $count columns forwards.

$success = $win->insertch( $count )

Insert $count blank characters, moving subsequent ones to the right. Note this can only be achieved if the window extends all the way to the righthand edge of the terminal, or else the operation would corrupt further windows beyond it.

If this window does not extend to the righthand edge, then this method will simply return false. If it does, the characters are inserted and the method returns true.

$success = $win->deletech( $count )

Delete $count characters, moving subsequent ones to the left, and inserting blanks at the end of the line. Note this can only be achieved if the window extends all the way to the righthand edge of the terminal, or else the operation would corrupt further windows beyond it.

If this window does not extend to the righthand edge, then this method will simply return false. If it does, the characters are inserted and the method returns true.

$success = $win->scroll( $downward, $rightward )

Attempt to scroll the contents of the window in the given direction. Most terminals cannot scroll arbitrary regions. If the terminal does not support the type of scrolling requested, this method returns false to indicate that the caller should instead redraw the required contents. If the scrolling was sucessful, the method returns true.

$win->focus( $line, $col )

Put the cursor at the given position in this window. Ensures the cursor remains at this position after drawing.

$win->restore

Restore the state of the terminal to its idle state. Places the cursor back at the focus position, and restores the pen.

$win->clearline( $line )

Erase the entire content of one line of the window

$win->clear

Erase the entire content of the window and reset it to the current background colour.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>