PannableArea

Hildon::PannableArea is a container widget than can be panned around using fingers. The widget has no scrollbars, but small "indicators" that appear when a dragging motion is started on the pannable area. The motion is "kinetic", meaning it can be flicked to a position and also stopped by tapping on the pannable area.

Hildon::PannableArea can be used in the same way as Gtk::ScrolledWindow, except that it has extra features specific to the Hildon platform. It is derived from Gtk::Bin, so it only accepts a single widget.

PannableArea Reference

Example

This example shows a simple window with ten Hildon::Button widgets inside a Hildon::PannableArea.

Figure 5.22. PannableArea

PannableArea

Source Code

File: examplewindow.h

#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H

#include <hildonmm/window.h>
#include <hildonmm/pannable-area.h>
#include <hildonmm/button.h>
#include <gtkmm/buttonbox.h>
#include <gtkmm/viewport.h>

class ExampleWindow : public Hildon::Window
{
  public:
    ExampleWindow();
    virtual ~ExampleWindow();

  private:
    //Signal handlers:
    void on_button_clicked();

    //Child widgets:
    Gtk::HButtonBox box_;
    Hildon::Button button1_;
    Hildon::Button button2_;
    Hildon::Button button3_;
    Hildon::Button button4_;
    Hildon::Button button5_;
    Hildon::Button button6_;
    Hildon::Button button7_;
    Hildon::Button button8_;
    Hildon::Button button9_;
    Hildon::Button button10_;
    Hildon::PannableArea area_;
};

#endif /* _MAEMOMM_EXAMPLEWINDOW_H */

File: main.cc

#include <hildonmm.h>
#include "examplewindow.h"

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);
  Hildon::init();

  ExampleWindow window;
  kit.run(window); //Shows the window and returns when it is closed.

  return 0;
}

File: examplewindow.cc

#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow() :
  button1_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "1"),
  button2_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "2"),
  button3_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "3"),
  button4_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "4"),
  button5_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "5"),
  button6_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "6"),
  button7_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "7"),
  button8_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "8"),
  button9_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "9"),
  button10_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click me!",
    "10"),
  // TODO: Fix this in hildonmm.
  area_(static_cast<Hildon::MovementMode>(Hildon::PANNABLE_AREA_MODE_AUTO), true, 20, 500, 0.93, 20)
{
  set_title("Hildon::PannableArea example");

  box_.add(button1_);
  box_.add(button2_);
  box_.add(button3_);
  box_.add(button4_);
  box_.add(button5_);
  box_.add(button6_);
  box_.add(button7_);
  box_.add(button8_);
  box_.add(button9_);
  box_.add(button10_);

  area_.add(box_);
  add(area_);

  button1_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button2_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button3_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button4_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button5_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button6_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button7_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button8_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button9_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
  button10_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));

  show_all();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_clicked()
{
  std::cout << "Button clicked!" << std::endl;
}