[recipes/more-cuisines: 4/5] cuisines: Add an expander for cuisines



commit 0fa06a04d068a8b4a3d9c2aae3a593371262e723
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 5 12:45:34 2017 -0500

    cuisines: Add an expander for cuisines
    
    This will let us add more cuisines in the future.

 src/gr-cuisines-page.c  |   44 +++++++++++++++++++++++----
 src/gr-cuisines-page.ui |   74 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 109 insertions(+), 9 deletions(-)
---
diff --git a/src/gr-cuisines-page.c b/src/gr-cuisines-page.c
index 796fbba..0f38c86 100644
--- a/src/gr-cuisines-page.c
+++ b/src/gr-cuisines-page.c
@@ -39,7 +39,10 @@ struct _GrCuisinesPage
 {
         GtkBox parent_instance;
 
-        GtkWidget *top_box;
+        GtkWidget *cuisines_box;
+        GtkWidget *cuisines_box2;
+        GtkWidget *cuisines_more;
+        GtkWidget *cuisines_expander_image;
         GtkWidget *seasonal_box;
         GtkWidget *seasonal_box2;
         GtkWidget *seasonal_more;
@@ -61,6 +64,17 @@ cuisines_page_finalize (GObject *object)
 }
 
 static void
+set_cuisines_expanded (GrCuisinesPage *page,
+                       gboolean        expanded)
+{
+        gtk_revealer_set_transition_duration (GTK_REVEALER (page->cuisines_more), expanded ? 250 : 0);
+
+        gtk_revealer_set_reveal_child (GTK_REVEALER (page->cuisines_more), expanded);
+        gtk_image_set_from_icon_name (GTK_IMAGE (page->cuisines_expander_image),
+                                      expanded ? "pan-up-symbolic" : "pan-down-symbolic", 1);
+}
+
+static void
 set_seasonal_expanded (GrCuisinesPage *page,
                        gboolean        expanded)
 {
@@ -79,13 +93,25 @@ gr_cuisines_page_unexpand (GrCuisinesPage *page)
         transition = gtk_revealer_get_transition_type (GTK_REVEALER (page->seasonal_more));
         gtk_revealer_set_transition_type (GTK_REVEALER (page->seasonal_more),
                                           GTK_REVEALER_TRANSITION_TYPE_NONE);
-
         set_seasonal_expanded (page, FALSE);
-
         gtk_revealer_set_transition_type (GTK_REVEALER (page->seasonal_more), transition);
+
+        transition = gtk_revealer_get_transition_type (GTK_REVEALER (page->cuisines_more));
+        gtk_revealer_set_transition_type (GTK_REVEALER (page->cuisines_more),
+                                          GTK_REVEALER_TRANSITION_TYPE_NONE);
+        set_cuisines_expanded (page, FALSE);
+        gtk_revealer_set_transition_type (GTK_REVEALER (page->cuisines_more), transition);
 }
 
 static void
+cuisines_expander_button_clicked (GrCuisinesPage *page)
+{
+        gboolean expanded;
+
+        expanded = gtk_revealer_get_reveal_child (GTK_REVEALER (page->cuisines_more));
+        set_cuisines_expanded (page, !expanded);
+}
+static void
 season_expander_button_clicked (GrCuisinesPage *page)
 {
         gboolean expanded;
@@ -105,7 +131,7 @@ populate_cuisines (GrCuisinesPage *page)
         GrRecipeStore *store;
         int tiles;
 
-        container_remove_all (GTK_CONTAINER (page->top_box));
+        container_remove_all (GTK_CONTAINER (page->cuisines_box));
 
         store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
 
@@ -131,7 +157,7 @@ populate_cuisines (GrCuisinesPage *page)
         tile = gr_cuisine_tile_new (page->featured, TRUE);
         gtk_widget_show (tile);
         gtk_widget_set_halign (tile, GTK_ALIGN_FILL);
-        gtk_grid_attach (GTK_GRID (page->top_box), tile, 0, 0, 2, 1);
+        gtk_grid_attach (GTK_GRID (page->cuisines_box), tile, 0, 0, 2, 1);
 
         tiles = 0;
         for (i = 0; i < length; i++) {
@@ -141,7 +167,7 @@ populate_cuisines (GrCuisinesPage *page)
                 tile = gr_cuisine_tile_new (cuisines[i], FALSE);
                 gtk_widget_show (tile);
                 gtk_widget_set_halign (tile, GTK_ALIGN_FILL);
-                gtk_grid_attach (GTK_GRID (page->top_box), tile, tiles % 2, 1 + tiles / 2, 1, 1);
+                gtk_grid_attach (GTK_GRID (page->cuisines_box), tile, tiles % 2, 1 + tiles / 2, 1, 1);
 
                 tiles++;
 
@@ -211,13 +237,17 @@ gr_cuisines_page_class_init (GrCuisinesPageClass *klass)
 
         gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Recipes/gr-cuisines-page.ui");
 
-        gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, top_box);
+        gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, cuisines_box);
+        gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, cuisines_box2);
+        gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, cuisines_more);
+        gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, cuisines_expander_image);
         gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, seasonal_box);
         gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, seasonal_box2);
         gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, seasonal_more);
         gtk_widget_class_bind_template_child (widget_class, GrCuisinesPage, seasonal_expander_image);
 
          gtk_widget_class_bind_template_callback (widget_class, season_expander_button_clicked);
