2008-07-31 Alberto Garcia <agarcia@igalia.com>
authorAlberto Garcia <agarcia@igalia.com>
Thu, 31 Jul 2008 19:33:13 +0000 (19:33 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Thu, 31 Jul 2008 19:33:13 +0000 (19:33 +0000)
* src/hildon-button.c: Updated documentation.

* examples/hildon-button-example.c: Add the posibility to create
the buttons using horizontal layout for title and value.

ChangeLog
examples/hildon-button-example.c
src/hildon-button.c

index 6fdf630..c110874 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-07-31  Alberto Garcia  <agarcia@igalia.com>
 
+       * src/hildon-button.c: Updated documentation.
+
+       * examples/hildon-button-example.c: Add the posibility to create
+       the buttons using horizontal layout for title and value.
+
+2008-07-31  Alberto Garcia  <agarcia@igalia.com>
+
        * src/hildon-app-menu-private.h
        * src/hildon-app-menu.c (hildon_app_menu_add_filter)
        (hildon_app_menu_init, hildon_app_menu_finalize): Don't use a
index 47d9c4b..58871b4 100644 (file)
@@ -33,7 +33,8 @@ button_clicked_cb                               (HildonButton *button,
 }
 
 static void
-vertical_buttons_window                         (void)
+vertical_buttons_window                         (GtkButton *b,
+                                                 GtkToggleButton *horizontal)
 {
     GtkWidget *win;
     GtkWidget *button;
@@ -42,11 +43,16 @@ vertical_buttons_window                         (void)
     GtkBox *vbox2;
     GtkBox *vbox3;
     int i;
+    HildonButtonFlags layout;
 
     /* Create window */
     win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_container_set_border_width (GTK_CONTAINER (win), 20);
 
+    layout = gtk_toggle_button_get_active (horizontal) ?
+            HILDON_BUTTON_WITH_HORIZONTAL_VALUE :
+            HILDON_BUTTON_WITH_VERTICAL_VALUE;
+
     /* Create and pack boxes */
     hbox = GTK_BOX (gtk_hbox_new (FALSE, 10));
     vbox1 = GTK_BOX (gtk_vbox_new (FALSE, 10));
@@ -61,7 +67,7 @@ vertical_buttons_window                         (void)
     gtk_box_pack_start (vbox1, gtk_label_new ("Finger height"), FALSE, FALSE, 0);
     for (i = 0; i < 4; i++) {
         char *title = g_strdup_printf ("Title %d", i);
-        button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+        button = hildon_button_new_with_text (layout |
                                               HILDON_BUTTON_FINGER_HEIGHT, title,
                                               i % 2 ? "Value" : NULL);
         g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
@@ -73,7 +79,7 @@ vertical_buttons_window                         (void)
     gtk_box_pack_start (vbox2, gtk_label_new ("Thumb height"), FALSE, FALSE, 0);
     for (i = 0; i < 3; i++) {
         char *title = g_strdup_printf ("Title %d", i);
-        button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+        button = hildon_button_new_with_text (layout |
                                               HILDON_BUTTON_THUMB_HEIGHT, title,
                                               i % 2 ? "Value" : NULL);
         g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
@@ -85,7 +91,7 @@ vertical_buttons_window                         (void)
     gtk_box_pack_start (vbox3, gtk_label_new ("Auto height"), FALSE, FALSE, 0);
     for (i = 0; i < 6; i++) {
         char *title = g_strdup_printf ("Title %d", i);
-        button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE, title,
+        button = hildon_button_new_with_text (layout, title,
                                               i % 2 ? "Value" : NULL);
         g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
         gtk_box_pack_start (vbox3, button, FALSE, FALSE, 0);
@@ -100,7 +106,8 @@ vertical_buttons_window                         (void)
 }
 
 static void
-horizontal_buttons_window                       (void)
+horizontal_buttons_window                       (GtkButton *b,
+                                                 GtkToggleButton *horizontal)
 {
     GtkWidget *win;
     GtkWidget *button;
@@ -109,11 +116,16 @@ horizontal_buttons_window                       (void)
     GtkBox *hbox2;
     GtkBox *hbox3;
     GtkBox *hbox4;
+    HildonButtonFlags layout;
 
     /* Create window */
     win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     gtk_container_set_border_width (GTK_CONTAINER (win), 20);
 
+    layout = gtk_toggle_button_get_active (horizontal) ?
+            HILDON_BUTTON_WITH_HORIZONTAL_VALUE :
+            HILDON_BUTTON_WITH_VERTICAL_VALUE;
+
     /* Create and pack boxes */
     vbox = GTK_BOX (gtk_vbox_new (FALSE, 10));
     hbox1 = GTK_BOX (gtk_hbox_new (FALSE, 10));
@@ -128,20 +140,20 @@ horizontal_buttons_window                       (void)
     gtk_box_pack_start (vbox, GTK_WIDGET (hbox4), FALSE, FALSE, 0);
 
     /* Full screen width button */
-    button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+    button = hildon_button_new_with_text (layout |
                                           HILDON_BUTTON_FULLSCREEN_WIDTH |
                                           HILDON_BUTTON_FINGER_HEIGHT, "Full width", "Value");
     gtk_box_pack_start (hbox1, button, TRUE, TRUE, 0);
     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
 
     /* Half screen width buttons */
-    button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+    button = hildon_button_new_with_text (layout |
                                           HILDON_BUTTON_HALFSCREEN_WIDTH |
                                           HILDON_BUTTON_FINGER_HEIGHT, "Half width 1", "Value");
     gtk_box_pack_start (hbox2, button, TRUE, TRUE, 0);
     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
 
-    button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+    button = hildon_button_new_with_text (layout |
                                           HILDON_BUTTON_HALFSCREEN_WIDTH |
                                           HILDON_BUTTON_FINGER_HEIGHT,
                                           "Half width 2 with long title",
@@ -150,13 +162,13 @@ horizontal_buttons_window                       (void)
     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
 
     /* Half screen width buttons */
-    button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+    button = hildon_button_new_with_text (layout |
                                           HILDON_BUTTON_HALFSCREEN_WIDTH |
                                           HILDON_BUTTON_FINGER_HEIGHT, "Half width 3", NULL);
     gtk_box_pack_start (hbox3, button, TRUE, TRUE, 0);
     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
 
-    button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+    button = hildon_button_new_with_text (layout |
                                           HILDON_BUTTON_HALFSCREEN_WIDTH |
                                           HILDON_BUTTON_FINGER_HEIGHT,
                                           "Half width 4 with very long title (REALLY long)",
@@ -165,14 +177,14 @@ horizontal_buttons_window                       (void)
     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
 
     /* Auto width button */
-    button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+    button = hildon_button_new_with_text (layout |
                                           HILDON_BUTTON_AUTO_WIDTH |
                                           HILDON_BUTTON_FINGER_HEIGHT,
                                           "Auto width 1", "Value");
     gtk_box_pack_start (hbox4, button, TRUE, TRUE, 0);
     g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
 
-    button = hildon_button_new_with_text (HILDON_BUTTON_WITH_VERTICAL_VALUE |
+    button = hildon_button_new_with_text (layout |
                                           HILDON_BUTTON_AUTO_WIDTH |
                                           HILDON_BUTTON_FINGER_HEIGHT,
                                           "Auto width 2 with longer text", NULL);
@@ -195,6 +207,9 @@ main                                            (int    argc,
     GtkWidget *but2;
     GtkWidget *label;
     GtkBox *vbox;
+    GtkWidget *align;
+    GtkWidget *horizontal_layout;
+
 
     gtk_init (&argc, &argv);
 
@@ -206,15 +221,20 @@ main                                            (int    argc,
     but1 = gtk_button_new_with_label ("Buttons with different heights");
     but2 = gtk_button_new_with_label ("Buttons with different widths");
 
+    horizontal_layout = gtk_check_button_new_with_label ("Use horizontal layout");
+    align = gtk_alignment_new (0.5, 0.5, 0, 0);
+    gtk_container_add (GTK_CONTAINER (align), horizontal_layout);
+
     gtk_box_pack_start (vbox, label, TRUE, TRUE, 0);
     gtk_box_pack_start (vbox, but1, TRUE, TRUE, 0);
     gtk_box_pack_start (vbox, but2, TRUE, TRUE, 0);
+    gtk_box_pack_start (vbox, align, FALSE, FALSE, 0);
 
     gtk_container_set_border_width (GTK_CONTAINER (win), 20);
     gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (vbox));
 
-    g_signal_connect (but1, "clicked", G_CALLBACK (vertical_buttons_window), NULL);
-    g_signal_connect (but2, "clicked", G_CALLBACK (horizontal_buttons_window), NULL);
+    g_signal_connect (but1, "clicked", G_CALLBACK (vertical_buttons_window), horizontal_layout);
+    g_signal_connect (but2, "clicked", G_CALLBACK (horizontal_buttons_window), horizontal_layout);
     g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
 
     gtk_widget_show_all (win);
index 516f6fd..0135ccf 100644 (file)
@@ -30,7 +30,9 @@
  * "auto" so it behaves like a standard GtkButton.
  *
  * The #HildonButton can hold any valid child widget, but it usually
- * contains two labels: title and value (the latter being optional).
+ * contains two labels: title and value (the latter being
+ * optional). To change the alignment of the labels, use
+ * gtk_button_set_alignment()
  */
 
 #include                                        "hildon-button.h"