Commits

Herbert Breunung  committed b9d4048

next example for first lesson

  • Participants
  • Parent commits cce65a2

Comments (0)

Files changed (4)

File example/2a_minimal_subset/golden_button.pl

-use strict;
-use warnings;
-
-package App;
-use parent qw(Wx::App);
-use Wx;
-
-sub OnInit {
-	my $app   = shift;
-	my $frame = Wx::Frame->new( undef, -1, 'Golden Proportion');
-
-	my $button = Wx::Button->new($frame, -1,  'make it golden');
-	Wx::Event::EVT_BUTTON( $button, $button, sub {
-		my $size = $button->GetSize;
-		$size->SetWidth( $size->GetHeight * 1.618 ) ;
-		$button->SetSize( $size );
-		$frame->Fit;
-	} );
-
-	$frame->Center();
-	$frame->Show(1);
-	$app->SetTopWindow($frame);
-	1;
-}
-
-package main;
-App->new->MainLoop;

File example/2a_minimal_subset/ratio_button.pl

 use parent qw(Wx::App);
 use Wx;
 
-my %ratio = (Golden => 1.618, Din => 1.41421, '2:3' => 1.5,  Square => 1);
+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 $button = Wx::Choice->new($frame, -1, [-1,-1], [-1,-1], [keys %ratio]);
-	Wx::Event::EVT_CHOICE( $button, $button, sub {
-		my $size = $frame->GetSize;
-		$size->SetWidth( $size->GetHeight * $ratio{ $_[1]->GetString } ) ;
-		$frame->SetSize( $size );
-	} );
+	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);

File example/2a_minimal_subset/ratio_selector.pl

-use v5.12;
-use warnings;
-
-package App;
-use parent qw(Wx::App);
-use Wx;
-
-my %ratio = (Golden => 1.618, Din => 1.41421, '2:3' => 1.5,  Square => 1);
-
-sub OnInit {
-	my $app   = shift;
-	my $frame = Wx::Frame->new( undef, -1, 'Golden Proportion');
-
-	my $button = Wx::Choice->new($frame, -1, [-1,-1], [-1,-1], [keys %ratio]);
-	Wx::Event::EVT_CHOICE( $button, $button, sub {
-		my $size = $frame->GetSize;
-		$size->SetWidth( $size->GetHeight * $ratio{ $_[1]->GetString } ) ;
-		$frame->SetSize( $size );
-	} );
-
-	$frame->Center();
-	$frame->Show(1);
-	$app->SetTopWindow($frame);
-	1;
-}
-
-package main;
-App->new->MainLoop;

File example/3a_top_level_window/golden_button.pl

+use strict;
+use warnings;
+
+package App;
+use parent qw(Wx::App);
+use Wx;
+
+sub OnInit {
+	my $app   = shift;
+	my $frame = Wx::Frame->new( undef, -1, 'Golden Proportion');
+
+	my $button = Wx::Button->new($frame, -1,  'make it golden');
+	Wx::Event::EVT_BUTTON( $button, $button, sub {
+		my $size = $button->GetSize;
+		$size->SetWidth( $size->GetHeight * 1.618 ) ;
+		$button->SetSize( $size );
+		$frame->Fit;
+	} );
+
+	$frame->Center();
+	$frame->Show(1);
+	$app->SetTopWindow($frame);
+	1;
+}
+
+package main;
+App->new->MainLoop;