[gtk+/wip/matthiasc/tab-strip] tests: Better example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/tab-strip] tests: Better example
- Date: Tue, 31 May 2016 12:49:47 +0000 (UTC)
commit 9552ced2d87e61712174c385de2b2925c228196f
Author: Matthias Clasen <mclasen redhat com>
Date: Tue May 31 08:06:36 2016 -0400
tests: Better example
Populate the example with typical web page titles, and move the
new tab button to the headerbar.
tests/testtabstrip.c | 52 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 38 insertions(+), 14 deletions(-)
---
diff --git a/tests/testtabstrip.c b/tests/testtabstrip.c
index f54a64a..fdc756a 100644
--- a/tests/testtabstrip.c
+++ b/tests/testtabstrip.c
@@ -1,17 +1,15 @@
#include <gtk/gtk.h>
+static int count = 1;
+
static void
-add_stack_child (GtkWidget *stack)
+add_child (GtkWidget *stack,
+ const char *title)
{
- static int count;
char *name;
- char *title;
GtkWidget *sw, *tv;
- count++;
-
- name = g_strdup_printf ("tab%d", count);
- title = g_strdup_printf ("Page %d", count);
+ name = g_strdup_printf ("tab%d", count++);
sw = gtk_scrolled_window_new (NULL, NULL);
tv = gtk_text_view_new ();
@@ -23,22 +21,51 @@ add_stack_child (GtkWidget *stack)
gtk_stack_add_titled (GTK_STACK (stack), sw, name, title);
g_free (name);
+}
+
+static void
+add_stack_child (GtkWidget *stack)
+{
+ char *title;
+
+ title = g_strdup_printf ("Page %d", count);
+ add_child (stack, title);
g_free (title);
}
+static void
+populate (GtkWidget *stack)
+{
+ add_child (stack, "Enigma machine - Wikipedia, the free ecyclopedia");
+ add_child (stack, "Ada Lovelace");
+ add_child (stack, "Analytical Engine | computer | Britannica.com");
+ add_child (stack, "Charles Babbage");
+ add_child (stack, "Turing Machine — from Wolfram MathWorld");
+ add_child (stack, "Enigma machine - Wikipedia, the free ecyclopedia");
+ add_child (stack, "Enigma machine - Wikipedia, the free ecyclopedia");
+ add_child (stack, "Enigma machine - Wikipedia, the free ecyclopedia");
+ add_child (stack, "Enigma machine - Wikipedia, the free ecyclopedia");
+}
+
int
main (int argc, char *argv[])
{
GtkWidget *window;
+ GtkWidget *titlebar;
GtkWidget *vbox;
GtkWidget *tabs;
- GtkWidget *box;
GtkWidget *stack;
GtkWidget *button;
gtk_init (NULL, NULL);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 600, 800);
+ titlebar = gtk_header_bar_new ();
+ gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (titlebar), TRUE);
+ gtk_widget_show (titlebar);
+ gtk_window_set_titlebar (GTK_WINDOW (window), titlebar);
+ gtk_window_set_title (GTK_WINDOW (window), "Tab Strip Test");
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -51,19 +78,16 @@ main (int argc, char *argv[])
gtk_tab_strip_set_closable (GTK_TAB_STRIP (tabs), TRUE);
gtk_tab_strip_set_stack (GTK_TAB_STRIP (tabs), GTK_STACK (stack));
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_pack_start (GTK_BOX (box), tabs, TRUE, TRUE, 0);
-
button = gtk_button_new_from_icon_name ("tab-new-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
- gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (titlebar), button);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (add_stack_child), stack);
- gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), tabs, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), stack, TRUE, TRUE, 0);
- add_stack_child (stack);
+ populate (stack);
gtk_widget_show_all (window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]