Skip to content

Commit

Permalink
move .checkable and .checked up to AbstractButton
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Dec 12, 2024
1 parent facbccd commit 94a1ffa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 79 deletions.
146 changes: 68 additions & 78 deletions Prima/Buttons.pm
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,37 @@ sub check_auto_size
}
}

sub checkable
{
return $_[0]-> {checkable} unless $#_;
$_[0]-> checked( 0) unless $_[0]-> {checkable} == $_[1];
$_[0]-> {checkable} = $_[1];
}

sub checked
{
return $_[0]-> {checked} unless $#_;
return unless $_[0]-> {checkable};
return if $_[0]-> {checked}+0 == $_[1]+0;
$_[0]-> {checked} = $_[1];
$_[0]-> repaint;
$_[0]-> notify( 'Check', $_[0]-> {checked});
}

sub toggle { my $i = $_[0]-> checked; $_[0]-> checked( !$i); return !$i;}
sub check { $_[0]-> checked(1)}
sub uncheck { $_[0]-> checked(0)}

package Prima::Button;
use vars qw(@ISA);
@ISA = qw(Prima::AbstractButton);
use base qw(Prima::AbstractButton);

my %standardGlyphScheme = (
glyphs => 4,
defaultGlyph => 0,
hiliteGlyph => 0,
disabledGlyph => 1,
pressedGlyph => 2,
holdGlyph => 3,
glyphs => 4,
defaultGlyph => 0,
hiliteGlyph => 0,
disabledGlyph => 1,
pressedGlyph => 2,
holdGlyph => 3,
);

sub profile_default
Expand Down Expand Up @@ -808,27 +828,6 @@ sub borderWidth
$self-> repaint;
}

sub checkable
{
return $_[0]-> {checkable} unless $#_;
$_[0]-> checked( 0) unless $_[0]-> {checkable} == $_[1];
$_[0]-> {checkable} = $_[1];
}

sub checked
{
return $_[0]-> {checked} unless $#_;
return unless $_[0]-> { checkable};
return if $_[0]-> {checked}+0 == $_[1]+0;
$_[0]-> {checked} = $_[1];
$_[0]-> repaint;
$_[0]-> notify( 'Check', $_[0]-> {checked});
}

sub toggle { my $i = $_[0]-> checked; $_[0]-> checked( !$i); return !$i;}
sub check { $_[0]-> checked(1)}
sub uncheck { $_[0]-> checked(0)}

sub default
{
return $_[0]-> {default} unless $#_;
Expand Down Expand Up @@ -941,10 +940,8 @@ sub glyphs


package Prima::Cluster;
use vars qw(@ISA @images);
@ISA = qw(Prima::AbstractButton);

my @images;
our @images;
use base qw(Prima::AbstractButton);

Prima::Application::add_startup_notification( sub {
my $i = 0;
Expand All @@ -967,6 +964,7 @@ sub profile_default
%{$_[ 0]-> SUPER::profile_default},
auto => 1,
checked => 0,
checkable => 1,
height => 36,
ownerBackColor => 1,
}
Expand All @@ -976,12 +974,15 @@ sub init
{
my $self = shift;
my %profile = $self-> SUPER::init(@_);
$self-> { auto } = $profile{ auto };
$self-> { checked} = $profile{ checked};
$self-> {auto } = $profile{ auto };
$self-> {checked} = $profile{ checked};
$self-> {checkable} = 1;
$self-> check_auto_size;
return %profile;
}

sub checkable { 1 }

sub on_keydown
{
my ( $self, $code, $key, $mod, $repeat) = @_;
Expand Down Expand Up @@ -1036,8 +1037,7 @@ sub calc_geom_size
}

package Prima::CheckBox;
use vars qw(@ISA);
@ISA = qw(Prima::Cluster);
use base qw(Prima::Cluster);

sub profile_default
{
Expand Down Expand Up @@ -1179,8 +1179,8 @@ sub on_paint
}

package Prima::Radio;
use vars qw(@ISA @images);
@ISA = qw(Prima::Cluster);
our @images;
use base qw(Prima::Cluster);

sub profile_default
{
Expand Down Expand Up @@ -1330,8 +1330,7 @@ sub checked


package Prima::SpeedButton;
use vars qw(@ISA);
@ISA = qw(Prima::Button);
use base qw(Prima::Button);

sub profile_default
{
Expand All @@ -1351,8 +1350,7 @@ sub calc_geom_size
}

package Prima::PopupButton;
use vars qw(@ISA);
@ISA = qw(Prima::SpeedButton);
use base qw(Prima::SpeedButton);

use constant MARGIN => 26;
use constant TRIANGLE => 0.2;
Expand Down Expand Up @@ -1432,8 +1430,7 @@ sub on_check
}

package Prima::GroupBox;
use vars qw(@ISA);
@ISA=qw(Prima::Widget);
use base qw(Prima::Widget);

{
my %RNT = (
Expand Down Expand Up @@ -1672,6 +1669,20 @@ Called whenever the user activates the button.
=over
=item checkable BOOLEAN
Selects if the button toggles the L<checked> state when the user
presses it.
Default value: 0
=item checked BOOLEAN
Selects whether the button is checked or not. Only actual
when the L<checkable> property is set. See also L<holdGlyph>.
Default value: 0
=item hotKey CHAR
A key (defined by CHAR) that the button will react to if pressed if the button
Expand Down Expand Up @@ -1705,6 +1716,10 @@ font currently selected on the CANVAS.
If CANVAS is undefined, the widget's font is used for the calculations instead.
=item check
Alias to C<checked(1)>
=item draw_veil CANVAS, X1, Y1, X2, Y2
Draws a rectangular veil shape over the CANVAS in given boundaries.
Expand All @@ -1722,6 +1737,14 @@ draws a dotted rectangle around the text.
Returns four integers that define the pixel widths of the margins between button exterior and
interior text and/or image
=item toggle
Reverts the C<checked> state of the button and returns the new state.
=item uncheck
Alias to C<checked(0)>
=back
=head1 Prima::Button
Expand Down Expand Up @@ -1773,20 +1796,6 @@ Width of the border around the button.
Default value: depends on the skin
=item checkable BOOLEAN
Selects if the button toggles the L<checked> state when the user
presses it.
Default value: 0
=item checked BOOLEAN
Selects whether the button is checked or not. Only actual
when the L<checkable> property is set. See also L<holdGlyph>.
Default value: 0
=item default BOOLEAN
Defines if the button should react when the user presses the enter button. If
Expand Down Expand Up @@ -1936,25 +1945,6 @@ In a special case when L<text> is an empty string, the image is centered.
=back
=head2 Methods
=over
=item check
Alias to C<checked(1)>
=item uncheck
Alias to C<checked(0)>
=item toggle
Reverts the C<checked> state of the button and returns the new state.
=back
=head1 Prima::SpeedButton
A convenience class, same as L<Prima::Button> but with default
Expand Down
2 changes: 1 addition & 1 deletion examples/buttons2.pl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ =head1 FEATURES
);

$w-> insert( PopupButton =>
origin => [ 250, 10],
origin => [ 230, 10],
image => $j,
glyphs => 2,
text => 0,
Expand Down

0 comments on commit 94a1ffa

Please sign in to comment.