[gnome-software/1800-reviews-stars-at-the-top-and-bottom-view-doesn-t-match] gs-star-widget: Round fraction to one digit, the same as the GsReviewHistogram does



commit 0e011554a18dffac976fdd061f534b7f9e7377d4
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jun 20 11:05:43 2022 +0200

    gs-star-widget: Round fraction to one digit, the same as the GsReviewHistogram does
    
    That's to show the same fraction in the stars, which could differ when
    rounding up in the histogram.

 src/gs-star-widget.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-star-widget.c b/src/gs-star-widget.c
index ab91a6302..1d4170523 100644
--- a/src/gs-star-widget.c
+++ b/src/gs-star-widget.c
@@ -84,6 +84,9 @@ gs_star_widget_button_clicked_cb (GtkButton *button, GsStarWidget *star)
        g_signal_emit (star, signals[RATING_CHANGED], 0, priv->rating);
 }
 
+/* Round to one digit, the same as the GsReviewHistogram */
+#define GS_ROUND(x) (round (((gdouble) (x)) * 10.0) / 10.0)
+
 /* Update the star styles to display the new rating */
 static void
 gs_star_widget_refresh_rating (GsStarWidget *star)
@@ -100,9 +103,9 @@ gs_star_widget_refresh_rating (GsStarWidget *star)
                if (priv->rating >= rate_to_star[i])
                        fraction = 1.0;
                else if (!i)
-                       fraction = priv->rating / 20.0;
+                       fraction = GS_ROUND (priv->rating / 20.0);
                else if (priv->rating > rate_to_star[i - 1])
-                       fraction = (priv->rating - rate_to_star[i - 1]) / 20.0;
+                       fraction = GS_ROUND ((priv->rating - rate_to_star[i - 1]) / 20.0);
                else
                        fraction = 0.0;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]