Button Boxes are a convenient way to quickly layout a group of buttons. They come in both horizontal and vertical flavors. You create a new Button Box with one of the following calls, which create a horizontal or vertical box, respectively:
Gtk::HButtonBox.new Gtk::VButtonBox.new
Buttons are added to a Button Box using the usual method:
Gtk::ButtonBox#add( child_widget )
Here's an example that illustrates all the different layout settings for Button Boxes.
require 'gtk2' def create_bbox( horizontal, title, spacing, child_w, child_h, layout ) frame = Gtk::Frame.new( title ) if horizontal bbox = Gtk::HButtonBox.new else bbox = Gtk::VButtonBox.new end bbox.border_width=( 5 ) frame.add( bbox ) # Set the appearance os the Button Box bbox.layout_style=( layout ) bbox.spacing=( spacing ) button = Gtk::Button.new( Gtk::Stock::OK ) bbox.add( button ) button = Gtk::Button.new( Gtk::Stock::CANCEL ) bbox.add( button ) button = Gtk::Button.new( Gtk::Stock::HELP ) bbox.add( button ) return frame end Gtk.init window = Gtk::Window.new( Gtk::Window::TOPLEVEL ) window.title=( "Button Boxes" ) window.signal_connect( "destroy" ) { Gtk.main_quit } window.border_width=( 10 ) main_vbox = Gtk::VBox.new( false, 0 ) window.add( main_vbox ) frame_horz = Gtk::Frame.new( "Horizontal Button Boxes" ) main_vbox.pack_start( frame_horz, true, true, 10 ) vbox = Gtk::VBox.new( false, 0 ) vbox.border_width=( 10 ) frame_horz.add( vbox ) vbox.pack_start( create_bbox( true, "Spread (spacing 40)", 40, 85, 20, Gtk::ButtonBox::SPREAD ), true, true, 0 ) vbox.pack_start( create_bbox( true, "Edge (spacing 30)", 30, 85, 20, Gtk::ButtonBox::EDGE ), true, true, 5 ) vbox.pack_start( create_bbox( true, "Start (spacing 20)", 20, 85, 20, Gtk::ButtonBox::START ), true, true, 5 ) vbox.pack_start( create_bbox( true, "End (spacing 10)", 10, 85, 20, Gtk::ButtonBox::END ), true, true, 5 ) frame_vert = Gtk::Frame.new( "Vertical Button Boxes" ) main_vbox.pack_start( frame_vert, true, true, 10 ) hbox = Gtk::HBox.new( false, 0 ) hbox.border_width=( 10 ) frame_vert.add( hbox ) hbox.pack_start( create_bbox( false, "Spread (spacing 5)", 5, 85, 20, Gtk::ButtonBox::SPREAD ), true, true, 0 ) hbox.pack_start( create_bbox( false, "Edge (spacing 30)", 30, 85, 20, Gtk::ButtonBox::EDGE ), true, true, 5 ) hbox.pack_start( create_bbox( false, "Start (spacing 20)", 20, 85, 20, Gtk::ButtonBox::START ), true, true, 5 ) hbox.pack_start( create_bbox( false, "End (spacing 20)", 20, 85, 20, Gtk::ButtonBox::END ), true, true, 5 ) window.show_all Gtk.main
Prev | Next |