13. Frames

The frame widget provides a place for other widget to sit. In other words, it's a container. The next example has two frames. The left frame has a combobox. Selecting a value results in a colored right frame.

mainwindow


use Prima qw(Buttons Label ComboBox FrameSet Application);

%mcColors = (
'black' => 0x000000,
'white' => 0xFFFFFF,
'silver' => 0xC0C0C0,
'grey' => 0x808080,
'maroon' => 0x800000,
'red' => 0xFF0000,
'purple' => 0x800080,
'fuchsia' => 0xFF00FF,
'green' => 0x008000,
'lime' => 0x00FF00,
'olive' => 0x808000,
'yellow' => 0xFFFF00,
'navy' => 0x000080,
'blue' => 0x0000FF,
'teal' => 0x008080,
'aqua' => 0x00FFFF,
);


$mw = Prima::MainWindow-> create(
    text   => "Frames example",
    size => [ 600, 300],
    icon => Prima::Icon-> load('icon.png'),		
    skin => 'flat',
);


$frame = $mw-> insert(

	FrameSet =>
             # arrangement => fra::Vertical,# Horizontal is the default
             size => [$mw-> size],
             origin => [0, 0],
             frameSizes => [qw(50% 50%)],
             flexible => 0,
             separatorWidth => 1,
);

$frame-> insert_to_frame(
      0,
      Label => 
          pack => { fill => 'none', side => 'top', pad => 15 },	
          text   => "Color picker",
          alignment => ta::Center,          
          font   => { size => 14, },
);


$frame-> insert_to_frame(
      0,# id
      ComboBox =>
              pack => { fill => 'none', side => 'top', pad => 15 },
              size => [200, 30],
              name => 'Select your color:',
              items => [ 'black', 'white', 'silver', 'grey', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua' ],
              style => (cs::DropDown),
              onSelectItem => sub { 
				  
				  mcSetColorFrame($_[0]-> items-> [$_[0]->focusedItem]);
				  # alternative: mcSetColorFrame($_[0]-> get_items($_[0]->focusedItem));

			  },	  
);

sub mcSetColorFrame {

 $frame-> frame(1)-> backColor( $mcColors{$_[0]} );# frame(1) refers to the right frame with id = 1

} 


$frame-> insert_to_frame(
		1,# id
   
);	


run Prima;