[gnome-control-center/wip/jsparber/background: 13/45] background: resize thumbnail to fill space a row



commit cae001f380c0e09aa23c8ab160b14ebdbe0894ef
Author: Julian Sparber <julian sparber net>
Date:   Sat Nov 11 21:33:07 2017 +0100

    background: resize thumbnail to fill space a row
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788515

 panels/background/background.ui         |    5 ++-
 panels/background/cc-background-panel.c |   32 ++++++++++++++++++++++++------
 2 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/panels/background/background.ui b/panels/background/background.ui
index db3793c..5166954 100644
--- a/panels/background/background.ui
+++ b/panels/background/background.ui
@@ -138,11 +138,12 @@
                   <object class="GtkFlowBox" id="background-gallery">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-
-        <property name="expand">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">False</property>
                     <property name="homogeneous">True</property>
                     <property name="orientation">horizontal</property>
                     <property name="min-children-per-line">2</property>
+                    <property name="max-children-per-line">1000</property>
                     <property name="row_spacing">5</property>
                     <property name="column_spacing">5</property>
                     <property name="halign">fill</property>
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index bb9d0bb..c1e1154 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -335,16 +335,32 @@ on_gallery_item_draw (GtkWidget         *widget,
                       cairo_t           *cr,
                       GdkPixbuf *pixbuf)
 {
-  const gint width = gtk_widget_get_allocated_width (gtk_widget_get_parent (widget));
-  const gint height = gtk_widget_get_allocated_height (gtk_widget_get_parent (widget));
+  const gint space_width = gtk_widget_get_allocated_width (widget);
+  const gint space_height = gtk_widget_get_allocated_height ( (widget));
+  //g_print ("Parent name %s\n", gtk_widget_get_name (gtk_widget_get_parent (widget)));
+
+  const gint pixbuf_width = gdk_pixbuf_get_width (pixbuf);
+  const gint pixbuf_height = gdk_pixbuf_get_height (pixbuf);
+
+  gint new_width;
+  gint new_height;
+  if (space_width * 9/16 > space_height) {
+    new_width = space_width;
+    new_height = space_width * 9/16;
+  }
+  else {
+    new_width = space_height * 16/9;
+    new_height = space_height;
+  }
 
   pixbuf = gdk_pixbuf_scale_simple (pixbuf,
-                                    width,
-                                    height,
+                                    new_width,
+                                    new_height,
                                     GDK_INTERP_BILINEAR);
+
   gdk_cairo_set_source_pixbuf (cr,
                                pixbuf,
-                               0, 0);
+                               -(new_width - space_width)/2, -(new_height - space_height)/2);
   cairo_paint (cr);
 
   return TRUE;
@@ -894,8 +910,8 @@ create_gallery_item (gpointer item,
   GdkPixbuf *pixbuf;
   CcBackgroundItem *self = item;
   gint scale_factor;
-  const gint preview_width = 400;//panel->gallery_size;//309;
-  const gint preview_height = 400 * 9 / 16; //panel->gallery_size * 9/16;//168;
+  const gint preview_width = 800;//panel->gallery_size;//309;
+  const gint preview_height = 800 * 9 / 16; //panel->gallery_size * 9/16;//168;
 
   scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (panel));
 
@@ -918,6 +934,8 @@ create_gallery_item (gpointer item,
                     G_CALLBACK (on_gallery_item_draw), pixbuf);
 
   flow = cc_background_grid_item_new(self);
+
+  gtk_widget_set_size_request (flow, 200, 150);
   cc_background_grid_item_set_ref (flow, self);
   gtk_widget_show (flow);
   gtk_widget_show (widget);


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