[libadwaita/libadwaita-1-0] carousel-indicator: Correctly measure animations
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/libadwaita-1-0] carousel-indicator: Correctly measure animations
- Date: Fri, 18 Mar 2022 17:49:16 +0000 (UTC)
commit 9a022c30635b5d12a6a65f401b1ef7342d667890
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Feb 23 08:54:13 2022 +0100
carousel-indicator: Correctly measure animations
This takes the size of the animations into account when measuring the
indicator.
(cherry picked from commit ee898477dd47969acef258a1bd16d7c99bc8f14c)
src/adw-carousel-indicator-dots.c | 24 +++++++++++++++++++++---
src/adw-carousel-indicator-lines.c | 24 +++++++++++++++++++++---
2 files changed, 42 insertions(+), 6 deletions(-)
---
diff --git a/src/adw-carousel-indicator-dots.c b/src/adw-carousel-indicator-dots.c
index 3419284e..0c5e387e 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -191,11 +191,29 @@ adw_carousel_indicator_dots_measure (GtkWidget *widget,
int size = 0;
if (orientation == self->orientation) {
- int n_pages = 0;
+ int i, n_points = 0;
+ double indicator_length, dot_size;
+ double *points, *sizes;
+
if (self->carousel)
- n_pages = adw_carousel_get_n_pages (self->carousel);
+ points = adw_swipeable_get_snap_points (ADW_SWIPEABLE (self->carousel), &n_points);
+
+ sizes = g_new0 (double, n_points);
+
+ if (n_points > 0)
+ sizes[0] = points[0] + 1;
+ for (i = 1; i < n_points; i++)
+ sizes[i] = points[i] - points[i - 1];
+
+ dot_size = 2 * DOTS_RADIUS_SELECTED + DOTS_SPACING;
+ indicator_length = 0;
+ for (i = 0; i < n_points; i++)
+ indicator_length += dot_size * sizes[i];
+
+ size = ceil (indicator_length);
- size = MAX (0, (2 * DOTS_RADIUS_SELECTED + DOTS_SPACING) * n_pages - DOTS_SPACING);
+ g_free (points);
+ g_free (sizes);
} else {
size = 2 * DOTS_RADIUS_SELECTED;
}
diff --git a/src/adw-carousel-indicator-lines.c b/src/adw-carousel-indicator-lines.c
index 7ba3d69c..c8037037 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -176,11 +176,29 @@ adw_carousel_indicator_lines_measure (GtkWidget *widget,
int size = 0;
if (orientation == self->orientation) {
- int n_pages = 0;
+ int i, n_points = 0;
+ double indicator_length, line_size;
+ double *points = NULL, *sizes;
+
if (self->carousel)
- n_pages = adw_carousel_get_n_pages (self->carousel);
+ points = adw_swipeable_get_snap_points (ADW_SWIPEABLE (self->carousel), &n_points);
+
+ sizes = g_new0 (double, n_points);
+
+ if (n_points > 0)
+ sizes[0] = points[0] + 1;
+ for (i = 1; i < n_points; i++)
+ sizes[i] = points[i] - points[i - 1];
+
+ line_size = LINE_LENGTH + LINE_SPACING;
+ indicator_length = 0;
+ for (i = 0; i < n_points; i++)
+ indicator_length += line_size * sizes[i];
+
+ size = ceil (indicator_length);
- size = MAX (0, (LINE_LENGTH + LINE_SPACING) * n_pages - LINE_SPACING);
+ g_free (points);
+ g_free (sizes);
} else {
size = LINE_WIDTH;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]