[recipes] Stop using css for recipe tile images



commit ce1502e6ac03c291467eeca808eddad3dba32cdb
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Feb 26 20:41:03 2017 -0500

    Stop using css for recipe tile images
    
    While neat in that it automatically resizes, it has the downside
    that it loads all the big pictures at their original size,
    synchronously. Using GdkPixbuf and GtkImage is more manual
    work and less flexible, but we can now populate a list of
    100 recipe tiles in 6 seconds instead of 30.

 src/gr-recipe-tile.c  |   39 +++++++++++++++++++++++++++-
 src/gr-recipe-tile.h  |    1 +
 src/gr-recipe-tile.ui |   67 +++++++++++++++++++++++++-----------------------
 src/gr-recipes-page.c |    6 +++-
 4 files changed, 78 insertions(+), 35 deletions(-)
---
diff --git a/src/gr-recipe-tile.c b/src/gr-recipe-tile.c
index f03645c..f8863ca 100644
--- a/src/gr-recipe-tile.c
+++ b/src/gr-recipe-tile.c
@@ -36,6 +36,8 @@ struct _GrRecipeTile
 
         GrRecipe *recipe;
 
+        gboolean wide;
+
         GtkWidget *label;
         GtkWidget *author;
         GtkWidget *image;
@@ -66,7 +68,6 @@ add_recipe_css (GrRecipe *recipe,
 
         if (images->len > 0) {
                 GrImage *ri;
-                g_autofree char *path = NULL;
                 int index;
 
                 index = gr_recipe_get_default_image (recipe);
@@ -94,6 +95,7 @@ gr_recipe_tile_recreate_css (void)
         g_autoptr(GString) css = NULL;
         int i;
 
+return;
         store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
         keys = gr_recipe_store_get_recipe_keys (store, &length);
 
@@ -137,6 +139,7 @@ recipe_tile_set_recipe (GrRecipeTile *tile,
                 const char *author;
                 g_autoptr(GrChef) chef = NULL;
                 g_autofree char *tmp = NULL;
+                g_autoptr(GArray) images = NULL;
 
                 elem = gr_recipe_get_id (tile->recipe);
                 gtk_style_context_add_class (gtk_widget_get_style_context (tile->box), elem);
@@ -148,6 +151,26 @@ recipe_tile_set_recipe (GrRecipeTile *tile,
                 gtk_label_set_label (GTK_LABEL (tile->label), name);
                 tmp = g_strdup_printf (_("by %s"), chef ? gr_chef_get_name (chef) : _("Anonymous"));
                 gtk_label_set_label (GTK_LABEL (tile->author), tmp);
+
+                g_object_get (recipe, "images", &images, NULL);
+                if (images->len > 0) {
+                        int index;
+                        GrImage *ri;
+                        g_autoptr(GdkPixbuf) pixbuf = NULL;
+                        int width;
+                        int height;
+
+                        width = tile->wide ? 538 : 258;
+                        height = 200;
+
+                        index = gr_recipe_get_default_image (recipe);
+                        if (index < 0 || index >= images->len)
+                                index = 0;
+
+                        ri = &g_array_index (images, GrImage, index);
+                        pixbuf = load_pixbuf_fill_size (ri->path, width, height);
+                        gtk_image_set_from_pixbuf (GTK_IMAGE (tile->image), pixbuf);
+                }
         }
 }
 
@@ -166,6 +189,7 @@ gr_recipe_tile_init (GrRecipeTile *tile)
 {
         gtk_widget_set_has_window (GTK_WIDGET (tile), FALSE);
         gtk_widget_init_template (GTK_WIDGET (tile));
+        tile->wide = FALSE;
 }
 
 static void
@@ -197,6 +221,19 @@ gr_recipe_tile_new (GrRecipe *recipe)
         return GTK_WIDGET (tile);
 }
 
+GtkWidget *
+gr_recipe_tile_new_wide (GrRecipe *recipe)
+{
+        GrRecipeTile *tile;
+
+        tile = g_object_new (GR_TYPE_RECIPE_TILE, NULL);
+        tile->wide = TRUE;
+
+        recipe_tile_set_recipe (GR_RECIPE_TILE (tile), recipe);
+
+        return GTK_WIDGET (tile);
+}
+
 GrRecipe *
 gr_recipe_tile_get_recipe (GrRecipeTile *tile)
 {
diff --git a/src/gr-recipe-tile.h b/src/gr-recipe-tile.h
index 66c1a29..3a87b75 100644
--- a/src/gr-recipe-tile.h
+++ b/src/gr-recipe-tile.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GrRecipeTile, gr_recipe_tile, GR, RECIPE_TILE, GtkButton)
 
 GtkWidget      *gr_recipe_tile_new        (GrRecipe     *recipe);
+GtkWidget      *gr_recipe_tile_new_wide   (GrRecipe     *recipe);
 GrRecipe       *gr_recipe_tile_get_recipe (GrRecipeTile *tile);
 
 void            gr_recipe_tile_recreate_css (void);
diff --git a/src/gr-recipe-tile.ui b/src/gr-recipe-tile.ui
index 0f0b96e..092697f 100644
--- a/src/gr-recipe-tile.ui
+++ b/src/gr-recipe-tile.ui
@@ -13,49 +13,52 @@
       <object class="GtkEventBox" id="eboxbox">
         <property name="visible">1</property>
         <child>
-          <object class="GtkBox" id="box">
+          <object class="GtkOverlay" id="box">
             <property name="visible">1</property>
-            <property name="orientation">vertical</property>
             <style>
               <class name="recipe"/>
             </style>
             <child>
               <object class="GtkImage" id="image">
-                <property name="width-request">96</property>
-                <property name="height-request">64</property>
                 <property name="visible">1</property>
-                <property name="valign">center</property>
+                <property name="halign">fill</property>
+                <property name="valign">fill</property>
               </object>
-              <packing>
-                <property name="expand">1</property>
-              </packing>
             </child>
-            <child>
-              <object class="GtkLabel" id="label">
-                <property name="visible">1</property>
-                <property name="valign">end</property>
-                <property name="xalign">0</property>
-                <property name="ellipsize">end</property>
-                <property name="width-chars">12</property>
-                <property name="max-width-chars">12</property>
-                <style>
-                  <class name="recipe"/>
-                  <class name="name"/>
-                </style>
-              </object>
-            </child>
-            <child>
-              <object class="GtkLabel" id="author">
+            <child type="overlay">
+              <object class="GtkBox">
                 <property name="visible">1</property>
+                <property name="halign">fill</property>
                 <property name="valign">end</property>
-                <property name="xalign">0</property>
-                <property name="ellipsize">end</property>
-                <property name="width-chars">12</property>
-                <property name="max-width-chars">12</property>
-                <style>
-                  <class name="recipe"/>
-                  <class name="author"/>
-                </style>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkLabel" id="label">
+                    <property name="visible">1</property>
+                    <property name="valign">end</property>
+                    <property name="xalign">0</property>
+                    <property name="ellipsize">end</property>
+                    <property name="width-chars">12</property>
+                    <property name="max-width-chars">12</property>
+                    <style>
+                      <class name="recipe"/>
+                      <class name="name"/>
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="author">
+                    <property name="visible">1</property>
+                    <property name="valign">end</property>
+                    <property name="xalign">0</property>
+                    <property name="ellipsize">end</property>
+                    <property name="width-chars">12</property>
+                    <property name="max-width-chars">12</property>
+                    <style>
+                      <class name="recipe"/>
+                      <class name="author"/>
+                    </style>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
diff --git a/src/gr-recipes-page.c b/src/gr-recipes-page.c
index 8dd1d46..0559160 100644
--- a/src/gr-recipes-page.c
+++ b/src/gr-recipes-page.c
@@ -328,13 +328,15 @@ populate_recipes_from_store (GrRecipesPage *self)
                 recipe = gr_recipe_store_get_recipe (store, keys[i]);
 
                 if (todays < 3 && gr_recipe_store_recipe_is_todays (store, recipe)) {
-                        tile = gr_recipe_tile_new (recipe);
-                        gtk_widget_show (tile);
                         if (todays == 0) {
+                                tile = gr_recipe_tile_new_wide (recipe);
+                                gtk_widget_show (tile);
                                 gtk_grid_attach (GTK_GRID (self->today_box), tile, 0, 0, 2, 1);
                                 todays += 2;
                         }
                         else {
+                                tile = gr_recipe_tile_new (recipe);
+                                gtk_widget_show (tile);
                                 gtk_grid_attach (GTK_GRID (self->today_box), tile, todays, 0, 1, 1);
                                 todays += 1;
                         }


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