Debian Codegraph @

demos/gtk-demo/example_stacksidebar.cc

raw
1 /* Stack Sidebar
2 *
3 * Gtk::StackSidebar provides an automatic sidebar widget to control
4 * navigation of a Gtk::Stack object. This widget automatically updates its
5 * contents based on what is presently available in the Gtk::Stack object,
6 * and using the "title" child property to set the display labels.
7 */
8
9 #include <gtkmm.h>
10 #include <vector>
11
12 class Example_StackSidebar : public Gtk::Window
13 {
14 public:
15 Example_StackSidebar();
16 ~Example_StackSidebar() override;
17
18 protected:
19 // Container:
20 Gtk::Box m_Box;
21
22 // Widgets:
23 Gtk::HeaderBar m_HeaderBar;
24 Gtk::StackSidebar m_StackSidebar;
25 Gtk::Separator m_Separator;
26 Gtk::Stack m_Stack;
27
28 private:
29 void fill_page_names();
30 std::vector<Glib::ustring> m_page_names;
31 };
32
33 Gtk::Window* do_stacksidebar()
34 {
35 return new Example_StackSidebar();
36 }
37
38 Example_StackSidebar::Example_StackSidebar()
39 :
40 m_Box(Gtk::ORIENTATION_HORIZONTAL),
41 m_HeaderBar(),
42 m_StackSidebar(),
43 m_Separator(Gtk::ORIENTATION_VERTICAL),
44 m_Stack()
45 {
46 m_HeaderBar.set_show_close_button(true);
47 set_titlebar(m_HeaderBar);
48 set_title("Stack Sidebar demo");
49 set_default_size(500, 350);
50
51 add(m_Box);
52
53 m_Box.pack_start(m_StackSidebar, Gtk::PACK_SHRINK);
54 m_Box.pack_start(m_Separator, Gtk::PACK_SHRINK);
55 m_Box.pack_start(m_Stack, Gtk::PACK_EXPAND_WIDGET);
56
57 m_Stack.set_transition_type(Gtk::STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
58 m_StackSidebar.set_stack(m_Stack);
59
60 // Stack pages
61 fill_page_names();
62 for (std::size_t i = 0; i != m_page_names.size(); ++i)
63 {
64 Gtk::Widget* widget = nullptr;
65 if (i == 0)
66 {
67 Gtk::Image* image = Gtk::make_managed<Gtk::Image>();
68 image->set_from_icon_name("help-about", Gtk::ICON_SIZE_MENU);
69 image->set_pixel_size(256);
70 widget = image;
71 }
72 else
73 {
74 widget = Gtk::make_managed<Gtk::Label>(m_page_names[i]);
75 }
76 m_Stack.add(*widget, m_page_names[i], m_page_names[i]);
77 }
78
79 show_all();
80 }
81
82 Example_StackSidebar::~Example_StackSidebar()
83 {
84 }
85
86 void Example_StackSidebar::fill_page_names()
87 {
88 m_page_names.push_back("Welcome to gtkmm");
89 m_page_names.push_back("Gtk::StackSidebar Widget");
90 m_page_names.push_back("Automatic navigation");
91 m_page_names.push_back("Consistent appearance");
92 m_page_names.push_back("Scrolling");
93 m_page_names.push_back("Page 6");
94 m_page_names.push_back("Page 7");
95 m_page_names.push_back("Page 8");
96 m_page_names.push_back("Page 9");
97 }