| 1 |
/* Stack |
| 2 |
* |
| 3 |
* Gtk::Stack is a container that shows a single child at a time, |
| 4 |
* with nice transitions when the visible child changes. |
| 5 |
* |
| 6 |
* Gtk::StackSwitcher adds buttons to control which child is visible. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <gtkmm.h> |
| 10 |
|
| 11 |
class Example_Stack : public Gtk::Window |
| 12 |
{ |
| 13 |
public: |
| 14 |
Example_Stack(); |
| 15 |
~Example_Stack() override; |
| 16 |
|
| 17 |
protected: |
| 18 |
|
| 19 |
// Containers |
| 20 |
Gtk::Grid m_grid; |
| 21 |
Gtk::Stack m_stack; |
| 22 |
|
| 23 |
// Widgets |
| 24 |
Gtk::StackSwitcher m_stack_switcher; |
| 25 |
Gtk::Image m_image; |
| 26 |
Gtk::CheckButton m_check_button; |
| 27 |
Gtk::Spinner m_spinner; |
| 28 |
|
| 29 |
private: |
| 30 |
}; |
| 31 |
|
| 32 |
//Called by DemoWindow; |
| 33 |
Gtk::Window* do_stack() |
| 34 |
{ |
| 35 |
return new Example_Stack(); |
| 36 |
} |
| 37 |
|
| 38 |
Example_Stack::Example_Stack() |
| 39 |
{ |
| 40 |
// Window properties |
| 41 |
set_title("Stack"); |
| 42 |
|
| 43 |
// Build stack |
| 44 |
m_stack.add(m_image, "page1", "Page 1"); |
| 45 |
m_stack.add(m_check_button, "page2", "Page 2"); |
| 46 |
m_stack.add(m_spinner, "page3"); |
| 47 |
|
| 48 |
// Page 1 |
| 49 |
m_image.set_from_icon_name("gtk3-demo", Gtk::ICON_SIZE_DIALOG); |
| 50 |
|
| 51 |
// Page 2 |
| 52 |
m_check_button.set_label("Page 2"); |
| 53 |
m_check_button.set_halign(Gtk::ALIGN_CENTER); |
| 54 |
|
| 55 |
// Page 3 |
| 56 |
m_stack.child_property_icon_name(m_spinner) = "face-laugh-symbolic"; |
| 57 |
m_spinner.property_active() = true; |
| 58 |
|
| 59 |
// Stack transition |
| 60 |
m_stack.set_transition_type(Gtk::STACK_TRANSITION_TYPE_CROSSFADE); |
| 61 |
|
| 62 |
// Layout |
| 63 |
m_stack_switcher.set_stack(m_stack); |
| 64 |
m_grid.attach(m_stack_switcher, 0, 0, 1, 1); |
| 65 |
m_grid.attach(m_stack, 0, 1, 1, 1); |
| 66 |
add(m_grid); |
| 67 |
|
| 68 |
show_all_children(); |
| 69 |
} |
| 70 |
|
| 71 |
Example_Stack::~Example_Stack() |
| 72 |
{ |
| 73 |
} |