[gtkmm] Add Gtk::HeaderBar demo



commit 6c54dc6a3621f2f3ef9d3d8123335e78ce74a8ed
Author: Juan R. GarcĂ­a Blanco <juanrgar gmail com>
Date:   Sat Apr 12 16:11:11 2014 +0200

    Add Gtk::HeaderBar demo
    
    Add a Gtk::HeaderBar demo that mimics gtk3-demo's one.

 demos/Makefile.am                   |    1 +
 demos/gtk-demo/demos.h              |    2 +
 demos/gtk-demo/example_headerbar.cc |   96 +++++++++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+), 0 deletions(-)
---
diff --git a/demos/Makefile.am b/demos/Makefile.am
index a9c5f97..3afb3c3 100644
--- a/demos/Makefile.am
+++ b/demos/Makefile.am
@@ -34,6 +34,7 @@ gtk_demo_gtkmm_demo_SOURCES =                         \
        gtk-demo/example_dialog.cc                      \
        gtk-demo/example_drawingarea.cc                 \
        gtk-demo/example_flowbox.cc                     \
+       gtk-demo/example_headerbar.cc                   \
        gtk-demo/example_icontheme.cc                   \
        gtk-demo/example_iconview.cc                    \
        gtk-demo/example_images.cc                      \
diff --git a/demos/gtk-demo/demos.h b/demos/gtk-demo/demos.h
index 66edc88..52e0ae3 100644
--- a/demos/gtk-demo/demos.h
+++ b/demos/gtk-demo/demos.h
@@ -24,6 +24,7 @@ Gtk::Window* do_colorsel();
 Gtk::Window* do_dialog();
 Gtk::Window* do_drawingarea();
 Gtk::Window* do_flowbox();
+Gtk::Window* do_headerbar();
 Gtk::Window* do_icontheme();
 Gtk::Window* do_iconview();
 Gtk::Window* do_images();
@@ -57,6 +58,7 @@ Demo testgtk_demos[] =
   { "Dialog and Message Boxes", "example_dialog.cc", sigc::ptr_fun(&do_dialog), 0 },
   { "Drawing Area", "example_drawingarea.cc", sigc::ptr_fun(&do_drawingarea), 0 },
   { "Flow Box", "example_flowbox.cc",  sigc::ptr_fun(&do_flowbox), 0 },
+  { "Header Bar", "example_headerbar.cc",  sigc::ptr_fun(&do_headerbar), 0 },
   { "Icon Theme", "example_icontheme.cc", sigc::ptr_fun(&do_icontheme), 0 },  
   { "Icon View", "example_iconview.cc", sigc::ptr_fun(&do_iconview), 0 },  
   { "Images", "example_images.cc", sigc::ptr_fun(&do_images), 0 },
diff --git a/demos/gtk-demo/example_headerbar.cc b/demos/gtk-demo/example_headerbar.cc
new file mode 100644
index 0000000..8585e91
--- /dev/null
+++ b/demos/gtk-demo/example_headerbar.cc
@@ -0,0 +1,96 @@
+/* Header Bar
+ *
+ * Gtk::HeaderBar is a container that is suitable for implementing
+ * window titlebars. One of its features is that it can position
+ * a title (and optional subtitle) centered with regard to the
+ * full width, regardless of variable-width content at the left
+ * or right.
+ *
+ * It is commonly used with Gtk::Window::set_titlebar()
+ */
+
+#include "gtkmm.h"
+
+class Example_HeaderBar : public Gtk::Window
+{
+public:
+  Example_HeaderBar();
+  virtual ~Example_HeaderBar();
+
+protected:
+
+  // Widgets
+  Gtk::Image m_send_receive_image;
+  Gtk::Button m_send_receive_button;
+  Gtk::Arrow m_left_arrow;
+  Gtk::Arrow m_right_arrow;
+  Gtk::Button m_left_arrow_button;
+  Gtk::Button m_right_arrow_button;
+  Gtk::TextView m_text_view;
+
+  // Containers
+  Gtk::HeaderBar m_header_bar;
+  Gtk::Box m_arrow_buttons_box;
+
+private:
+  void configure_send_receive_button();
+  void configure_arrow_buttons();
+};
+
+//Called by DemoWindow;
+Gtk::Window* do_headerbar()
+{
+  return new Example_HeaderBar();
+}
+
+Example_HeaderBar::Example_HeaderBar()
+: m_left_arrow(Gtk::ARROW_LEFT, Gtk::SHADOW_NONE),
+  m_right_arrow(Gtk::ARROW_RIGHT, Gtk::SHADOW_NONE),
+  m_arrow_buttons_box(Gtk::ORIENTATION_HORIZONTAL)
+{
+  // Window properties
+  // Window title is set by header bar
+  set_default_size(600, 400);
+
+  // Configuration
+  m_header_bar.set_show_close_button();
+  m_header_bar.set_title("Welcome to Facebook - Log in, sign up or learn more");
+  m_header_bar.set_has_subtitle(false);
+
+  // Header Bar buttons
+  configure_send_receive_button();
+  configure_arrow_buttons();
+
+  // Header Bar layout
+  m_header_bar.pack_start(m_arrow_buttons_box);
+  m_header_bar.pack_end(m_send_receive_button);
+
+  // Layout
+  set_titlebar(m_header_bar);
+  add(m_text_view);
+
+  show_all_children();
+}
+
+Example_HeaderBar::~Example_HeaderBar()
+{
+}
+
+void Example_HeaderBar::configure_send_receive_button()
+{
+  Glib::RefPtr<Gio::ThemedIcon> icon = Gio::ThemedIcon::create("mail-send-receive-symbolic", false);
+
+  m_send_receive_image.set(icon, Gtk::ICON_SIZE_BUTTON);
+  m_send_receive_button.add(m_send_receive_image);
+}
+
+void Example_HeaderBar::configure_arrow_buttons()
+{
+  m_arrow_buttons_box.get_style_context()->add_class("linked");
+
+  m_left_arrow_button.add(m_left_arrow);
+  m_right_arrow_button.add(m_right_arrow);
+
+  m_arrow_buttons_box.add(m_left_arrow_button);
+  m_arrow_buttons_box.add(m_right_arrow_button);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]