|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="checkbutton.vala" xml:lang="pt-BR">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">CheckButton (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#buttons"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-09" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Create widgets with a discrete toggle button</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Rafael Ferreira</mal:name>
|
|
Packit |
1470ea |
<mal:email>rafael.f.f1@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>CheckButton</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/checkbutton.png"/>
|
|
Packit |
1470ea |
This CheckButton toggles the title.
|
|
Packit |
1470ea |
|
|
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 |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.CheckButton.html">Gtk.CheckButton</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|