Tickit-Widget-Layout-Desktop

 view release on metacpan or  search on metacpan

lib/Tickit/Widget/Layout/Desktop.pm  view on Meta::CPAN

<p><img src="http://tickit.perlsite.co.uk/cpan-screenshot/tickit-widget-layout-desktop1.gif" alt="Desktop widget in action" width="539" height="315"></p>

=end HTML

Constructed of:

=over 4

=item * L<Tickit::Widget::Layout::Desktop::Window> - the window implementation

=item * this class - background desktop on which the floats are displayed

=back

and maybe later:

=over 4

=item * ::Desktop::Taskbar - a subclass of statusbar which provides
window lists and launchers

=back

=cut

use curry::weak;
use List::UtilsBy;
use Scalar::Util qw(refaddr);
use List::Util qw(max pairmap);
use Tickit::Utils qw(textwidth distribute);

use Tickit::Widget::Menu;
use Tickit::Widget::Menu::Item;

use Tickit::Widget::Layout::Desktop::Window;
use Variable::Disposition;

use constant CAN_FOCUS => 1;
use constant WIDGET_PEN_FROM_STYLE => 1;

=head1 METHODS

=cut

method lines { 1 }
method cols { 1 }

=head2 render_to_rb

Clears the exposed area. All rendering happens in the
floating windows on top of this widget.

=cut

method render_to_rb ($rb, $rect) {
    $rb->eraserect($rect);
}

method children { @{$self->{widgets}} }

=head2 overlay

Render all window outlines on top of the target widget.

Takes the following parameters:

=over 4

=item * $rb - the L<Tickit::RenderBuffer> we will be drawing into

=item * $exclude - the current L<Tickit::Widget> we are drawing - this will be used
to check for intersections so we don't waste time drawing unrelated areas

=back

=cut

method overlay ($rb, $rect, $exclude) {
    my $target = $exclude->window->rect;

    # TODO change this when proper accessors are available
    my %win_map = map {
        refaddr($_->window) => $_
    } @{$self->{widgets}};
    delete $win_map{refaddr($exclude->window)};

    # Each child widget, from back to front
    CHILD:
    foreach my $child (reverse grep defined, map $win_map{refaddr($_)}, $self->window->subwindows) {
        next CHILD unless my $w = $child->window;
        next CHILD unless $w->rect->intersects($target);

        # Clear out anything that would be under this window,
        # so we don't draw lines that are obscured by upper
        # layers
        $rb->eraserect(
            $w->rect
        );

        # Let the child window render itself to the given
        # context, since it knows more about styles than we do
        $child->render_frame($rb, $target);
    }
}

=head2 window_gained

Records our initial window geometry when the L<Tickit::Window> is first attached.

=cut

method window_gained ($win) {
    $self->{geometry} = {
        map { $_ => $win->$_ } qw(top left lines cols)
    };
    $self->SUPER::window_gained($win);

}

=head2 create_panel

Creates a L<Tickit::Widget::Layout::Desktop::Window> on this L<Tickit::Widget::Layout::Desktop>.

Takes the following named parameters:

=over 4

=item * top - offset from top of desktop

=item * left - offset from desktop left margin

=item * lines - how many lines the new widget will have, should be >2 to display anything useful

=item * cols - how many columns the new widget will have, should be >2 to display anything useful

=item * label - what label to use, default is the uninspiring text C<window>

=back



( run in 1.593 second using v1.01-cache-2.11-cpan-39bf76dae61 )