Blame platform-demos/C/samples/colorbutton.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 |
/* Create the window of this application and show it. */
|
|
Packit |
1470ea |
var window = new Gtk.ApplicationWindow (this);
|
|
Packit |
1470ea |
window.title = "ColorButton";
|
|
Packit |
1470ea |
window.set_default_size (150, 50);
|
|
Packit |
1470ea |
window.set_border_width (10);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a new ColorButton with default blue. */
|
|
Packit |
1470ea |
var blue = Gdk.RGBA ();
|
|
Packit |
1470ea |
blue.parse ("blue");
|
|
Packit |
1470ea |
var colorbutton = new Gtk.ColorButton.with_rgba (blue);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
label = new Gtk.Label ("Click to choose a color");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var grid = new Gtk.Grid ();
|
|
Packit |
1470ea |
grid.attach (colorbutton, 0, 0, 1, 1);
|
|
Packit |
1470ea |
grid.attach_next_to (label, colorbutton, Gtk.PositionType.BOTTOM, 1, 1);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
colorbutton.color_set.connect (this.on_color_set);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
window.add (grid);
|
|
Packit |
1470ea |
window.show_all ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void on_color_set (Gtk.ColorButton button) {
|
|
Packit |
1470ea |
var color = button.get_rgba ();
|
|
Packit |
1470ea |
label.set_text ("RGBA: " + color.to_string());
|
|
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 |
}
|