File Coverage

blib/lib/Wx/DemoModules/wxBoxSizer.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             #############################################################################
2             ## Name: lib/Wx/DemoModules/wxBoxSizer.pm
3             ## Purpose: wxPerl demo helper for Wx::BoxSizer and Wx::StaticBoxSizer
4             ## Author: Mattia Barbon
5             ## Modified by:
6             ## Created: 03/07/2002
7             ## RCS-ID: $Id: wxBoxSizer.pm 2189 2007-08-21 18:15:31Z mbarbon $
8             ## Copyright: (c) 2002, 2006 Mattia Barbon
9             ## Licence: This program is free software; you can redistribute it and/or
10             ## modify it under the same terms as Perl itself
11             #############################################################################
12              
13             package Wx::DemoModules::wxBoxSizer;
14              
15 1     1   1311 use strict;
  1         2  
  1         36  
16 1     1   5 use base qw(Wx::Frame);
  1         1  
  1         701  
17             use Wx qw(:sizer wxDefaultPosition wxDefaultSize
18             wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER);
19              
20             sub new {
21             my( $class, $parent ) = @_;
22             my $self = $class->SUPER::new( undef, -1, "Wx::BoxSizer",
23             wxDefaultPosition, wxDefaultSize,
24             wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
25              
26             # top level sizer
27             my $tsz = Wx::BoxSizer->new( wxVERTICAL );
28              
29             my $fr = Wx::BoxSizer->new( wxHORIZONTAL );
30             # this button is fixed size, with some border
31             $fr->Add( Wx::Button->new( $self, -1, 'Button 1' ),
32             0, wxALL, 10 );
33             # this button has no border
34             $fr->Add( Wx::Button->new( $self, -1, 'Button 2' ), 0, 0 );
35             # this one has borders just on the top and bottom
36             $fr->Add( Wx::Button->new( $self, -1, 'Button 3' ), 0, wxTOP|wxBOTTOM, 5 );
37              
38             # first row can grow vertically, and horizontally
39             $tsz->Add( $fr, 1, wxGROW );
40             # second row is just some space
41             $tsz->Add( 10, 10, 0, wxGROW );
42              
43             my $sr = Wx::BoxSizer->new( wxHORIZONTAL );
44             # these elements compete for the available horizontal space
45             $sr->Add( Wx::Button->new( $self, -1, 'Button 1' ), 1, wxALL, 5 );
46             $sr->Add( Wx::Button->new( $self, -1, 'Button 2' ), 1, wxGROW|wxALL, 5 );
47             # sizers can be arbitrarily nested
48             my $nsz = Wx::StaticBoxSizer->new( Wx::StaticBox->new
49             ( $self, -1, 'Wx::StaticBoxSizer' ),
50             wxVERTICAL );
51             $nsz->Add( Wx::Button->new( $self, -1, 'Button 3' ), 1, wxGROW|wxALL, 5 );
52             $nsz->Add( Wx::Button->new( $self, -1, 'Button 4' ), 1, wxGROW|wxALL, 5 );
53             $sr->Add( $nsz, 2, wxGROW );
54              
55             # add third row
56             $tsz->Add( $sr, 1, wxGROW );
57              
58             # tell we want automatic layout
59             $self->SetAutoLayout( 1 );
60             $self->SetSizer( $tsz );
61             # size the window optimally and set its minimal size
62             $tsz->Fit( $self );
63             $tsz->SetSizeHints( $self );
64              
65             return $self;
66             }
67              
68             sub add_to_tags { qw(sizers) }
69             sub title { 'wxBoxSizer' }
70              
71             1;