+         gtk_widget_class_bind_template_callback (widget_class, cuisines_expander_button_clicked);
 }
 
 GtkWidget *
diff --git a/src/gr-cuisines-page.ui b/src/gr-cuisines-page.ui
index 1860422..b9d7130 100644
--- a/src/gr-cuisines-page.ui
+++ b/src/gr-cuisines-page.ui
@@ -30,7 +30,7 @@
                 <property name="label" translatable="yes">World Cuisines</property>
                 <property name="xalign">0</property>
                 <accessibility>
-                  <relation target="top_box" type="label-for"/>
+                  <relation target="cuisines_box" type="label-for"/>
                 </accessibility>
                 <style>
                   <class name="heading"/>
@@ -38,7 +38,7 @@
               </object>
             </child>
             <child>
-              <object class="GtkGrid" id="top_box">
+              <object class="GtkGrid" id="cuisines_box">
                 <property name="visible">1</property>
                 <property name="halign">center</property>
                 <property name="column-spacing">20</property>
@@ -51,6 +51,76 @@
               </object>
             </child>
             <child>
+              <object class="GtkRevealer" id="cuisines_more">
+                <property name="visible">1</property>
+                <property name="transition-type">slide-up</property>
+                <property name="margin-top">10</property>
+                <child>
+                  <object class="GtkFlowBox" id="cuisines_box2">
+                    <property name="visible">1</property>
+                    <property name="margin-top">10</property>
+                    <property name="margin-bottom">10</property>
+                    <property name="row-spacing">20</property>
+                    <property name="column-spacing">20</property>
+                    <property name="homogeneous">1</property>
+                    <property name="min-children-per-line">3</property>
+                    <property name="max-children-per-line">3</property>
+                    <property name="selection-mode">none</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">1</property>
+                <property name="margin-start">24</property>
+                <property name="margin-end">24</property>
+                <property name="margin-bottom">12</property>
+                <child>
+                  <object class="GtkSeparator">
+                    <property name="visible">1</property>
+                    <property name="expand">1</property>
+                    <property name="valign">center</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkButton">
+                    <property name="visible">1</property>
+                    <property name="can-focus">1</property>
+                    <property name="margin-start">9</property>
+                    <property name="margin-end">9</property>
+                    <property name="valign">center</property>
+                    <property name="relief">none</property>
+                    <signal name="clicked" handler="cuisines_expander_button_clicked" swapped="yes"/>
+                    <style>
+                      <class name="image-cutton"/>
+                      <class name="circular"/>
+                    </style>
+                    <child>
+                      <object class="GtkImage" id="cuisines_expander_image">
+                        <property name="visible">1</property>
+                        <property name="icon-name">pan-down-symbolic</property>
+                        <property name="icon-size">1</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSeparator">
+                    <property name="visible">1</property>
+                    <property name="expand">1</property>
+                    <property name="valign">center</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+            <child>
               <object class="GtkLabel" id="seasonal_label">
                 <property name="visible">1</property>
                 <property name="label" translatable="yes">Seasonal</property>


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