CellRendererSpin
Object Hierarchy:
Description:
public class CellRendererSpin : CellRendererText
CellRendererSpin renders text in a cell like CellRendererText from which it is derived.
But while CellRendererText offers a simple entry to edit the text, CellRendererSpin offers a SpinButton widget. Of course, that means that the text has to be parseable as a floating point number.
The range of the spinbutton is taken from the adjustment property of the cell renderer, which can be set explicitly or mapped to a column in the tree model, like all properties of cell renders. CellRendererSpin also has properties for the climb_rate and the number of digits to display. Other SpinButton properties can be set in a handler for the editing_started signal.
The CellRendererSpin cell renderer was added in GTK+ 2.10.
Example: CellRendererSpin:
public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.CellRendererSpin";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (350, 70);
// The Model:
Gtk.ListStore list_store = new Gtk.ListStore (2, typeof (string), typeof (int));
Gtk.TreeIter iter;
list_store.append (out iter);
list_store.set (iter, 0, "Burgenland", 1, 13);
list_store.append (out iter);
list_store.set (iter, 0, "Carinthia", 1, 17);
list_store.append (out iter);
list_store.set (iter, 0, "Lower Austria", 1, 75);
list_store.append (out iter);
list_store.set (iter, 0, "Upper Austria", 1, 32);
list_store.append (out iter);
list_store.set (iter, 0, "Salzburg", 1, 10);
list_store.append (out iter);
list_store.set (iter, 0, "Styria", 1, 34);
list_store.append (out iter);
list_store.set (iter, 0, "Tyrol", 1, 11);
list_store.append (out iter);
list_store.set (iter, 0, "Vorarlberg", 1, 5);
list_store.append (out iter);
list_store.set (iter, 0, "Vienna", 1, 1);
// The View:
Gtk.TreeView view = new Gtk.TreeView.with_model (list_store);
this.add (view);
Gtk.CellRenderer cell = new Gtk.CellRendererText ();
view.insert_column_with_attributes (-1, "State", cell, "text", 0);
Gtk.CellRendererSpin spin = new Gtk.CellRendererSpin ();
spin.adjustment = new Gtk.Adjustment (0, 0, double.MAX, 1, 2, 0);
spin.editable = true;
spin.edited.connect ((path, new_text) => {
int val = int.parse (new_text);
list_store.get_iter (out iter, new Gtk.TreePath.from_string (path));
list_store.set_value (iter, 1, val);
});
Gtk.TreeViewColumn column = new Gtk.TreeViewColumn ();
column.set_title ("Cities");
column.pack_start (spin, false);
column.add_attribute (spin, "text", 1);
view.append_column (column);
}
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.CellRendererSpin.vala