IconView provides an alternative view on a TreeModel.
It displays the model as a grid of icons with labels. Like TreeView, it allows to select one or multiple items (depending on the selection mode, see set_selection_mode). In addition to selection with the arrow keys, IconView supports rubberband selection, which is controlled by dragging the pointer.
Note that if the tree model is backed by an actual tree store (as opposed to a flat list where the mapping to icons is obvious), IconView will only display the first level of the tree and ignore the tree’s branches.
iconview.view
╰── [rubberband]
conView has a single CSS node with name iconview and
style class .view. For rubberband selection, a subnode with name rubberband is used.
Example: IconView:
public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.IconView";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (400, 400);
// The Model:
Gtk.ListStore model = new Gtk.ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
Gtk.TreeIter iter;
// The IconView:
Gtk.IconView view = new Gtk.IconView.with_model (model);
view.set_pixbuf_column (0);
view.set_text_column (1);
this.add (view);
// Data:
Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
try {
model.append (out iter);
Gdk.Pixbuf pixbuf = icon_theme.load_icon ("help-about", 20, 0);
model.set (iter, 0, pixbuf, 1, "Dialog");
model.append (out iter);
pixbuf = icon_theme.load_icon ("document-print", 20, 0);
model.set (iter, 0, pixbuf, 1, "Print");
model.append (out iter);
pixbuf = icon_theme.load_icon ("help-about", 20, 0);
model.set (iter, 0, pixbuf, 1, "Help");
} catch (Error e) {
// TODO
assert_not_reached ();
}
view.selection_changed.connect (() => {
List<Gtk.TreePath> paths = view.get_selected_items ();
Value title;
Value icon;
foreach (Gtk.TreePath path in paths) {
bool tmp = model.get_iter (out iter, path);
assert (tmp == true);
model.get_value (iter, 0, out icon);
model.get_value (iter, 1, out title);
print ("%s: %p\n", (string) title, ((Gdk.Pixbuf) icon));
}
});
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}
valac --pkg gtk+-3.0 Gtk.IconView.vala
GtkIconView::markup-column
property contains the
number of the model column containing markup information to be displayed.
GtkIconView::pixbuf-column
property contains the
number of the model column containing the pixbufs which are displayed.
GtkIconView::selection-mode
property specifies the
selection mode of icon view.
GtkIconView::text-column
property contains the number
of the model column containing the texts which are displayed.
area
to layout cells inside the icons.
model
.
path
.
path
and cell
.
GtkIconView::column-spacing
property.
GtkIconView::columns
s property.
path
and cell
with the current
cursor path and cell.
x
, y
), relative
to bin_window coordinates.
path
is currently
displayed.
GtkIconView::item-orientation
property which determines whether the labels are drawn beside the icons instead of below.
GtkIconView::item-padding
property.
path
is currently
displayed.
GtkIconView::item-width
property.
GtkIconView::margin
property.
x
, y
), relative
to bin_window coordinates.
GtkIconView::row-spacing
property.
GtkIconView::spacing
property.
start_path
and end_path
to be the first
and last visible path.
path
is currently selected.
path
.
path
.
GtkIconView::column-spacing
property which
specifies the space which is inserted between the columns of the icon view.
GtkIconView::columns
s property which determines
in how many columns the icons are arranged.
path
, and
selects it.
GtkIconView::item-orientation
property which
determines whether the labels are drawn beside the icons instead of below.
GtkIconView::item-width
property which specifies
the width to use for each item.
GtkIconView::margin
property which specifies the
space which is inserted at the top, bottom, left and right of the icon view.
column
.
column
.
GtkIconView::row-spacing
property which
specifies the space which is inserted between the rows of the icon view.
GtkIconView::spacing
property which specifies
the space which is inserted between the cells (i.
column
.
tooltip
to the area which cell
occupies in the item pointed to by path
.
tooltip
to be the area covered by
the item at path
.
path
.