Source

WxPerlBook / example / 2a_minimal_subset / ratio_button.pl

Full commit
use v5.12;
use warnings;

package App;
use parent qw(Wx::App);
use Wx;

my %ratio = (Golden => 1.618, '2:3' => 1.5, '3:4' => 1.3333, Din => 1.41421, Square => 1);

sub OnInit {
	my $app   = shift;
	my $frame = Wx::Frame->new( undef, -1, 'Golden Proportion');
	my $sizer = Wx::BoxSizer->new( 1 );

	my $tb = Wx::Button->new($frame, -1, '');
	my $width = $tb->GetSize->GetWidth;
	my $max_height = 0;
	$tb->Destroy;

	for my $label (keys %ratio) {
		my $height = $width / $ratio{ $label };
		$sizer->Add( Wx::Button->new($frame, -1, $label, [-1, -1], [$width, $height]) );
		$max_height = $height if $height > $max_height;
	}

	$frame->SetSizer( $sizer );
	$frame->SetSize( [$width * keys %ratio, $max_height] );
	$frame->Center();
	$frame->Show(1);
	$app->SetTopWindow($frame);
	1;
}

package main;
App->new->MainLoop;