summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2020-09-09 15:53:09 +0200
committerBenjamin Otte <otte@redhat.com>2020-09-09 17:38:37 +0200
commitdfccaa8831589576e081c9d6d39a5eff3b80284a (patch)
treee0484206d1ea1ae96b4b0e66f609926da4e11508
parentcc58956dbbe7ba6bb1c1b338678e7708e9b90df8 (diff)
downloadgtk+-dfccaa8831589576e081c9d6d39a5eff3b80284a.tar.gz
revealer: Prefer min and nat size
Assume that the fully expanded revealer will likely get an allocation that matches the child's minimum or natural allocation, so we special-case these two values. So when - due to the precision loss - multiple sizes would match the current allocation, we don't pick one at random, we prefer the min and nat size. The preference of nat size over min sie was decided after an IRC vote, we don't actually have an idea what's more likely to happen in the real world. Should we ever get better data, we might want to switch.
-rw-r--r--gtk/gtkrevealer.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/gtk/gtkrevealer.c b/gtk/gtkrevealer.c
index c6ac90c9ce..ee45854fb4 100644
--- a/gtk/gtkrevealer.c
+++ b/gtk/gtkrevealer.c
@@ -486,18 +486,39 @@ gtk_revealer_size_allocate (GtkWidget *widget,
* that in large downscaling cases we may run into the clipping issue
* described above. However, at these downscaling levels (100 times!)
* we're unlikely to notice much detail anyway.
+ *
+ * On top, we assume that the fully expanded revealer will likely get
+ * an allocation that matches the child's minimum or natural allocation,
+ * so we special-case these two values.
+ * So when - due to the precision loss - multiple sizes would match
+ * the current allocation, we don't pick one at random, we prefer the
+ * min and nat size.
*/
if (hscale < 1.0)
{
+ int min, nat;
g_assert (vscale == 1.0);
- child_width = MIN (100 * width, floor (width / hscale));
+ gtk_widget_measure (priv->child, GTK_ORIENTATION_HORIZONTAL, height, &min, &nat, NULL, NULL);
+ if (ceil (nat * hscale) == width)
+ child_width = nat;
+ else if (ceil (min * hscale) == width)
+ child_width = min;
+ else
+ child_width = MIN (100 * width, floor (width / hscale));
child_height = height;
}
else if (vscale < 1.0)
{
+ int min, nat;
child_width = width;
- child_height = MIN (100 * height, floor (height / vscale));
+ gtk_widget_measure (priv->child, GTK_ORIENTATION_VERTICAL, width, &min, &nat, NULL, NULL);
+ if (ceil (nat * vscale) == height)
+ child_height = nat;
+ else if (ceil (min * vscale) == height)
+ child_height = min;
+ else
+ child_height = MIN (100 * height, floor (height / vscale));
}
else
{