From a08bc4693670fd34f0a167dc02b28b26b8d7c7b8 Mon Sep 17 00:00:00 2001 From: Marco Melorio Date: Sat, 16 Jul 2022 01:18:07 +0200 Subject: [PATCH 1/3] picture: Fix replacement for deprecated methods --- gtk/gtkpicture.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtk/gtkpicture.h b/gtk/gtkpicture.h index 5d6078071d..4de07d0ba7 100644 --- a/gtk/gtkpicture.h +++ b/gtk/gtkpicture.h @@ -69,10 +69,10 @@ GDK_AVAILABLE_IN_ALL void gtk_picture_set_pixbuf (GtkPicture *self, GdkPixbuf *pixbuf); -GDK_DEPRECATED_IN_4_8_FOR(gtk_picture_set_fit_mode) +GDK_DEPRECATED_IN_4_8_FOR(gtk_picture_set_content_fit) void gtk_picture_set_keep_aspect_ratio (GtkPicture *self, gboolean keep_aspect_ratio); -GDK_DEPRECATED_IN_4_8_FOR(gtk_picture_get_fit_mode) +GDK_DEPRECATED_IN_4_8_FOR(gtk_picture_get_content_fit) gboolean gtk_picture_get_keep_aspect_ratio (GtkPicture *self); GDK_AVAILABLE_IN_ALL void gtk_picture_set_can_shrink (GtkPicture *self, From f1faa71d6d1ab640f3e5aebaaf767cb75b2f28af Mon Sep 17 00:00:00 2001 From: Marco Melorio Date: Sat, 16 Jul 2022 01:31:19 +0200 Subject: [PATCH 2/3] picture: Set overflow to be hidden The new content-fit property was wrongly suggesting to manually set widgets' overflow property, but that property is not really intended to be set by external code. This commit removes those suggestions and directly set picture's overflow to be hidden. --- demos/widget-factory/widget-factory.ui | 1 - gtk/gtkenums.h | 7 +++---- gtk/gtkpicture.c | 7 ++----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index 015ff4c791..7f8c1699d8 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -1266,7 +1266,6 @@ Suspendisse feugiat quam quis dolor accumsan cursus. resource:///org/gtk/WidgetFactory4/sunset.jpg cover - hidden diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h index 44e246fc9e..89d8f5e4a0 100644 --- a/gtk/gtkenums.h +++ b/gtk/gtkenums.h @@ -121,10 +121,9 @@ typedef enum * content will appear as letterboxed if its aspect ratio is different * from the allocation aspect ratio. * @GTK_CONTENT_FIT_COVER: Cover the entire allocation, while taking - * the content aspect ratio in consideration. This can result in an overflow - * if the content aspect ratio is different from the allocation aspect ratio. - * For this reason, you may also want to set [property@Gtk.Widget:overflow] - * to %GTK_OVERFLOW_HIDDEN. + * the content aspect ratio in consideration. The resulting content + * will appear as clipped if its aspect ratio is different from the + * allocation aspect ratio. * @GTK_CONTENT_FIT_SCALE_DOWN: The content is scaled down to fit the * allocation, if needed, otherwise its original size is used. * diff --git a/gtk/gtkpicture.c b/gtk/gtkpicture.c index eaabda7c74..92a177df97 100644 --- a/gtk/gtkpicture.c +++ b/gtk/gtkpicture.c @@ -474,6 +474,8 @@ gtk_picture_init (GtkPicture *self) { self->can_shrink = TRUE; self->content_fit = GTK_CONTENT_FIT_CONTAIN; + + gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN); } /** @@ -972,11 +974,6 @@ gtk_picture_get_can_shrink (GtkPicture *self) * Sets how the content should be resized to fit the `GtkPicture`. * * See [enum@Gtk.ContentFit] for details. - * - * If you use `GTK_CONTENT_FIT_COVER`, you may also want to set the - * [property@Gtk.Widget:overflow] to `GTK_OVERFLOW_HIDDEN`, otherwise the - * paintable will overflow the widget allocation if the aspect ratio of the - * paintable is different from the one of the `GtkPicture` allocation. */ void gtk_picture_set_content_fit (GtkPicture *self, From 3eac4ef5c938f5d0aa381f43ec0168dad41c9372 Mon Sep 17 00:00:00 2001 From: Marco Melorio Date: Sat, 16 Jul 2022 01:37:10 +0200 Subject: [PATCH 3/3] picture: Move variable definition at the top --- gtk/gtkpicture.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gtk/gtkpicture.c b/gtk/gtkpicture.c index 92a177df97..f58966e35d 100644 --- a/gtk/gtkpicture.c +++ b/gtk/gtkpicture.c @@ -979,13 +979,15 @@ void gtk_picture_set_content_fit (GtkPicture *self, GtkContentFit content_fit) { + gboolean notify_keep_aspect_ratio; + g_return_if_fail (GTK_IS_PICTURE (self)); if (self->content_fit == content_fit) return; - gboolean notify_keep_aspect_ratio = (content_fit == GTK_CONTENT_FIT_FILL || - self->content_fit == GTK_CONTENT_FIT_FILL); + notify_keep_aspect_ratio = (content_fit == GTK_CONTENT_FIT_FILL || + self->content_fit == GTK_CONTENT_FIT_FILL); self->content_fit = content_fit;