diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-03-13 08:11:29 +0100 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-03-13 08:11:29 +0100 |
commit | 88d9244b988146281fc041202f5efcfb2302e86f (patch) | |
tree | 5974d9c0e4967cfc5ca1c50938efb87b3da18dad | |
parent | fb4ae235a5ab83a0b6f6379d78a259b37dcc02d4 (diff) | |
download | gtk+-88d9244b988146281fc041202f5efcfb2302e86f.tar.gz |
gtk4-demo: Fix rotation handling in image scaling
We weren't sizing the widget correctly in rotated
cases.
-rw-r--r-- | demos/gtk-demo/demo3widget.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/demos/gtk-demo/demo3widget.c b/demos/gtk-demo/demo3widget.c index 756cb7565d..6fc935cffd 100644 --- a/demos/gtk-demo/demo3widget.c +++ b/demos/gtk-demo/demo3widget.c @@ -67,15 +67,13 @@ demo3_widget_snapshot (GtkWidget *widget, if (G_APPROX_VALUE (self->angle, 90.f, FLT_EPSILON) || G_APPROX_VALUE (self->angle, 270.f, FLT_EPSILON)) { - double s; - - s = w2; + double s = w2; w2 = h2; h2 = s; } - x = MAX (0, (width - ceil (w2)) / 2); - y = MAX (0, (height - ceil (h2)) / 2); + x = (width - ceil (w2)) / 2; + y = (height - ceil (h2)) / 2; gtk_snapshot_push_clip (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height)); gtk_snapshot_save (snapshot); @@ -102,14 +100,26 @@ demo3_widget_measure (GtkWidget *widget, int *natural_baseline) { Demo3Widget *self = DEMO3_WIDGET (widget); + int width, height; int size; + width = gdk_texture_get_width (self->texture); + height = gdk_texture_get_height (self->texture); + + if (G_APPROX_VALUE (self->angle, 90.f, FLT_EPSILON) || + G_APPROX_VALUE (self->angle, 270.f, FLT_EPSILON)) + { + int s = width; + width = height; + height = s; + } + if (orientation == GTK_ORIENTATION_HORIZONTAL) - size = gdk_texture_get_width (self->texture); + size = width; else - size = gdk_texture_get_height (self->texture); + size = height; - *minimum = *natural = self->scale * size; + *minimum = *natural = (int) ceil (self->scale * size); } static void |