From d26899770c97be774832b69c8e427cd57d2ab5ad Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Mon, 22 Nov 2021 22:24:06 +0100 Subject: [PATCH] Improving the manga list view to avoid images going out of the expected size. --- src/view/list_view_manga.c | 2 +- src/view/picture.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/view/list_view_manga.c b/src/view/list_view_manga.c index 829ec38..5349a46 100644 --- a/src/view/list_view_manga.c +++ b/src/view/list_view_manga.c @@ -55,7 +55,7 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory, GtkWidget *label = gtk_label_new (manga_title); GtkWidget *picture = GTK_WIDGET ( - create_picture_from_url (image_url, 200)); + create_picture_from_url (image_url, 100)); gtk_box_append (box, picture); gtk_box_append (box, label); diff --git a/src/view/picture.c b/src/view/picture.c index fa93a5d..aaa7015 100644 --- a/src/view/picture.c +++ b/src/view/picture.c @@ -6,11 +6,14 @@ #include GtkPicture * -create_picture_from_url (char *url, gint picture_height) { +create_picture_from_url (const char *const url, gint picture_size) { GtkPicture *picture = NULL; GFileIOStream *iostream; GFile *tmp_image; GError *error = NULL; + GdkTexture *texture; + + printf("%s\n", url); size_t size_downloaded_image = 0; char *downloaded_image; @@ -31,8 +34,15 @@ create_picture_from_url (char *url, gint picture_height) { g_clear_error (&error); goto cleanup_create_picture_from_url; } - picture = GTK_PICTURE (gtk_picture_new_for_file (tmp_image)); - g_object_set_property_int (G_OBJECT(picture), "height-request", picture_height); + texture = gdk_texture_new_from_file (tmp_image, &error); + if (error) { + fprintf (stderr, "Texture malformed."); + goto cleanup_create_picture_from_url; + } + picture = GTK_PICTURE (gtk_picture_new_for_paintable (GDK_PAINTABLE (texture))); + g_object_set_property_int (G_OBJECT(picture), "height-request", picture_size); + g_object_set_property_int (G_OBJECT(picture), "width-request", picture_size); + g_object_set_property_int (G_OBJECT(picture), "margin-end", 5); cleanup_create_picture_from_url: g_free (downloaded_image);