1/* This is the application. */
2public class MyApplication : Gtk.Application {
3	Gtk.Scale h_scale;
4	Gtk.Scale v_scale;
5	Gtk.Label label;
6
7	/* Override the 'activate' signal of GLib.Application. */
8	protected override void activate () {
9		var window = new Gtk.ApplicationWindow (this);
10		window.title = "Scale Example";
11		window.set_default_size (400, 300);
12		window.set_border_width (5);
13
14		h_scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0.0, 100.0, 5.0);
15		h_scale.set_digits (0); //number of decimal places displayed
16		h_scale.set_valign (Gtk.Align.START); //horizontal alignment
17
18		var adjustment = new Gtk.Adjustment (42.0, 0.0, 100.0, 5.0, 10.0, 0.0);
19		v_scale = new Gtk.Scale (Gtk.Orientation.VERTICAL, adjustment);
20		v_scale.set_vexpand(true);
21
22		label = new Gtk.Label ("Move the scale handles...");
23
24		var grid = new Gtk.Grid ();
25		grid.set_column_spacing (10); //amount of space between columns
26		grid.set_column_homogeneous (true); //all columns same width
27		grid.attach (h_scale, 0, 0, 1, 1);
28		grid.attach_next_to (v_scale, h_scale, Gtk.PositionType.RIGHT, 1, 1);
29		grid.attach (label, 0, 1, 2, 1);
30
31		h_scale.value_changed.connect (scale_moved);
32		v_scale.value_changed.connect (scale_moved);
33
34		window.add (grid);
35		window.show_all ();
36	}
37
38	/* Callback function for "value-changed" signal.
39	 * The parameter refers to the scale which emitted the signal.
40	 * Since we are accessing the values of not one, but two scales,
41	 * we made the ranges instance variables, and ignore the
42	 * parameter.
43	 */
44	void scale_moved (Gtk.Range range) {
45		label.set_text ("Horizontal scale is %.1f; vertical scale is %.1f.".printf (h_scale.get_value (), v_scale.get_value ()));
46	}
47}
48
49/* main creates and runs the application. */
50public int main (string[] args) {
51	return new MyApplication ().run (args);
52}
53