I am relatively new to Perl and I am using wxPerl
to create a GUI application. Now, I want to add a Panel
into a Frame
, possibly using a sizer
so that the panel resizes automatically as the frame gets resized.
So here's what I got:
(1) I have to use a BoxSizer
, which stretch components in one direction.
(2) I have to pass parameters in the Add
subroutines to stretch components in another direction.
I wrote the following code:
package Main;
use Wx;
use parent 'Wx::App';
sub OnInit {
my $frame = Wx::Frame->new(undef, -1, "SimpleCalc ".$Information::VERSION_NO, [-1,-1], [-1,-1]);
my $centerPanel = Wx::Panel->new($frame, -1, [-1,-1], [-1,-1]);
#set red background
$centerPanel->SetBackgroundColour(Wx::Colour->new(255,0,0));
my $frameSizer = Wx::BoxSizer->new(wxHORIZONTAL);
$frameSizer->Add($centerPanel, 1, 0, 0);
$frame->SetSizer($frameSizer);
$frame->Center();
$frame->Show(1);
return 1;
}
my $app = Main->new;
$app->MainLoop;
The unwanted result:
What I want is to stretch the red panel in both (horizontal and vertical) direction, or in short, I want something similar to BorderLayout
in Java
.
According to some online tutorials, I tried to replace $frameSizer->Add($centerPanel, 1, 0, 0);
with
$frameSizer->Add($centerPanel, 1, wxEXPAND, 0);
, but the script doesn't run. An error occurs saying that it is unable to resolve overload for Wx::Sizer::Add(Wx::Panel, number, scalar, number). I also tried $frameSizer->Add($centerPanel, 1, 0, 0, wxEXPAND);
, but the frame obtained is exactly the same as the frame in the image.
Is it possible to have something similar to Java's BorderLayout
in wxPerl
? Thanks in advance.
P.S. I know there is a duplicate, but there are no concrete answers...