Blame platform-demos/C/samples/scale.vala

Packit 1470ea
/* This is the application. */
Packit 1470ea
public class MyApplication : Gtk.Application {
Packit 1470ea
	Gtk.Scale h_scale;
Packit 1470ea
	Gtk.Scale v_scale;
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 = "Scale Example";
Packit 1470ea
		window.set_default_size (400, 300);
Packit 1470ea
		window.set_border_width (5);
Packit 1470ea
Packit 1470ea
		h_scale = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0.0, 100.0, 5.0);
Packit 1470ea
		h_scale.set_digits (0); //number of decimal places displayed
Packit 1470ea
		h_scale.set_valign (Gtk.Align.START); //horizontal alignment
Packit 1470ea
Packit 1470ea
		var adjustment = new Gtk.Adjustment (42.0, 0.0, 100.0, 5.0, 10.0, 0.0);
Packit 1470ea
		v_scale = new Gtk.Scale (Gtk.Orientation.VERTICAL, adjustment);
Packit 1470ea
		v_scale.set_vexpand(true);
Packit 1470ea
Packit 1470ea
		label = new Gtk.Label ("Move the scale handles...");
Packit 1470ea
Packit 1470ea
		var grid = new Gtk.Grid ();
Packit 1470ea
		grid.set_column_spacing (10); //amount of space between columns
Packit 1470ea
		grid.set_column_homogeneous (true); //all columns same width
Packit 1470ea
		grid.attach (h_scale, 0, 0, 1, 1);
Packit 1470ea
		grid.attach_next_to (v_scale, h_scale, Gtk.PositionType.RIGHT, 1, 1);
Packit 1470ea
		grid.attach (label, 0, 1, 2, 1);
Packit 1470ea
Packit 1470ea
		h_scale.value_changed.connect (scale_moved);
Packit 1470ea
		v_scale.value_changed.connect (scale_moved);
Packit 1470ea
Packit 1470ea
		window.add (grid);
Packit 1470ea
		window.show_all ();
Packit 1470ea
	}
Packit 1470ea
Packit 1470ea
	/* Callback function for "value-changed" signal.
Packit 1470ea
	 * The parameter refers to the scale which emitted the signal.
Packit 1470ea
	 * Since we are accessing the values of not one, but two scales,
Packit 1470ea
	 * we made the ranges instance variables, and ignore the
Packit 1470ea
	 * parameter.
Packit 1470ea
	 */
Packit 1470ea
	void scale_moved (Gtk.Range range) {
Packit 1470ea
		label.set_text ("Horizontal scale is %.1f; vertical scale is %.1f.".printf (h_scale.get_value (), v_scale.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
}