[libhandy] flap: Properly calculate minimum and natural sizes
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] flap: Properly calculate minimum and natural sizes
- Date: Wed, 6 Jan 2021 18:45:35 +0000 (UTC)
commit f686ee3a934c908298f5ab64d5ee2e37e8aaee1b
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Dec 22 14:36:50 2020 +0500
flap: Properly calculate minimum and natural sizes
Currently, we always calculate minimum and natural size the same way. This
technically works, but is incorrect semantically. For example, it means
that flap's natural size changes depending on whether it's currently
folded, while folding state may change depending on the allocated size.
Instead, calculate natural size as follows:
* When the flap is always folded, do the same thing as berore
* When it's never folded, assume natural to be what the flap will be like
when fully revealed
* For the automatic policy, an important distinction is whether the flap is
locked or not. If it's not locked, we can safely assume the size when
unfolded and fully revealed as well, but if it is locked and the flap is
not revealed, we assume that to be the natural size, because the flap
will never be auto-revealed on resizeing, and unlike the never folded
state, revealing the flap will not cause a widget resize either.
Additionally, never account for the separator size for the flap's
orientation. When folded, the separator will end up completely offscreen,
and it's expected and supported situation.
src/hdy-flap.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index d67355e3..8d8f375e 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -1014,12 +1014,31 @@ hdy_flap_measure (GtkWidget *widget,
if (self->separator.widget)
get_preferred_size (self->separator.widget, orientation, &separator_min, &separator_nat);
- if (self->orientation == orientation &&
- self->fold_policy != HDY_FLAP_FOLD_POLICY_AUTO) {
- gdouble progress = (1 - self->fold_progress) * self->reveal_progress;
+ if (self->orientation == orientation) {
+ gdouble min_progress, nat_progress;
+
+ switch (self->fold_policy) {
+ case HDY_FLAP_FOLD_POLICY_NEVER:
+ min_progress = (1 - self->fold_progress) * self->reveal_progress;
+ nat_progress = 1;
+ break;
+
+ case HDY_FLAP_FOLD_POLICY_ALWAYS:
+ min_progress = 0;
+ nat_progress = 0;
+ break;
+
+ case HDY_FLAP_FOLD_POLICY_AUTO:
+ min_progress = 0;
+ nat_progress = self->locked ? self->reveal_progress : 1;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
- min = MAX (content_min + (gint) round ((flap_min + separator_min) * progress), flap_min);
- nat = MAX (content_nat + (gint) round ((flap_nat + separator_nat) * progress), flap_nat);
+ min = MAX (content_min + (gint) round ((flap_min + separator_min) * min_progress), flap_min);
+ nat = MAX (content_nat + (gint) round ((flap_nat + separator_min) * nat_progress), flap_nat);
} else {
min = MAX (MAX (content_min, flap_min), separator_min);
nat = MAX (MAX (content_nat, flap_nat), separator_nat);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]