[gnome-software/gnome-42: 1/3] gs-star-widget: Round fraction to one digit, the same as the GsReviewHistogram does
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-42: 1/3] gs-star-widget: Round fraction to one digit, the same as the GsReviewHistogram does
- Date: Mon, 20 Jun 2022 10:17:14 +0000 (UTC)
commit f02928fee15416d1c2e68cca8f705c90f5098ebc
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]