Blame platform-demos/C/samples/checkbutton.vala
|
Packit |
1470ea |
/* A window in the application */
|
|
Packit |
1470ea |
class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The constructor */
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "CheckButton Example");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.set_default_size (300, 100);
|
|
Packit |
1470ea |
this.border_width = 10;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var checkbutton = new Gtk.CheckButton.with_label ("Show Title");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Connect the checkbutton to the
|
|
Packit |
1470ea |
* callback function (aka. signal handler).
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
checkbutton.toggled.connect (this.toggled_cb);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Add the button to the this window */
|
|
Packit |
1470ea |
this.add (checkbutton);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
checkbutton.set_active (true);
|
|
Packit |
1470ea |
checkbutton.show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The signal handler for the 'toggled' signal of the checkbutton. */
|
|
Packit |
1470ea |
void toggled_cb (Gtk.ToggleButton checkbutton) {
|
|
Packit |
1470ea |
if (checkbutton.get_active())
|
|
Packit |
1470ea |
this.set_title ("CheckButton Example");
|
|
Packit |
1470ea |
else
|
|
Packit |
1470ea |
this.set_title ("");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This is the application */
|
|
Packit |
1470ea |
class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* The constructor */
|
|
Packit |
1470ea |
internal MyApplication () {
|
|
Packit |
1470ea |
Object (application_id: "org.example.checkbutton");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Override the activate signal of GLib.Application */
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new MyWindow (this).show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* main creates and runs the application */
|
|
Packit |
1470ea |
int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|