|
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="button.vala" xml:lang="cs">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Button (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#buttons"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="GtkApplicationWindow.vala"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-02-21" status="stub"/>
|
|
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>Widget tlačítka, který vyšle signál při kliknutí</desc>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Widget Button</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/button.png"/>
|
|
Packit |
1470ea |
Widget tlačítka napojený na jednoduchou funkci zpětného volání.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Okno v aplikaci */
|
|
Packit |
1470ea |
public class MyWindow : Gtk.ApplicationWindow {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Konstruktor okna */
|
|
Packit |
1470ea |
internal MyWindow (MyApplication app) {
|
|
Packit |
1470ea |
Object (application: app, title: "GNOME Button");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var button = new Gtk.Button.with_label ("Click Me");
|
|
Packit |
1470ea |
button.clicked.connect (this.reverse_label);
|
|
Packit |
1470ea |
button.show ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
this.window_position = Gtk.WindowPosition.CENTER;
|
|
Packit |
1470ea |
this.set_default_size (250,50);
|
|
Packit |
1470ea |
this.add (button);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Funkce zpětného volání napojen na
|
|
Packit |
1470ea |
* signál "clicked" tlačítka
|
|
Packit |
1470ea |
*/
|
|
Packit |
1470ea |
void reverse_label (Gtk.Button button) {
|
|
Packit |
1470ea |
button.label = button.label.reverse ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Toto je aplikace */
|
|
Packit |
1470ea |
public class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Toto je konstruktor */
|
|
Packit |
1470ea |
internal MyApplication () {
|
|
Packit |
1470ea |
Object (application_id: "org.example.MyApplication");
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Přepíše signál "activate" z GLib.Application */
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
new MyWindow (this).show ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* main vytvoří a spustí aplikaci */
|
|
Packit |
1470ea |
public int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
V této ukázce se používá následující: <link href="http://www.valadoc.org/gtk+-3.0/Gtk.Button.html">Gtk.Button</link>
|
|
Packit |
1470ea |
</page>
|