Commit d0076a8f by PotatoGim

GridSizer 예제 추가

parent 67df9ca9
......@@ -11,12 +11,16 @@
# LICENSE: Artistic License 2.0
# NOTE:
#=============================================================================
my $flag = $ARGV[0];
package MyApp;
use strict;
use warnings;
no warnings qw/experimental::smartmatch/;
use utf8;
use feature qw/switch/;
use base qw/Wx::App/;
use Wx qw/:everything/;
......@@ -26,7 +30,7 @@ sub OnInit
my ($frame, $sizer);
$frame = Wx::Frame->new(
undef, -1, "A Frame", wxDefaultPosition, wxSIZE(300, 200)
undef, -1, "A Frame - $flag", wxDefaultPosition, wxSIZE(300, 200)
);
$sizer = $self->init_sizer($frame);
......@@ -42,12 +46,86 @@ sub init_sizer
my ($self, $frame) = @_;
my ($sizer, $button);
if ($flag eq "flex")
{
$sizer = Wx::FlexGridSizer->new(2, 3);
my $add_button = sub {
my ($w, $h) = @_;
my $button = Wx::Button->new(
$frame, -1, "($w, $h)", wxDefaultPosition, wxSIZE($w, $h)
);
$sizer->Add($button);
};
$add_button->(90, 30);
$add_button->(70, 40);
$add_button->(50, 60);
$add_button->(50, 80);
$add_button->(50, 40);
$add_button->(80, 70);
return $sizer;
}
$sizer = Wx::GridSizer->new(2, 3);
foreach my $row (1 .. 2) {
foreach my $col (1 .. 3) {
foreach my $row (1 .. 2)
{
foreach my $col (1 .. 3)
{
$button = Wx::Button->new($frame, -1, "($row, $col)");
$sizer->Add($button);
given ($flag)
{
when ("default")
{
$sizer->Add($button);
}
when ("aligning")
{
$sizer->Add($button, 0, wxALIGN_BOTTOM|wxALIGN_RIGHT);
}
when ("growing")
{
if (($row + $col) % 2)
{
$sizer->Add($button, 0, wxGROW);
}
else
{
$sizer->Add($button);
}
}
when ("shaping")
{
if (($row + $col) % 2)
{
$sizer->Add($button, 0, wxSHAPED);
}
else
{
$sizer->Add($button);
}
}
when ("center shaping")
{
if (($row + $col) % 2)
{
$sizer->Add($button, 0, wxSHAPED|wxALIGN_CENTER_VERTICAL);
}
else
{
$sizer->Add($button);
}
}
when ("padding")
{
$sizer->Add($button, 0, wxGROW|wxTOP|wxBOTTOM, 20);
}
}
}
}
......@@ -62,4 +140,6 @@ use strict;
use warnings;
use utf8;
$flag = "default" unless (defined($flag) && length($flag));
MyApp->new()->MainLoop();
#!/usr/bin/env perl
#=============================================================================
# FILE: sizers.pl
# USAGE: ./sizers.pl
# OPTIONS:
# BRIEF:
# AUTHOR: Ji-Hyeon Gim <potatogim@potatogim.net>
# ORGANIZATION:
# DATE: 2015년 08월 23일 11시 47분 18초
# VERSION: 1.0
# LICENSE: Artistic License 2.0
# NOTE:
#=============================================================================
package MyApp;
use strict;
use warnings;
use utf8;
use base qw/Wx::App/;
use Wx qw/:everything/;
sub OnInit
{
my $self = shift;
my ($frame, $sizer);
$frame = Wx::Frame->new(
undef, -1, "A Frame", wxDefaultPosition, wxSIZE(300, 200)
);
$sizer = $self->init_sizer($frame);
$frame->SetAutoLayout(1);
$frame->SetSizer($sizer);
$self->SetTopWindow($frame);
$frame->Show(1);
}
sub init_sizer
{
my ($self, $frame) = @_;
my ($sizer, $button);
return $sizer;
}
1;
package main;
use strict;
use warnings;
use utf8;
MyApp->new()->MainLoop();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment