1/* This is the application. */ 2public class MyApplication : Gtk.Application { 3 Gtk.Label label; 4 5 /* Override the 'activate' signal of GLib.Application. */ 6 protected override void activate () { 7 /* Create the window of this application and show it. */ 8 var window = new Gtk.ApplicationWindow (this); 9 window.title = "ColorButton"; 10 window.set_default_size (150, 50); 11 window.set_border_width (10); 12 13 /* Create a new ColorButton with default blue. */ 14 var blue = Gdk.RGBA (); 15 blue.parse ("blue"); 16 var colorbutton = new Gtk.ColorButton.with_rgba (blue); 17 18 label = new Gtk.Label ("Click to choose a color"); 19 20 var grid = new Gtk.Grid (); 21 grid.attach (colorbutton, 0, 0, 1, 1); 22 grid.attach_next_to (label, colorbutton, Gtk.PositionType.BOTTOM, 1, 1); 23 24 colorbutton.color_set.connect (this.on_color_set); 25 26 window.add (grid); 27 window.show_all (); 28 } 29 30 void on_color_set (Gtk.ColorButton button) { 31 var color = button.get_rgba (); 32 label.set_text ("RGBA: " + color.to_string()); 33 } 34} 35 36/* main creates and runs the application. */ 37public int main (string[] args) { 38 return new MyApplication ().run (args); 39} 40