line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2009-2017 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Tickit::Widget::HBox; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
783
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
9
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
10
|
1
|
|
|
1
|
|
3
|
use base qw( Tickit::Widget::LinearBox ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
306
|
|
11
|
|
|
|
|
|
|
use Tickit::Style; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use List::Util qw( sum max ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
C - distribute child widgets in a horizontal row |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Tickit; |
24
|
|
|
|
|
|
|
use Tickit::Widget::HBox; |
25
|
|
|
|
|
|
|
use Tickit::Widget::Static; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $hbox = Tickit::Widget::HBox->new; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
foreach my $position (qw( left centre right )) { |
30
|
|
|
|
|
|
|
$hbox->add( |
31
|
|
|
|
|
|
|
Tickit::Widget::Static->new( |
32
|
|
|
|
|
|
|
text => $position, |
33
|
|
|
|
|
|
|
align => $position, |
34
|
|
|
|
|
|
|
valign => "middle", |
35
|
|
|
|
|
|
|
), |
36
|
|
|
|
|
|
|
expand => 1 |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Tickit->new( root => $hbox )->run; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This subclass of L distributes its children in a |
45
|
|
|
|
|
|
|
horizontal row. Its height will be the height of the tallest child, and its |
46
|
|
|
|
|
|
|
width will be the sum of the widths of all the children, plus the inter-child |
47
|
|
|
|
|
|
|
spacing. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 STYLE |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The default style pen is used as the widget pen. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Note that while the widget pen is mutable and changes to it will result in |
54
|
|
|
|
|
|
|
immediate redrawing, any changes made will be lost if the widget style is |
55
|
|
|
|
|
|
|
changed. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
The following style keys are used: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=over 4 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item spacing => INT |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
The number of columns of spacing between children |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=back |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
style_definition base => |
70
|
|
|
|
|
|
|
spacing => 0; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
style_reshape_keys qw( spacing ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use constant WIDGET_PEN_FROM_STYLE => 1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub lines |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
my $self = shift; |
79
|
|
|
|
|
|
|
return max( 1, map { $_->requested_lines } $self->children ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub cols |
83
|
|
|
|
|
|
|
{ |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
my $spacing = $self->get_style_values( "spacing" ); |
86
|
|
|
|
|
|
|
return ( sum( map { $_->requested_cols } $self->children ) || 1 ) + |
87
|
|
|
|
|
|
|
$spacing * ( $self->children - 1 ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_total_quota |
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
my ( $window ) = @_; |
94
|
|
|
|
|
|
|
return $window->cols; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_child_base |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
my ( $child ) = @_; |
101
|
|
|
|
|
|
|
return $child->requested_cols; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub set_child_window |
105
|
|
|
|
|
|
|
{ |
106
|
|
|
|
|
|
|
my $self = shift; |
107
|
|
|
|
|
|
|
my ( $child, $left, $cols, $window ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if( $window and $cols ) { |
110
|
|
|
|
|
|
|
if( my $childwin = $child->window ) { |
111
|
|
|
|
|
|
|
$childwin->change_geometry( 0, $left, $window->lines, $cols ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
|
|
|
|
|
|
my $childwin = $window->make_sub( 0, $left, $window->lines, $cols ); |
115
|
|
|
|
|
|
|
$child->set_window( $childwin ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else { |
119
|
|
|
|
|
|
|
if( my $childwin = $child->window ) { |
120
|
|
|
|
|
|
|
$child->set_window( undef ); |
121
|
|
|
|
|
|
|
$childwin->close; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Paul Evans |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
0x55AA; |