[gnome-devel-docs] Vala ToggleButton example.



commit cf46f9a137f2b04530f39438cb2ce39ac30bede0
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Wed May 9 14:01:16 2012 -0400

    Vala ToggleButton example.

 platform-demos/C/media/togglebutton.png    |  Bin 0 -> 14667 bytes
 platform-demos/C/samples/togglebutton.vala |   55 ++++++++++++++++++++++++++++
 platform-demos/C/togglebutton.vala.page    |   32 ++++++++++++++++
 platform-demos/Makefile.am                 |    3 ++
 4 files changed, 90 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/media/togglebutton.png b/platform-demos/C/media/togglebutton.png
new file mode 100644
index 0000000..9258e23
Binary files /dev/null and b/platform-demos/C/media/togglebutton.png differ
diff --git a/platform-demos/C/samples/togglebutton.vala b/platform-demos/C/samples/togglebutton.vala
new file mode 100644
index 0000000..252c3e2
--- /dev/null
+++ b/platform-demos/C/samples/togglebutton.vala
@@ -0,0 +1,55 @@
+public class MyWindow : Gtk.ApplicationWindow {
+
+	Gtk.Spinner spinner;
+
+	internal MyWindow (MyApplication app) {
+		Object (application: app, title: "ToggleButton Example");
+
+		this.set_default_size (300, 300);
+		this.border_width = 30;
+
+		/*Spinner*/
+		spinner = new Gtk.Spinner ();
+		spinner.set_hexpand (true);
+		spinner.set_vexpand (true);
+
+		/*ToggleButton*/
+		var togglebutton = new Gtk.ToggleButton.with_label ("Start/Stop");
+		togglebutton.toggled.connect (toggled_cb);
+		
+		/*Grid*/
+		var grid = new Gtk.Grid ();
+		grid.set_row_homogeneous (false);
+		grid.set_row_spacing (15);
+		grid.attach (spinner, 0, 0, 1, 1);
+		grid.attach (togglebutton, 0, 1, 1, 1);
+
+		this.add (grid);
+	}
+
+	void toggled_cb (Gtk.ToggleButton button) {
+		if (button.get_active()) {
+			spinner.start ();
+		}
+		else {
+			spinner.stop ();
+		}
+	}
+}
+
+public class MyApplication : Gtk.Application {
+
+	protected override void activate () {
+
+		//Show all the things
+		new MyWindow (this).show_all ();
+	}
+
+	internal MyApplication () {
+		Object (application_id: "org.example.spinner");
+	}
+}
+
+public int main (string[] args) {
+	return new MyApplication ().run (args);
+}
diff --git a/platform-demos/C/togglebutton.vala.page b/platform-demos/C/togglebutton.vala.page
new file mode 100644
index 0000000..94cda67
--- /dev/null
+++ b/platform-demos/C/togglebutton.vala.page
@@ -0,0 +1,32 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="togglebutton.vala">
+  <info>
+    <link type="guide" xref="beginner.vala#samples"/>
+    <link type="seealso" xref="grid"/>
+    <link type="seealso" xref="spinner"/>
+
+    <revision version="0.1" date="2012-05-09" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Tiffany Antopolski</name>
+      <email>tiffany antopolski gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A button which retains state</desc>
+  </info>
+
+  <title>ToggleButton</title>
+  <media type="image" mime="image/png" src="media/togglebutton.png"/>
+  <p>When this ToggleButton is in an active state, the spinner spins.</p>
+
+<code mime="text/x-vala" style="numbered"><xi:include href="samples/togglebutton.vala" parse="text"><xi:fallback/></xi:include></code>
+<p>
+  In this sample we used the following:
+</p>
+<list>
+  <item><p><link href="http://www.valadoc.org/#!api=gtk+-3.0/Gtk.ToggleButton";>Gtk.ToggleButton</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 71889d5..d4fe3bf 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -47,6 +47,7 @@ demo_sources = \
 	samples/radiobutton.vala		\
 	samples/spinner.vala			\
 	samples/statusbar.vala			\
+	samples/togglebutton.vala		\
 	samples/toolbar.vala			\
 	samples/window.c			\
 	samples/window.py			\
@@ -85,6 +86,7 @@ DOC_FIGURES = \
 	media/record-collection.png		\
 	media/spinner.png			\
 	media/statusbar.png			\
+	media/togglebutton.png			\
 	media/toolbar.png			\
 	media/toolbar2.png			\
 	media/ubuntu.png			\
@@ -152,6 +154,7 @@ DOC_PAGES =				\
 	record-collection.js.page	\
 	spinner.vala.page		\
 	statusbar.vala.page		\
+	togglebutton.vala.page		\
 	toolbar.js.page			\
 	toolbar.vala.page		\
 	translate.page			\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]