[gnome-software/1205-reviews-ratings-are-rounded-to-integer-stars] Apply review suggestions



commit d26466414292a8a3d7c0a2f0d362ef57172041da
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jun 4 12:25:24 2021 +0200

    Apply review suggestions

 src/gs-review-histogram.ui | 90 ++++++++--------------------------------------
 src/gs-star-image.c        | 39 +++++++++++++++-----
 src/gs-star-image.h        | 17 +--------
 src/gs-star-widget.c       |  1 -
 src/gtk-style-hc.css       |  8 +----
 src/gtk-style.css          |  8 +----
 6 files changed, 48 insertions(+), 115 deletions(-)
---
diff --git a/src/gs-review-histogram.ui b/src/gs-review-histogram.ui
index 11d4c6bff..8c52a018c 100644
--- a/src/gs-review-histogram.ui
+++ b/src/gs-review-histogram.ui
@@ -48,53 +48,33 @@
             <property name="hexpand">True</property>
             <property name="vexpand">True</property>
             <child>
-              <object class="GtkImage" id="star5_1">
+              <object class="GsStarImage" id="star5_1">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star5_2">
+              <object class="GsStarImage" id="star5_2">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star5_3">
+              <object class="GsStarImage" id="star5_3">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star5_4">
+              <object class="GsStarImage" id="star5_4">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star5_5">
+              <object class="GsStarImage" id="star5_5">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
           </object>
@@ -144,43 +124,27 @@
             <property name="hexpand">True</property>
             <property name="vexpand">True</property>
             <child>
-              <object class="GtkImage" id="star4_1">
+              <object class="GsStarImage" id="star4_1">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star4_2">
+              <object class="GsStarImage" id="star4_2">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star4_3">
+              <object class="GsStarImage" id="star4_3">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star4_4">
+              <object class="GsStarImage" id="star4_4">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
           </object>
@@ -230,33 +194,21 @@
             <property name="hexpand">True</property>
             <property name="vexpand">True</property>
             <child>
-              <object class="GtkImage" id="star3_1">
+              <object class="GsStarImage" id="star3_1">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star3_2">
+              <object class="GsStarImage" id="star3_2">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star3_3">
+              <object class="GsStarImage" id="star3_3">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
           </object>
@@ -306,23 +258,15 @@
             <property name="hexpand">True</property>
             <property name="vexpand">True</property>
             <child>
-              <object class="GtkImage" id="star2_1">
+              <object class="GsStarImage" id="star2_1">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
             <child>
-              <object class="GtkImage" id="star2_2">
+              <object class="GsStarImage" id="star2_2">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
           </object>
@@ -372,13 +316,9 @@
             <property name="hexpand">True</property>
             <property name="vexpand">True</property>
             <child>
-              <object class="GtkImage" id="star1_1">
+              <object class="GsStarImage" id="star1_1">
                 <property name="visible">True</property>
-                <property name="icon_name">starred-symbolic</property>
                 <property name="sensitive">False</property>
-                <style>
-                  <class name="star-disabled"/>
-                </style>
               </object>
             </child>
           </object>
diff --git a/src/gs-star-image.c b/src/gs-star-image.c
index 4cbaa2734..9fb7fa846 100644
--- a/src/gs-star-image.c
+++ b/src/gs-star-image.c
@@ -4,15 +4,32 @@
  * SPDX-License-Identifier: GPL-2.0+
  */
 
+/**
+ * SECTION:gs-star-image
+ * @title: GsStarImage
+ * @stability: Unstable
+ * @short_description: Draw a star image, which can be partially filled
+ *
+ * Depending on the %GsStarImage::fraction property, the star image can be
+ * drawn as filled only partially or fully or not at all. This is accomplished
+ * by using a `color` style property for the filled part and a
+ * %GsStarImage::star-bg style property for the unfilled part of the star.
+ *
+ * Since: 41
+ */
+
 #include "config.h"
 
 #include "gs-star-image.h"
 
