### Tutorial
« Scrolled Windows | Toolbar »

## Button Boxes

Button Boxes are a convenient way to quickly layout a group of buttons. They come in both horizontal and vertical flavours. You create a new Button Box with one of the following constructors, which create a horizontal or vertical box, respectively:

`HButtonBox(Gtk::ButtonBoxStyle layout = Gtk::BUTTONBOX_DEFAULT_STYLE, int spacing = default_spacing``); VButtonBox(Gtk::ButtonBoxStyle layout = Gtk::BUTTONBOX_DEFAULT_STYLE, int spacing = default_spacing``);`

The layout argument sets the method used to spread the buttons in a button box. It can be one of the values from the Gtk::ButtonBoxStyle enumeration:

- BUTTONBOX_DEFAULT_STYLE - default packing.
- BUTTONBOX_SPREAD - buttons are evenly spread across the ButtonBox.
- BUTTONBOX_EDGE - buttons are placed at the edges of the ButtonBox.
- BUTTONBOX_START - buttons are grouped towards the start of box, (on the left for a HBox, or the top for a VBox).
- BUTTONBOX_END - buttons are grouped towards the end of a box, (on the right for a HBox, or the bottom for a VBox).

The spacing argument specifies the number of pixels to put between the buttons in the button box. The default_spacing is defined as -1 and implies zero pixels. The spacing can be retrieved or altered using the inherited Gtk::Box::set_spacing() and Gtk::Box::get_spacing() methods.
The Button Box layout can be altered or retrieved using the following methods, respectively.

`voidset_layout(Gtk::ButtonBoxStyle layout_style); Gtk::ButtonBoxStyle get_layout() const;`

Buttons are added to a Button Box using the usual method, Gtk::Container::add():

buttonbox->add(*button);

Here's an example that illustrates all the different layout settings for Button Boxes.
The header file for Button Boxes is buttonbox.h:

`#include<inti/main.h> #include <inti/core.h> #include <inti/gtk/buttonbox.h> #include <inti/gtk/frame.h> #include <inti/gtk/button.h> using namespace Inti; class ButtonBoxFrame : public Gtk::Frame { public: ButtonBoxFrame(bool horizontal, const char *title, int spacing, Gtk::ButtonBoxStyle layout); virtual ~ButtonBoxFrame(); }; class ButtonBoxWindow : public Gtk::Window { public: ButtonBoxWindow(); virtual ~ButtonBoxWindow(); };`

and the source file is buttonbox.cc:

`#include"buttonbox.h" // ButtonBoxFrame ButtonBoxFrame::ButtonBoxFrame(bool horizontal, const char *title, int spacing, Gtk::ButtonBoxStyle layout) { set_label(title); Gtk::ButtonBox *bbox; if (horizontal) bbox = new Gtk::HButtonBox; else bbox = new Gtk::VButtonBox; bbox->set_border_width(5); add(*bbox); bbox->set_layout(layout); bbox->set_spacing(spacing); Gtk::Button *button = new Gtk::StockButton(GTK_STOCK_OK); bbox->add(*button); button = new Gtk::StockButton(GTK_STOCK_CANCEL); bbox->add(*button); button = new Gtk::StockButton(GTK_STOCK_HELP); bbox->add(*button); } ButtonBoxFrame::~ButtonBoxFrame() { } // ButtonBoxWindow ButtonBoxWindow::ButtonBoxWindow() { set_title("Button Boxes"); set_border_width(10); Gtk::VBox *main_vbox = new Gtk::VBox; add(*main_vbox); // Horizontal Button Boxes Gtk::Frame *frame = new Gtk::Frame("Horizontal Button Boxes"); main_vbox->pack_start(*frame, true, true, 10); Gtk::Box *box = new Gtk::VBox; box->set_border_width(10); frame->add(*box); ButtonBoxFrame *button_box_frame = new ButtonBoxFrame(true, "Spread (spacing 40)", 40, Gtk::BUTTONBOX_SPREAD); box->pack_start(*button_box_frame); button_box_frame = new ButtonBoxFrame(true, "Edge (spacing 30)", 30, Gtk::BUTTONBOX_EDGE); box->pack_start(*button_box_frame, true, true, 5); button_box_frame = new ButtonBoxFrame(true, "Start (spacing 20)", 20, Gtk::BUTTONBOX_START); box->pack_start(*button_box_frame, true, true, 5); button_box_frame = new ButtonBoxFrame(true, "End (spacing 10)", 10, Gtk::BUTTONBOX_END); box->pack_start(*button_box_frame, true, true, 5); // Vertical Button Boxes frame = new Gtk::Frame("Vertical Button Boxes"); main_vbox->pack_start(*frame, true, true, 10); box = new Gtk::HBox; box->set_border_width(10); frame->add(*box); button_box_frame = new ButtonBoxFrame(false, "Spread (spacing 5)", 5, Gtk::BUTTONBOX_SPREAD); box->pack_start(*button_box_frame); button_box_frame = new ButtonBoxFrame(false, "Edge (spacing 30)", 30, Gtk::BUTTONBOX_EDGE); box->pack_start(*button_box_frame, true, true, 5); button_box_frame = new ButtonBoxFrame(false, "Start (spacing 20)", 20, Gtk::BUTTONBOX_START); box->pack_start(*button_box_frame, true, true, 5); button_box_frame = new ButtonBoxFrame(false, "End (spacing 20)", 20, Gtk::BUTTONBOX_END); box->pack_start(*button_box_frame, true, true, 5); show_all(); } ButtonBoxWindow::~ButtonBoxWindow() { } int main (int argc, char *argv[]) { using namespace Main; init(&argc, &argv); ButtonBoxWindow window; window.sig_destroy().connect(slot(&Inti::Main::quit)); run(); return 0; }`

« Scrolled Windows | Index Container Widgets Top | Toolbar »