[gnome-usage] color-rectangle: Use property & constructor



commit 12849cde8637166da8c5a755d415692a0d654f86
Author: Petr Štětka <pstetka redhat com>
Date:   Fri Aug 18 11:28:07 2017 +0200

    color-rectangle: Use property & constructor
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781542

 src/color-rectangle.vala |   47 +++++++++++++++++++++++----------------------
 src/storage-row.vala     |    8 +++---
 2 files changed, 28 insertions(+), 27 deletions(-)
---
diff --git a/src/color-rectangle.vala b/src/color-rectangle.vala
index 79d31a3..f1812cc 100644
--- a/src/color-rectangle.vala
+++ b/src/color-rectangle.vala
@@ -24,39 +24,22 @@ namespace Usage {
 
     public class ColorRectangle : Gtk.DrawingArea
     {
-        Gdk.RGBA color;
+        public Gdk.RGBA color { get; set; }
+
         class construct
         {
             set_css_name("ColorRectangle");
         }
 
-        public Gdk.RGBA get_color()
-        {
-            return color;
-        }
-
-        public ColorRectangle.new_from_rgba(Gdk.RGBA color)
-        {
-            this.color = color;
-            init();
-        }
-
-        public ColorRectangle.new_from_css(string css_class)
-        {
-            get_style_context().add_class(css_class);
-            color = get_style_context().get_color(get_style_context().get_state());
-            init();
-        }
-
-        private void init()
+        construct
         {
             this.height_request = 17;
             this.width_request = 17;
             this.valign = Gtk.Align.CENTER;
             this.draw.connect ((context) =>
             {
-               int height = this.get_allocated_height ();
-               int width = this.get_allocated_width ();
+                int height = this.get_allocated_height ();
+                int width = this.get_allocated_width ();
 
                 double degrees = Math.PI / 180.0;
                 double x = 0;
@@ -72,8 +55,26 @@ namespace Usage {
 
                 Gdk.cairo_set_source_rgba (context, color);
                 context.fill();
-               return true;
+                return true;
             });
         }
+
+        public ColorRectangle.new_from_rgba(Gdk.RGBA color)
+        {
+            this.color = color;
+            queue_draw_area(0, 0, this.get_allocated_width(), this.get_allocated_height());
+        }
+
+        public ColorRectangle.new_from_css(string css_class)
+        {
+            set_color_from_css(css_class);
+        }
+
+        public void set_color_from_css(string css_class)
+        {
+            get_style_context().add_class(css_class);
+            color = get_style_context().get_color(get_style_context().get_state());
+            queue_draw_area(0, 0, this.get_allocated_width(), this.get_allocated_height());
+        }
     }
 }
diff --git a/src/storage-row.vala b/src/storage-row.vala
index 3aa4a89..adeed3c 100644
--- a/src/storage-row.vala
+++ b/src/storage-row.vala
@@ -59,22 +59,22 @@ namespace Usage
             {
                 case StorageItemType.SYSTEM:
                     icon = new ColorRectangle.new_from_css("system");
-                    color = ((ColorRectangle) icon).get_color();
+                    color = (icon as ColorRectangle).color;
                     selectable = false;
                     break;
                 case StorageItemType.TRASH:
                     check_button = new Gtk.CheckButton();
                     icon = new ColorRectangle.new_from_css("trash");
-                    color = ((ColorRectangle) icon).get_color();
+                    color = (icon as ColorRectangle).color;
                     break;
                 case StorageItemType.USER:
                     check_button = new Gtk.CheckButton();
                     icon = new ColorRectangle.new_from_css("user");
-                    color = ((ColorRectangle) icon).get_color();
+                    color = (icon as ColorRectangle).color;
                     break;
                 case StorageItemType.AVAILABLE:
                     icon = new ColorRectangle.new_from_css("available-storage");
-                    color = ((ColorRectangle) icon).get_color();
+                    color = (icon as ColorRectangle).color;
                     selectable = false;
                     break;
                 case StorageItemType.STORAGE:


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