11.8. Viewports

It is unlikely that you will ever need to use the Viewport widget directly. You are much more likely to use the Scrolled Window widget which itself uses the Viewport.

A viewport widget allows you to place a larger widget within it such that you can view a part of it at a time. It uses Adjustments to define the area that is currently in view.

A Viewport is created with the method

Gtk::Viewport.new( hadjustment, vadjustment )

As you can see you can specify the horizontal and vertical Adjustments that the widget is to use when you create the widget. It will create its own if you pass nil as the value of the arguments.

You can get and set the adjustments after the widget has been created using the following four methods:

Gtk::Viewport#hadjustment
Gtk::Viewport#vadjustment

# Syntax Sugar again
Gtk::Viewport#set_hadjustment( adjustment )
Gtk::Viewport#hadjustment=( adjustment )

# Syntax Sugar yet again
Gtk::Viewport#set_vadjustment( adjustment )
Gtk::Viewport#vadjustment=( adjustment )

The only other viewport methods are used to alter its appearance:

Gtk::Viewport#set_shadow_type( type )
Gtk::Viewport#shadow_type=( type )

Possible values for the type parameter are:

Gtk::SHADOW_NONE
Gtk::SHADOW_IN
Gtk::SHADOW_OUT
Gtk::SHADOW_ETCHED_IN
Gtk::SHADOW_ETCHED_OUT

Prev Next