Viewport


Object Hierarchy:

Object hierarchy for Viewport

Description:

public class Viewport : Bin, Implementor, Buildable, Scrollable

The Viewport widget acts as an adaptor class, implementing scrollability for child widgets that lack their own scrolling capabilities.

Use GtkViewport to scroll child widgets such as Grid, Box, and so on.

If a widget has native scrolling abilities, such as TextView, TreeView or IconView, it can be added to a ScrolledWindow with add. If a widget does not, you must first add the widget to a Viewport, then add the viewport to the scrolled window. add does this automatically if a child that does not implement Scrollable is added to a ScrolledWindow, so you can ignore the presence of the viewport.

The GtkViewport will start scrolling content only if allocated less than the child widget’s minimum size in a given orientation.

CSS nodes

GtkViewport has a single CSS node with name viewport.

Example: Viewport:

public class Application : Gtk.Window {
public Application (string filename) {
// Prepare Gtk.Window:
this.title = "My Gtk.Viewport";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (200, 200);

// ScrolledWindow:
Gtk.ScrolledWindow scrolled = new Gtk.ScrolledWindow (null, null);
this.add (scrolled);

// The Viewport:
Gtk.Viewport viewport = new Gtk.Viewport (null, null);
viewport.set_size_request (200, 200);
scrolled.add (viewport);

// A Pixbuf:
Gtk.Image img = new Gtk.Image.from_file (filename);
viewport.add (img);
}

public static int main (string[] args) {
Gtk.init (ref args);

if (args[1] == null) {
print ("Error: Use `./Gtk.Viewport <image-path>`\n");
return 0;
}

Application app = new Application (args[1]);
app.show_all ();
Gtk.main ();
return 0;
}
}

valac --pkg gtk+-3.0 Gtk.Viewport.vala


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class Gtk.Bin
All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor