[libhandy/wip/haecker-felix/flap-widget] Refactor it again
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/wip/haecker-felix/flap-widget] Refactor it again
- Date: Thu, 19 Nov 2020 10:41:36 +0000 (UTC)
commit 2b15492b6ff4174e8d5ddc4ee8121e0ac9df7bf7
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Thu Nov 19 00:48:05 2020 +0500
Refactor it again
Fix a few bugs and reduce the number of lerps.
src/hdy-flap.c | 199 +++++++++++++++++++++++++--------------------------------
1 file changed, 88 insertions(+), 111 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index f81545bf..038761bd 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -335,22 +335,6 @@ compute_sizes (HdyFlap *self,
return;
}
- if (!revealed || folded) {
- gboolean expand = gtk_widget_compute_expand (self->flap, self->orientation);
-
- if (expand)
- *flap_size = total;
- else if (revealed)
- get_preferred_size (self->flap, self->orientation, NULL, flap_size);
- else
- get_preferred_size (self->flap, self->orientation, flap_size, NULL);
-
- *flap_size = MIN (*flap_size, total);
- *content_size = total;
-
- return;
- }
-
if (!self->content) {
*content_size = 0;
*flap_size = total;
@@ -364,9 +348,26 @@ compute_sizes (HdyFlap *self,
flap_expand = gtk_widget_compute_expand (self->flap, self->orientation);
content_expand = gtk_widget_compute_expand (self->content, self->orientation);
+ if (folded) {
+ *content_size = total;
+
+ if (flap_expand) {
+ *flap_size = total;
+ } else {
+ get_preferred_size (self->flap, self->orientation, NULL, flap_size);
+ *flap_size = MIN (*flap_size, total);
+ }
+
+ return;
+ }
+
if (flap_expand && content_expand) {
*flap_size = MAX (total / 2, *flap_size);
- *content_size = total - *flap_size;
+
+ if (!revealed)
+ *content_size = total;
+ else
+ *content_size = total - *flap_size;
return;
}
@@ -375,14 +376,17 @@ compute_sizes (HdyFlap *self,
if (flap_expand) {
*flap_size += extra;
+ extra = 0;
+
+ if (!revealed)
+ *content_size = total;
return;
}
if (content_expand) {
*content_size += extra;
-
- return;
+ extra = 0;
}
if (extra > 0) {
@@ -401,13 +405,67 @@ compute_sizes (HdyFlap *self,
*flap_size = sizes[0].minimum_size;
*content_size = sizes[1].minimum_size + extra;
}
+
+ if (!revealed)
+ *content_size = total;
+}
+
+static inline void
+interpolate_reveal (HdyFlap *self,
+ GtkAllocation *alloc,
+ gboolean folded,
+ gint *flap_size,
+ gint *content_size)
+{
+ if (self->reveal_progress <= 0) {
+ compute_sizes (self, alloc, folded, FALSE, flap_size, content_size);
+ } else if (self->reveal_progress >= 1) {
+ compute_sizes (self, alloc, folded, TRUE, flap_size, content_size);
+ } else {
+ gint flap_revealed, content_revealed;
+ gint flap_hidden, content_hidden;
+
+ compute_sizes (self, alloc, folded, TRUE, &flap_revealed, &content_revealed);
+ compute_sizes (self, alloc, folded, FALSE, &flap_hidden, &content_hidden);
+
+ *flap_size =
+ (gint) round (hdy_lerp (flap_hidden, flap_revealed,
+ self->reveal_progress));
+ *content_size =
+ (gint) round (hdy_lerp (content_hidden, content_revealed,
+ self->reveal_progress));
+ }
+}
+
+static inline void
+interpolate_fold (HdyFlap *self,
+ GtkAllocation *alloc,
+ gint *flap_size,
+ gint *content_size)
+{
+ if (self->fold_progress <= 0) {
+ interpolate_reveal (self, alloc, FALSE, flap_size, content_size);
+ } else if (self->fold_progress >= 1) {
+ interpolate_reveal (self, alloc, TRUE, flap_size, content_size);
+ } else {
+ gint flap_folded, content_folded;
+ gint flap_unfolded, content_unfolded;
+
+ interpolate_reveal (self, alloc, TRUE, &flap_folded, &content_folded);
+ interpolate_reveal (self, alloc, FALSE, &flap_unfolded, &content_unfolded);
+
+ *flap_size =
+ (gint) round (hdy_lerp (flap_unfolded, flap_folded,
+ self->fold_progress));
+ *content_size =
+ (gint) round (hdy_lerp (content_unfolded, content_folded,
+ self->fold_progress));
+ }
}
static void
compute_allocation (HdyFlap *self,
GtkAllocation *alloc,
- gboolean folded,
- gboolean revealed,
GtkAllocation *flap_alloc,
GtkAllocation *content_alloc)
{
@@ -420,12 +478,10 @@ compute_allocation (HdyFlap *self,
flap_alloc->y = 0;
if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
- compute_sizes (self, alloc, folded, revealed,
- &flap_alloc->width, &content_alloc->width);
+ interpolate_fold (self, alloc, &flap_alloc->width, &content_alloc->width);
flap_alloc->height = content_alloc->height = alloc->height;
} else {
- compute_sizes (self, alloc, folded, revealed,
- &flap_alloc->height, &content_alloc->height);
+ interpolate_fold (self, alloc, &flap_alloc->height, &content_alloc->height);
flap_alloc->width = content_alloc->width = alloc->width;
}
@@ -434,100 +490,21 @@ compute_allocation (HdyFlap *self,
if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
if (self->flap_position == get_start_or_end (self)) {
- if (!folded && revealed)
- content_alloc->x = flap_alloc->width;
- else if (!revealed)
- flap_alloc->x = -flap_alloc->width;
+ content_alloc->x = alloc->width - content_alloc->width;
+ flap_alloc->x = (self->reveal_progress - 1) * flap_alloc->width;
} else {
- if (!revealed)
- flap_alloc->x = alloc->width;
- else if (folded)
- flap_alloc->x = alloc->width - flap_alloc->width;
- else
- flap_alloc->x = content_alloc->width;
+ flap_alloc->x = alloc->width - self->reveal_progress * flap_alloc->width;
}
} else {
if (self->flap_position == GTK_PACK_START) {
- if (!folded && revealed)
- content_alloc->y = flap_alloc->height;
- else if (!revealed)
- flap_alloc->y = -flap_alloc->height;
+ content_alloc->y = alloc->height - content_alloc->height;
+ flap_alloc->y = (self->reveal_progress - 1) * flap_alloc->height;
} else {
- if (!revealed)
- flap_alloc->y = alloc->height;
- else if (folded)
- flap_alloc->y = alloc->height - flap_alloc->height;
- else
- flap_alloc->y = content_alloc->height;
+ flap_alloc->y = alloc->height - self->reveal_progress * flap_alloc->height;
}
}
}
-static inline void
-interpolate_allocation (GtkAllocation *from,
- GtkAllocation *to,
- gdouble t,
- GtkAllocation *ret)
-{
- ret->x = (gint) round (hdy_lerp (from->x, to->x, t));
- ret->y = (gint) round (hdy_lerp (from->y, to->y, t));
- ret->width = (gint) round (hdy_lerp (from->width, to->width, t));
- ret->height = (gint) round (hdy_lerp (from->height, to->height, t));
-}
-
-static inline void
-interpolate_reveal (HdyFlap *self,
- GtkAllocation *alloc,
- gboolean folded,
- GtkAllocation *flap_alloc,
- GtkAllocation *content_alloc)
-{
- if (self->reveal_progress <= 0) {
- compute_allocation (self, alloc, folded, FALSE,
- flap_alloc, content_alloc);
- } else if (self->reveal_progress >= 1) {
- compute_allocation (self, alloc, folded, TRUE,
- flap_alloc, content_alloc);
- } else {
- GtkAllocation flap_revealed, content_revealed;
- GtkAllocation flap_hidden, content_hidden;
-
- compute_allocation (self, alloc, folded, TRUE,
- &flap_revealed, &content_revealed);
- compute_allocation (self, alloc, folded, FALSE,
- &flap_hidden, &content_hidden);
-
- interpolate_allocation (&flap_hidden, &flap_revealed,
- self->reveal_progress, flap_alloc);
- interpolate_allocation (&content_hidden, &content_revealed,
- self->reveal_progress, content_alloc);
- }
-}
-
-static inline void
-interpolate_fold (HdyFlap *self,
- GtkAllocation *alloc,
- GtkAllocation *flap_alloc,
- GtkAllocation *content_alloc)
-{
- if (self->fold_progress <= 0) {
- interpolate_reveal (self, alloc, FALSE, flap_alloc, content_alloc);
- } else if (self->fold_progress >= 1) {
- interpolate_reveal (self, alloc, TRUE, flap_alloc, content_alloc);
- } else {
- GtkAllocation flap_folded, content_folded;
- GtkAllocation flap_unfolded, content_unfolded;
-
- interpolate_reveal (self, alloc, TRUE, &flap_folded, &content_folded);
- interpolate_reveal (self, alloc, FALSE, &flap_unfolded, &content_unfolded);
-
- interpolate_allocation (&flap_unfolded, &flap_folded,
- self->fold_progress, flap_alloc);
- interpolate_allocation (&content_unfolded, &content_folded,
- self->fold_progress, content_alloc);
- }
-}
-
static void
hdy_flap_size_allocate (GtkWidget *widget,
GtkAllocation *alloc)
@@ -553,7 +530,7 @@ hdy_flap_size_allocate (GtkWidget *widget,
set_folded (self, alloc->height < content_min.height + flap_min.height);
}
- interpolate_fold (self, alloc, &flap_alloc, &content_alloc);
+ compute_allocation (self, alloc, &flap_alloc, &content_alloc);
if (self->content)
gtk_widget_size_allocate (self->content, &content_alloc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]