Tickit::WidgetRole::Movable - support for resizable/movable "panels"
package Tickit::Widget::MovingThing; use parent qw(Tickit::WidgetRole::Movable Tickit::Widget); sub lines { 2 } sub cols { 2 } sub render_to_rb { ... }
Apply this as a parent class to a widget to provide for resize/move semantics, similar to behaviour provided by common window managers.
Expects the widget to be contained by a parent object which provides a suitable area in which to resize/move the widget.
State information is stored in the _movable_role hashref in $self , so this requires instances to be blessed hashrefs.
_movable_role
$self
Minimum height to apply to this widget. Default is 2.
Minimum width to apply to this widget. Default is 2.
Empty implementation for Tickit::WidgetRole export_subs_for.
export_subs_for
Handle mouse events.
We can be in one of three states here: a mouse press, a drag event, or a release.
We delegate each of these to separate methods - see:
"mouse_press" - first click, this is either a one-off or the start of a drag event
"mouse_release" - mouse has been released, either after a click or after dragging
"mouse_drag" - one or more mouse buttons are pressed and the mouse has moved
Handle a mouse press event.
We're either in:
a corner - start resizing in both directions
an edge - start resizing in one dimension
the title bar - start moving the window
If this location is a corner of the window, return the appropriate constant (NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST), otherwise returns false.
If this location is an edge for this window, return the appropriate constant (NORTH, EAST, SOUTH, WEST), otherwise returns false.
If this location is somewhere in the title (currently defined as "top row, apart from corners and close button), returns true.
Start resizing from a corner.
Start resizing from an edge.
Start moving the window.
Deal with our drag events by changing window geometry accordingly.
Handle ongoing move events.
Resize action, from a corner.
Resize action - starting from an edge.
On release make sure we hand back input to the previous handler.
Default action when attempting to change geometry is to proxy this to the Tickit::Window directly. Override this in subclasses to implement constraints (e.g. clamp co-ordinates and pass to -SUPER::change_geometry >, or return early without applying the action) or linked window actions (move/resize another window after applying the geometry change to this one).
-
Tickit::Window
Tickit::WidgetRole::Borderable
Tom Molesworth <TEAM@cpan.org>
Copyright Tom Molesworth 2012-2024. Licensed under the same terms as Perl itself.
To install Tickit::WidgetRole::Movable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tickit::WidgetRole::Movable
CPAN shell
perl -MCPAN -e shell install Tickit::WidgetRole::Movable
For more information on module installation, please visit the detailed CPAN module installation guide.