[libgnome-games-support: 6/13] gridframe: Port GtkBin to GtkWidget




commit 19fa30d7a49dfdb552b2ac4b50325d6a93ee4b2d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu May 7 09:52:25 2020 +0200

    gridframe: Port GtkBin to GtkWidget
    
    We do not need to invalidate_rect in size_allocate.

 games/gridframe.vala | 50 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)
---
diff --git a/games/gridframe.vala b/games/gridframe.vala
index 1580bcf..8ede601 100644
--- a/games/gridframe.vala
+++ b/games/gridframe.vala
@@ -24,7 +24,7 @@
 
 namespace Games {
 
-public class GridFrame : Gtk.Bin
+public class GridFrame : Gtk.Widget
 {
     private int _xpadding = 0;
     public int xpadding
@@ -110,6 +110,23 @@ public class GridFrame : Gtk.Bin
         }
     }
 
+    private Gtk.Widget _child = null;
+    public Gtk.Widget child {
+        get { return _child; }
+
+        set
+        {
+            if (_child == value)
+                return;
+            if (_child != null)
+                _child.unparent ();
+            _child = value;
+            if (_child != null)
+                _child.set_parent (this);
+            queue_resize ();
+        }
+    }
+
     private Gtk.Allocation old_allocation;
 
     public GridFrame (int width, int height)
@@ -117,6 +134,13 @@ public class GridFrame : Gtk.Bin
         Object (width: width, height: height);
     }
 
+    protected override void dispose () {
+        child.unparent ();
+        child = null;
+
+        base.dispose ();
+    }
+
     public new void @set (int width, int height)
     {
         this.width = width;
@@ -135,32 +159,22 @@ public class GridFrame : Gtk.Bin
         this.yalign = yalign;
     }
 
-    public override void size_allocate (Gtk.Allocation allocation)
+    public override void size_allocate (int width, int height, int baseline)
     {
-        base.size_allocate (allocation);
+        base.size_allocate (width, height, baseline);
 
-        int xsize = int.max (1, (allocation.width - _xpadding) / _xmult);
-        int ysize = int.max (1, (allocation.height - _ypadding) / _ymult);
+        int xsize = int.max (1, (width - _xpadding) / _xmult);
+        int ysize = int.max (1, (height - _ypadding) / _ymult);
         int size = int.min (xsize, ysize);
 
         Gtk.Allocation child_allocation = { 0, 0, 0, 0 };
         child_allocation.width = size * _xmult + _xpadding;
         child_allocation.height = size * _ymult + _ypadding;
-        child_allocation.x = (int) ((allocation.width - child_allocation.width) * _xalign + allocation.x);
-        child_allocation.y = (int) ((allocation.height - child_allocation.height) * _yalign + allocation.y);
-
-        if (get_mapped () &&
-            (child_allocation.x != old_allocation.x ||
-             child_allocation.y != old_allocation.y ||
-             child_allocation.width != old_allocation.width ||
-             child_allocation.height != old_allocation.height))
-        {
-            get_window ().invalidate_rect (allocation, false);
-        }
+        child_allocation.x = (int) ((width - child_allocation.width) * _xalign);
+        child_allocation.y = (int) ((height - child_allocation.height) * _yalign);
 
-        Gtk.Widget child = get_child ();
         if (child != null && child.get_visible ())
-            child.size_allocate (child_allocation);
+            child.allocate_size (child_allocation, -1);
 
         old_allocation = child_allocation;
     }


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