[gnome-devel-docs] Vala toolbar example, with fullscreen ability.
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] Vala toolbar example, with fullscreen ability.
- Date: Tue, 8 May 2012 06:46:22 +0000 (UTC)
commit 71bb151d6104a0c76b813435219186f57159ed6e
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date: Tue May 8 02:45:36 2012 -0400
Vala toolbar example, with fullscreen ability.
platform-demos/C/media/toolbar2.png | Bin 0 -> 6664 bytes
platform-demos/C/samples/toolbar.vala | 101 +++++++++++++++++++++++++++++++++
platform-demos/C/toolbar.vala.page | 22 +++++--
platform-demos/Makefile.am | 3 +
4 files changed, 119 insertions(+), 7 deletions(-)
---
diff --git a/platform-demos/C/media/toolbar2.png b/platform-demos/C/media/toolbar2.png
new file mode 100644
index 0000000..d931d21
Binary files /dev/null and b/platform-demos/C/media/toolbar2.png differ
diff --git a/platform-demos/C/samples/toolbar.vala b/platform-demos/C/samples/toolbar.vala
new file mode 100644
index 0000000..759e426
--- /dev/null
+++ b/platform-demos/C/samples/toolbar.vala
@@ -0,0 +1,101 @@
+public class MyToolbar : Gtk.Toolbar {
+
+ Gtk.ApplicationWindow window;
+ Gtk.ToolButton new_button;
+ Gtk.ToolButton open_button;
+ Gtk.ToolButton undo_button;
+ Gtk.ToolButton fullscreen_button;
+ Gtk.ToolButton leave_fullscreen_button;
+ bool window_is_fullscreen = false;
+
+ public MyToolbar (MyWindow window) {
+
+ this.window = window;
+
+ this.get_style_context ().add_class (Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
+
+ new_button = new Gtk.ToolButton.from_stock (Gtk.Stock.NEW);
+ new_button.is_important = true; //decides whether to show the label
+ this.add (new_button);
+ new_button.show ();
+ new_button.clicked.connect (on_new_clicked);
+
+ open_button = new Gtk.ToolButton.from_stock (Gtk.Stock.OPEN);
+ open_button.is_important = true;
+ this.add (open_button);
+ open_button.clicked.connect (on_open_clicked);
+
+ undo_button = new Gtk.ToolButton.from_stock (Gtk.Stock.UNDO);
+ undo_button.is_important = true;
+ this.add (undo_button);
+ undo_button.clicked.connect (on_undo_clicked);
+
+ fullscreen_button = new Gtk.ToolButton.from_stock (Gtk.Stock.FULLSCREEN);
+ fullscreen_button.is_important = true;
+ this.add (fullscreen_button);
+ fullscreen_button.clicked.connect (on_toggle_fullscreen);
+
+ leave_fullscreen_button = new Gtk.ToolButton.from_stock (Gtk.Stock.LEAVE_FULLSCREEN);
+ leave_fullscreen_button.is_important = true;
+ leave_fullscreen_button.clicked.connect (on_toggle_fullscreen);
+ }
+
+ void on_new_clicked () {
+ print ("You clicked the \"New\" ToolButton.\n");
+ }
+
+ void on_open_clicked () {
+ print ("You clicked the \"Open\" ToolButton.\n");
+ }
+
+ void on_undo_clicked () {
+ print ("You clicked the \"Undo\" ToolButton.\n");
+ }
+
+ void on_toggle_fullscreen (Gtk.ToolButton toolbutton) {
+ if (window_is_fullscreen) {
+ this.window.unfullscreen ();
+ window_is_fullscreen = false;
+ this.remove (toolbutton);
+ this.add (fullscreen_button);
+ fullscreen_button.show ();
+ }
+ else {
+ this.window.fullscreen ();
+ window_is_fullscreen = true;
+ this.remove (toolbutton);
+ this.add (leave_fullscreen_button);
+ leave_fullscreen_button.show ();
+ }
+ }
+}
+
+class MyWindow : Gtk.ApplicationWindow {
+
+ internal MyWindow (MyApplication app) {
+ Object (application: app, title: "Toolbar Example");
+
+ this.set_default_size (400, 200);
+ var grid = new Gtk.Grid ();
+ this.add (grid);
+
+ MyToolbar toolbar = new MyToolbar (this);
+ toolbar.set_hexpand (true);
+ grid.attach (toolbar, 1, 1, 1, 1);
+ toolbar.show ();
+ }
+}
+
+class MyApplication : Gtk.Application {
+ protected override void activate () {
+ new MyWindow (this).show_all ();
+ }
+
+ internal MyApplication () {
+ Object (application_id: "org.example.toolbar");
+ }
+}
+
+int main (string[] args) {
+ return new MyApplication ().run (args);
+}
diff --git a/platform-demos/C/toolbar.vala.page b/platform-demos/C/toolbar.vala.page
index 216f0d1..0f1317f 100644
--- a/platform-demos/C/toolbar.vala.page
+++ b/platform-demos/C/toolbar.vala.page
@@ -1,9 +1,11 @@
<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
type="guide" style="task"
id="toolbar.vala">
<info>
<link type="guide" xref="beginner.vala#menu-combo-toolbar"/>
- <revision version="0.1" date="2012-02-20" status="stub"/>
+ <link type="seealso" xref="grid.vala"/>
+ <revision version="0.1" date="2012-05-08" status="draft"/>
<credit type="author copyright">
<name>Tiffany Antopolski</name>
@@ -11,17 +13,23 @@
<years>2012</years>
</credit>
- <desc>A toolbar widget which is connected to a Dialog widget</desc>
+ <desc>A bar of buttons</desc>
</info>
<title>Toolbar widget</title>
- <media type="image" mime="image/png" src="media/toolbar.png"/>
- <p>Toolbar is a widget that may contain either text or stock icons. In this sample we use stock icons.</p>
+ <media type="image" mime="image/png" src="media/toolbar2.png"/>
+ <p>Toolbar can contain either text or stock icons. In this sample we use stock icons. This example has fullscreen functionality.</p>
- <code mime="text/x-vala" style="numbered"><![CDATA[
-]]></code>
+<code mime="text/x-vala" style="numbered"><xi:include href="samples/toolbar.vala" parse="text"><xi:fallback/></xi:include></code>
-<p>In this sample we use the following widgets: <link href="">Gtk.Window</link>, <link href="">Gtk.Grid</link>, <link href="">Gtk.Toolbar</link>, <link href="">Gtk.ToolButton</link>, <link href="">Gtk.Dialog</link>.</p>
+<p>
+ In this sample we used the following:
+</p>
+<list>
+ <item><p><link href="http://references.valadoc.org/#!api=gtk+-3.0/Gtk.Toolbar">Gtk.Toolbar</link></p></item>
+ <item><p><link href="http://references.valadoc.org/#!api=gtk+-3.0/Gtk.ToolButton">Gtk.Toolbutton</link></p></item>
+ <item><p><link href="http://references.valadoc.org/#!api=gtk+-3.0/Gtk.Stock">Gtk.Stock</link></p></item>
+</list>
</page>
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index a6b1f36..8dfdc52 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -44,6 +44,7 @@ demo_sources = \
samples/messagedialog.vala \
samples/progressbar.vala \
samples/spinner.vala \
+ samples/toolbar.vala \
samples/window.c \
samples/window.py \
samples/window.vala \
@@ -79,6 +80,7 @@ DOC_FIGURES = \
media/record-collection.png \
media/spinner.png \
media/toolbar.png \
+ media/toolbar2.png \
media/ubuntu.png \
media/weatherAppJs.png \
media/window.png \
@@ -142,6 +144,7 @@ DOC_PAGES = \
progressbar.vala.page \
py.page \
record-collection.js.page \
+ toolbar.vala.page \
translate.page \
vala.page \
weatherApp.js.page \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]