Skip to content

Commit

Permalink
add Header.gridColor, use it for DetailedList.gridColor
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Nov 12, 2024
1 parent 6720b32 commit a153a0b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
33 changes: 25 additions & 8 deletions Prima/DetailedList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ sub init
my $bw = $self-> borderWidth;
my @sz = $self-> size;

$self-> {header} = $self-> insert( $profile{headerClass} =>
name => 'Header',
origin => [ $bw, $sz[1] - $bw - $hh],
size => [ $sz[0] - $bw * 2, $hh],
vertical => 0,
growMode => gm::Ceiling,
items => $profile{headers},
widths => $profile{widths},
$self-> {header} = $self-> insert( $profile{headerClass} =>
name => 'Header',
origin => [ $bw, $sz[1] - $bw - $hh],
size => [ $sz[0] - $bw * 2, $hh],
vertical => 0,
growMode => gm::Ceiling,
items => $profile{headers},
widths => $profile{widths},
delegations => $profile{headerDelegations},
gridColor => $profile{gridColor},
(map { $_ => $profile{$_}} keys %hdrProps),
%{$profile{headerProfile}},
);
Expand Down Expand Up @@ -239,6 +240,22 @@ sub draw_items
$self-> draw_item_background( $canvas, @$_, 1, $clrs[3]) for @p_selected;
}

if ( $self->{drawGrid}) {
my $x = $xstart - $o + 1;
my @a = $self->get_active_area(1);
my @l;
for ( $ci = 0; $ci < $cols; $ci++) {
$x += $widths[ $ci] + 2;
push @l, $x, $a[1], $x, $a[3]
if $x >= $a[0] && $x <= $a[2];
}
if (@l) {
$self->color($self->{gridColor});
$self->lines(\@l);
$self->color($clrs[0]);
}
}

# draw veil
if ( $drawVeilFoc >= 0) {
my ( $itemIndex, $x, $y, $x2, $y2) = @{$$iref[$drawVeilFoc]};
Expand Down
50 changes: 37 additions & 13 deletions Prima/Widget/Header.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sub profile_default
vertical => 0,
selectable => 0,
syncPaint => 1,
gridColor => cl::Black,
);
@$def{keys %prf} = values %prf;
return $def;
Expand All @@ -68,7 +69,7 @@ sub init
$self-> {fontHeight} = $self-> font-> height;
$self-> {resetDisabled} = 1;
$self-> $_( $profile{$_})
for ( qw( vertical minTabWidth items widths offset pressed clickable scalable draggable));
for ( qw( vertical minTabWidth items widths offset pressed clickable scalable draggable gridColor));
if ( scalar @{$profile{widths}} == 0) {
$self-> autowidths;
$self-> repaint;
Expand All @@ -81,9 +82,10 @@ sub on_paint
my ( $self, $canvas) = @_;
my @size = $canvas-> size;
my @c = $self-> enabled ?
( $self-> color, $self-> backColor) :
( $self-> disabledColor, $self-> disabledBackColor);
( $self-> color, $self-> backColor) :
( $self-> disabledColor, $self-> disabledBackColor);
my @c3d = ( $self-> light3DColor, $self-> dark3DColor);
my @clip = $canvas->clipRect;

my ($prelightPart, $prelightColor) = (-1);
if ( defined $self->{prelight} ) {
Expand All @@ -102,15 +104,18 @@ sub on_paint
$showlines = 1;
}
my $v = $self-> {vertical};
my ( $x, $y) = ( - $self-> {offset}, ( $size[1] - $self-> {fontHeight}) / 2);
my ( $x, $y) = ( - $self-> {offset} + 1, ( $size[1] - $self-> {fontHeight}) / 2);
my $i;

my $pressed = $self-> {pressed};
@c3d = reverse @c3d if $v;
my ( $wx, $cx) = ( $self-> {widths}, $self-> {count});
my ( $notifier, @notifyParms) = $self-> get_notify_sub(q(DrawItem));
$self-> push_event;
my ( $d, $lim) = $v ? ( $x, $size[1]) : ( $x, $size[0]);
my ( $d, $lim) = $v ? ($x, $size[1]) : ($x, $size[0]);
my @grids;
my $grid_offset = $flat ? 0 : 1;

for ( $i = 0; $i < $cx; $i++) {
next unless $$wx[$i];
if ( $d + $$wx[$i] + 2 < 1) {
Expand Down Expand Up @@ -158,13 +163,18 @@ sub on_paint
}
NO_LINES:
$d += $$wx[$i] + 1;
$v ?
$canvas-> line( 1, $d, $size[0] - 2, $d) :
$canvas-> line( $d, 1, $d, $size[1] - 2)
if $showlines;
push @grids, $v ?
( $grid_offset, $d, $size[0] - $grid_offset - 1, $d) :
( $d, $grid_offset, $d, $size[1] - $grid_offset - 1)
if $showlines;
last if $d > $lim - 3;
$d++;
}
if ( @grids ) {
$canvas->clipRect(@clip);
$canvas->color($self->{gridColor});
$canvas->lines(\@grids);
}
$self-> pop_event;
}

Expand Down Expand Up @@ -388,15 +398,16 @@ sub on_mousemove
$self-> {widths}-> [$self-> {tabId}] = $nw;
my $o = $self-> {swidth} + $ow;
$self-> {maxWidth} += $nw - $ow;
my $go = ($self->skin eq 'flat') ? 0 : 1;
$self-> {vertical} ?
$self-> scroll(
0, $nw - $ow,
confineRect => [ 1, $o, $sz[0] - 1, $sz[1] - 1 + abs($nw - $ow)],
clipRect => [ 1, 1, $sz[0]-1, $sz[1]-1],
confineRect => [ $go, $o, $sz[0] - $go, $sz[1] - 1 + abs($nw - $ow)],
clipRect => [ $go, 1, $sz[0] - $go, $sz[1]-1],
) : $self-> scroll(
$nw - $ow, 0,
confineRect => [ $o, 1, $sz[0] - 1 + abs($nw - $ow), $sz[1] - 1],
clipRect => [ 1, 1, $sz[0]-1, $sz[1]-1],
confineRect => [ $o, $go, $sz[0] - 1 + abs($nw - $ow), $sz[1] - $go],
clipRect => [ 1, $go, $sz[0] - 1, $sz[1] - $go],
);
$self-> notify(q(SizeItem), $self-> {tabId}, $ow, $nw);
}
Expand Down Expand Up @@ -533,6 +544,13 @@ sub minTabWidth
$_[0]-> notify(q(SizeItems)) if $changed;
}

sub gridColor
{
return $_[0]-> {gridColor} unless $#_;
$_[0]->{gridColor} = $_[1];
$_[0]->repaint;
}

sub items
{
unless ( $#_) {
Expand Down Expand Up @@ -666,6 +684,12 @@ Selects if the user is allowed to move the tabs.
Default value: 1
=item gridColor COLOR
Sets the color of the divisor lines
Default value: cl::Black
=item items ARRAY
An array of scalars representing the internal data of the tabs.
Expand Down

0 comments on commit a153a0b

Please sign in to comment.