Blame platform-demos/C/samples/spinbutton.vala
|
Packit |
1470ea |
/* This is the application. */
|
|
Packit |
1470ea |
public class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
Gtk.Label label;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Override the 'activate' signal of GLib.Application. */
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
var window = new Gtk.ApplicationWindow (this);
|
|
Packit |
1470ea |
window.title = "SpinButton Example";
|
|
Packit |
1470ea |
window.set_default_size (210, 70);
|
|
Packit |
1470ea |
window.set_border_width (5);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var spinbutton = new Gtk.SpinButton.with_range (0, 100, 1);
|
|
Packit |
1470ea |
spinbutton.set_hexpand (true);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
label = new Gtk.Label ("Choose a number");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var grid = new Gtk.Grid ();
|
|
Packit |
1470ea |
grid.attach (spinbutton, 0, 0, 1, 1);
|
|
Packit |
1470ea |
grid.attach (label, 0, 1, 1, 1);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
spinbutton.value_changed.connect (this.value_changed_cb);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
window.add (grid);
|
|
Packit |
1470ea |
window.show_all ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void value_changed_cb (Gtk.SpinButton spin) {
|
|
Packit |
1470ea |
label.set_text ("The number you selected is %.0f.".printf (spin.get_value()));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* main creates and runs the application. */
|
|
Packit |
1470ea |
public int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|