To position widgets in the MainWindow, you can use the
Example 1
use Prima qw(Application Themes Buttons); $mw = Prima::MainWindow-> create( text => "Pack ex. 1", sizeMin => [250, 200], sizeMax => [250, 200], skin => 'flat', ); $mw-> insert( Button => pack => { fill => 'none', side => 'top', pad => 10 }, # side => 'top' can be omitted: 'top' is the default value text => "none - top - 10", onClick => sub { $::application-> close }, ); run Prima;
use Prima qw(Application Themes Buttons); $mw = Prima::MainWindow-> create( text => "Pack ex. 2", sizeMin => [250, 200], sizeMax => [250, 200], skin => 'flat', ); $mw-> insert( Button => pack => { fill => 'x', side => 'top', pad => 10 }, # fill => 'x' increases the button size horizontally text => "x - top - 10", onClick => sub { $::application-> close }, ); run Prima;
use Prima qw(Application Themes Buttons); my $mw = Prima::MainWindow-> create( text => "Pack ex. 3", sizeMin => [250, 200], sizeMax => [250, 200], ); $mw-> insert( Button => pack => { fill => 'none', side => 'top', pad => 10 }, text => "none - top - 10", onClick => sub { $::application-> close }, ); $mw-> insert( Button => pack => { fill => 'none', side => 'bottom', pad => 10 }, text => "none - bottom - 10", onClick => sub { $::application-> close }, ); run Prima;
use Prima qw(Application Themes Buttons); my $mw = Prima::MainWindow-> create( text => "Pack ex. 4", sizeMin => [250, 200], sizeMax => [250, 200], skin => 'flat', ); $mw-> insert( Button => pack => { fill => 'none', side => 'top', pad => 20 }, # horizontal and vertical external padding 20 text => "none - top - 20", onClick => sub { $::application-> close }, ); $mw-> insert( Button => pack => { fill => 'none', side => 'top', pad => 20 }, text => "none - top - 20", onClick => sub { $::application-> close }, ); $mw-> insert( Button => pack => { fill => 'none', side => 'top', pad => 20 }, text => "none - top - 20", onClick => sub { $::application-> close }, ); run Prima;
use Prima qw(Application Themes Buttons Label); my $mw = Prima::MainWindow-> create( text => "Pack ex. 5", sizeMin => [425, 200], sizeMax => [425, 200], skin => 'flat', ); $output = $mw-> insert( Label => pack => { fill => 'none', side => 'top', pad => 20 }, text => "Buttons on a row", autoHeight => 1, font => { size => 18, }, ); $mw-> insert( Button => pack => { fill => 'x', side => 'left', pad => 20 }, # horizontal and vertical external padding 20 text => "x - left - 20", onClick => sub { $::application-> close }, ); $mw-> insert( Button => pack => { fill => 'x', side => 'left', pad => 20 }, text => "x - left - 20", onClick => sub { $::application-> close }, ); $mw-> insert( Button => pack => { fill => 'x', side => 'left', pad => 20 }, text => "x - left - 20", onClick => sub { $::application-> close }, ); run Prima;
To set the background color of PB_2 to the white color, you could write:$mw-> insert( Button => pack => { fill => 'x', side => 'left', pad => 20 }, # horizontal and vertical external padding 20 name => "PB_1", text => "x - left - 20", onClick => sub { $::application-> close }, ); $mw-> insert( Button => pack => { fill => 'x', side => 'left', pad => 20 }, name => "PB_2", text => "x - left - 20", onClick => sub { $::application-> close }, ); $mw-> insert( Button => pack => { fill => 'x', side => 'left', pad => 20 }, name => "PB_3", text => "x - left - 20", onClick => sub { $::application-> close }, );
Alternatively, you can omit the name property and define an object like this:$mw-> PB_2-> backColor(0xFFFFFF);
To set the background color of this button to the white color, you could write:$PB_2 = $mw-> insert( Button => pack => { fill => 'x', side => 'left', pad => 20 }, text => "x - left - 20", onClick => sub { $::application-> close }, );
$PB_2-> backColor(0xFFFFFF);
use Prima qw(Application Themes Buttons Label); $mw = Prima::MainWindow-> create( text => "Random", sizeMin => [250, 200], sizeMax => [250, 200], ); $mw-> borderIcons(bi::SystemMenu); # system menu button and/or close button ( usually with icon ) is shown $output = $mw-> insert( Label => pack => { fill => 'none', side => 'top', pad => 50 }, size => [50, 50], text => "", font => { size => 26, }, ); $mw-> insert( Button => pack => { fill => 'none', side => 'top', pad => 50 }, size => [150, 50],# explicit definition of size; otherwise Prima would determine text => "Random number!", default => 1, onClick => sub { $random_number = int(rand(100)); $output-> set(text => $random_number); }, ); run Prima;