[gtkmm-documentation] ScaleButton Example: Actually show the scale.



commit 84b8e3cf3a5a1130da4b81a9c270785ff7c80769
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Feb 2 13:11:17 2015 +0100

    ScaleButton Example: Actually show the scale.
    
    The window must be (arbitrarily) big enough to show it.
    Otherwise we just see a little indicator arrow and the rest is
    truncated.

 examples/book/buttons/scalebutton/examplewindow.cc |   32 ++++++++++++++++---
 examples/book/buttons/scalebutton/examplewindow.h  |    7 +++-
 2 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/examples/book/buttons/scalebutton/examplewindow.cc 
b/examples/book/buttons/scalebutton/examplewindow.cc
index bfc0ee9..7bc6516 100644
--- a/examples/book/buttons/scalebutton/examplewindow.cc
+++ b/examples/book/buttons/scalebutton/examplewindow.cc
@@ -20,14 +20,34 @@
 #include <iostream>
 
 ExampleWindow::ExampleWindow()
-: m_button(Gtk::ICON_SIZE_BUTTON, 0, 100, 10)
+: m_button(Gtk::ICON_SIZE_BUTTON, 0.0, 100.0, 10.0)
 {
-  m_button.set_label("Some Value");
+  //Make the window big enough to show the popup scale from the GtkVolumeButton.
+  //Otherwise it will be truncated.
+  set_default_size(300, 300);
 
   set_title("ScaleButton Example");
   set_border_width(12);
 
-  add(m_button);
+  std::vector<Glib::ustring> icons;
+  icons.push_back("audio-volume-high");
+  icons.push_back("audio-volume-low");
+  icons.push_back("audio-volume-medium");
+  m_button.set_icons(icons);
+
+  m_button.set_label("Some Value");
+
+  add(m_grid);
+  m_grid.set_vexpand(true);
+  m_grid.set_hexpand(true);
+
+  m_grid.attach(m_button, 1, 1, 1, 1);
+  m_button.set_valign(Gtk::ALIGN_END);
+  m_button.set_halign(Gtk::ALIGN_END);
+
+  m_button.set_value(30.0);
+  m_button.signal_value_changed().connect(
+    sigc::mem_fun(*this, &ExampleWindow::on_value_changed));
 
   show_all_children();
 }
@@ -36,7 +56,9 @@ ExampleWindow::~ExampleWindow()
 {
 }
 
-void ExampleWindow::on_button_clicked()
+void ExampleWindow::on_value_changed(double value)
 {
-  std::cout << "The Button was clicked." << std::endl;
+  std::cout << "Value: " << value << std::endl;
 }
+
+
diff --git a/examples/book/buttons/scalebutton/examplewindow.h 
b/examples/book/buttons/scalebutton/examplewindow.h
index 20faf77..3486aa1 100644
--- a/examples/book/buttons/scalebutton/examplewindow.h
+++ b/examples/book/buttons/scalebutton/examplewindow.h
@@ -20,6 +20,7 @@
 #define GTKMM_EXAMPLE_BUTTONS_H
 
 #include <gtkmm/window.h>
+#include <gtkmm/grid.h>
 #include <gtkmm/scalebutton.h>
 
 class ExampleWindow : public Gtk::Window
@@ -29,10 +30,12 @@ public:
   virtual ~ExampleWindow();
 
 protected:
-  //Signal handlers:
-  void on_button_clicked();
+
+  void on_value_changed(double value);
 
   //Child widgets:
+  Gtk::Grid m_grid;
+
   Gtk::ScaleButton m_button;
 };
 


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