[gnome-software/1617-screenshot-spinners-have-bad-layout] gs-screenshot-image: Allocate enough space for a spinner



commit 2d81a0e73732ac65a8dee9c59c1abf02fbeccc43
Author: Milan Crha <mcrha redhat com>
Date:   Fri Feb 25 11:15:24 2022 +0100

    gs-screenshot-image: Allocate enough space for a spinner
    
    When loading and the load takes too long a spinner is shown. Without
    requesting approximate image width the spinners for multiple images
    could be tight beside each other, instead of being spread in the carousel
    in a similar way the images are spread.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1617

 src/gs-screenshot-image.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 94550d9fd..ad00634cc 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -330,6 +330,8 @@ gs_screenshot_image_complete_cb (SoupSession *session,
        if (stream == NULL) {
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
                        g_warning ("Failed to download screenshot: %s", error->message);
+                       /* Reset the width request, thus the image shrinks when the window width is small */
+                       gtk_widget_set_size_request (ssimg->stack, -1, (gint) ssimg->height);
                        gs_screenshot_image_stop_spinner (ssimg);
                        gs_screenshot_image_set_error (ssimg, _("Screenshot not found"));
                }
@@ -354,6 +356,9 @@ gs_screenshot_image_complete_cb (SoupSession *session,
 #endif
                return;
 
+       /* Reset the width request, thus the image shrinks when the window width is small */
+       gtk_widget_set_size_request (ssimg->stack, -1, (gint) ssimg->height);
+
        if (status_code == SOUP_STATUS_NOT_MODIFIED) {
                g_debug ("screenshot has not been modified");
                as_screenshot_show_image (ssimg);
@@ -459,6 +464,7 @@ gs_screenshot_image_set_size (GsScreenshotImage *ssimg,
 
        ssimg->width = width;
        ssimg->height = height;
+       /* Reset the width request, thus the image shrinks when the window width is small */
        gtk_widget_set_size_request (ssimg->stack, -1, (gint) height);
 }
 
@@ -535,6 +541,9 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
        g_return_if_fail (ssimg->width != 0);
        g_return_if_fail (ssimg->height != 0);
 
+       /* Reset the width request, thus the image shrinks when the window width is small */
+       gtk_widget_set_size_request (ssimg->stack, -1, (gint) ssimg->height);
+
        /* load an image according to the scale factor */
        ssimg->scale = (guint) gtk_widget_get_scale_factor (GTK_WIDGET (ssimg));
        im = as_screenshot_get_image (ssimg->screenshot,
@@ -689,6 +698,9 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
                gs_screenshot_soup_msg_set_modified_request (ssimg->message, file);
        }
 
+       /* Make sure the spinner takes approximately the size the screenshot will use */
+       gtk_widget_set_size_request (ssimg->stack, (gint) ssimg->width, (gint) ssimg->height);
+
        ssimg->load_timeout_id = g_timeout_add_seconds (SPINNER_TIMEOUT_SECS,
                gs_screenshot_show_spinner_cb, ssimg);
 


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