-struct _GsStarImagePrivate {
+struct _GsStarImage
+{
+       GtkWidget parent_instance;
+
        gdouble fraction;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GsStarImage, gs_star_image, GTK_TYPE_WIDGET)
+G_DEFINE_TYPE (GsStarImage, gs_star_image, GTK_TYPE_WIDGET)
 
 enum {
        PROP_FRACTION = 1
@@ -26,6 +43,10 @@ gs_star_image_outline_star (cairo_t *cr,
                            gint *out_min_x,
                            gint *out_max_x)
 {
+       /* Coordinates of the vertices of the star,
+        * where (0, 0) is the centre of the star.
+        * These range from -1 to +1 in both dimensions,
+        * and will be scaled to @radius when drawn. */
        const struct _points {
                gdouble x, y;
        } points[] = {
@@ -148,8 +169,7 @@ gs_star_image_draw (GtkWidget *widget,
                cairo_fill (cr);
                cairo_restore (cr);
 
-               if (star_bg)
-                       gdk_rgba_free (star_bg);
+               g_clear_pointer (&star_bg, gdk_rgba_free);
        }
 
        return FALSE;
@@ -178,13 +198,14 @@ gs_star_image_class_init (GsStarImageClass *klass)
                                         g_param_spec_boxed ("star-bg", NULL, NULL,
                                                             GDK_TYPE_RGBA,
                                                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+       gtk_widget_class_set_css_name (widget_class, "star-image");
 }
 
 static void
 gs_star_image_init (GsStarImage *self)
 {
-       self->priv = gs_star_image_get_instance_private (self);
-       self->priv->fraction = 1.0;
+       self->fraction = 1.0;
 
        gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
        gtk_widget_set_size_request (GTK_WIDGET (self), 16, 16);
@@ -202,10 +223,10 @@ gs_star_image_set_fraction (GsStarImage *self,
 {
        g_return_if_fail (GS_IS_STAR_IMAGE (self));
 
-       if (self->priv->fraction == fraction)
+       if (self->fraction == fraction)
                return;
 
-       self->priv->fraction = fraction;
+       self->fraction = fraction;
 
        g_object_notify (G_OBJECT (self), "fraction");
 
@@ -217,5 +238,5 @@ gs_star_image_get_fraction (GsStarImage *self)
 {
        g_return_val_if_fail (GS_IS_STAR_IMAGE (self), -1.0);
 
-       return self->priv->fraction;
+       return self->fraction;
 }
diff --git a/src/gs-star-image.h b/src/gs-star-image.h
index b3c6d04a5..f1f99fea0 100644
--- a/src/gs-star-image.h
+++ b/src/gs-star-image.h
@@ -11,24 +11,9 @@
 G_BEGIN_DECLS
 
 #define GS_TYPE_STAR_IMAGE             (gs_star_image_get_type ())
-#define GS_STAR_IMAGE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GS_TYPE_STAR_IMAGE, GsStarImage))
-#define GS_STAR_IMAGE_CLASS(obj)       (G_TYPE_CHECK_CLASS_CAST ((obj), GS_TYPE_STAR_IMAGE,  
GsStarImageClass))
-#define GS_IS_STAR_IMAGE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GS_TYPE_STAR_IMAGE))
-#define GS_IS_STAR_IMAGE_CLASS(obj)    (G_TYPE_CHECK_CLASS_TYPE ((obj), GS_TYPE_STAR_IMAGE))
-#define GS_STAR_IMAGE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GS_TYPE_STAR_IMAGE, 
GsStarImageClass))
 
-typedef struct _GsStarImagePrivate GsStarImagePrivate;
+G_DECLARE_FINAL_TYPE (GsStarImage, gs_star_image, GS, STAR_IMAGE, GtkWidget)
 
-typedef struct _GsStarImageClass {
-       GtkWidgetClass parent_class;
-} GsStarImageClass;
-
-typedef struct _GsStarImage {
-       GtkWidget parent;
-       GsStarImagePrivate *priv;
-} GsStarImage;
-
-GType          gs_star_image_get_type          (void) G_GNUC_CONST;
 GtkWidget *    gs_star_image_new               (void);
 void           gs_star_image_set_fraction      (GsStarImage *self,
                                                 gdouble fraction);
diff --git a/src/gs-star-widget.c b/src/gs-star-widget.c
index 560c40e19..60747dfe7 100644
--- a/src/gs-star-widget.c
+++ b/src/gs-star-widget.c
@@ -128,7 +128,6 @@ gs_star_widget_refresh (GsStarWidget *star)
                /* create image */
                im = gs_star_image_new ();
                gtk_widget_set_size_request (im, (gint) priv->icon_size, (gint) priv->icon_size);
-               gtk_style_context_add_class (gtk_widget_get_style_context (im), "star-enabled");
 
                priv->images[i] = im;
 
diff --git a/src/gtk-style-hc.css b/src/gtk-style-hc.css
index b82514005..e6d65bedc 100644
--- a/src/gtk-style-hc.css
+++ b/src/gtk-style-hc.css
@@ -211,13 +211,7 @@ button.star, .button.star {
 }
 
 /* for the review dialog */
-.star-enabled,
-.star-enabled:disabled {
-       color: #000000;
-       -GsStarImage-star-bg: #777777;
-}
-.star-disabled,
-.star-disabled:disabled {
+star-image {
        color: #000000;
        -GsStarImage-star-bg: #777777;
 }
diff --git a/src/gtk-style.css b/src/gtk-style.css
index fd5ed63d3..00d63691a 100644
--- a/src/gtk-style.css
+++ b/src/gtk-style.css
@@ -484,13 +484,7 @@ flowboxchild {
 }
 
 /* for the review dialog */
-.star-enabled,
-.star-enabled:disabled {
-       color: #e5a50a;
-       -GsStarImage-star-bg: #deddda;
-}
-.star-disabled,
-.star-disabled:disabled {
+star-image {
        color: #e5a50a;
        -GsStarImage-star-bg: #deddda;
 }


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