[gnome-mines/arnaudb/wip/gtk4: 37/39] Adapt to Container API, again.




commit 6e2fcee4abf45d6e101d99cb43b6f3b082d4625f
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Sep 9 16:10:03 2020 +0200

    Adapt to Container API, again.

 src/minefield-view.vala | 44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/src/minefield-view.vala b/src/minefield-view.vala
index c895217..a01c245 100644
--- a/src/minefield-view.vala
+++ b/src/minefield-view.vala
@@ -146,18 +146,16 @@ public class MinefieldView : Gtk.Widget
     private Gtk.Grid grid;
     private Gtk.BinLayout layout;
 
-    construct
+    private bool first_init_done = false;
+    private void init_grid ()
     {
-        init_keyboard ();
-
-        hexpand = true;
-        vexpand = true;
-
-        layout = new Gtk.BinLayout ();
-        set_layout_manager (layout);
-
-        frame = new Gtk.AspectFrame (/* xalign */ 0.5f, /* yalign */ 0.5f, /* ratio */ 1.0f, /* obey-child 
*/ false);
-        frame.insert_after (this, /* insert first */ null);
+        if (first_init_done)
+        {
+            frame.set_child (null);
+            grid.destroy ();
+        }
+        else
+            first_init_done = true;
 
         grid = new Gtk.Grid ();
         frame.set_child (grid);
@@ -171,6 +169,22 @@ public class MinefieldView : Gtk.Widget
         grid.hexpand = true;
         grid.vexpand = true;
         grid.add_css_class ("minefield");
+    }
+
+    construct
+    {
+        init_keyboard ();
+
+        hexpand = true;
+        vexpand = true;
+
+        layout = new Gtk.BinLayout ();
+        set_layout_manager (layout);
+
+        frame = new Gtk.AspectFrame (/* xalign */ 0.5f, /* yalign */ 0.5f, /* ratio */ 1.0f, /* obey-child 
*/ false);
+        frame.insert_after (this, /* insert first */ null);
+
+        init_grid ();
 
         selected = new Position ();
         selected.set_x.connect ((x) => { return x; });
@@ -187,12 +201,6 @@ public class MinefieldView : Gtk.Widget
         this.settings = settings;
     }
 
-    protected override void destroy ()
-    {
-        frame.destroy ();
-        base.destroy ();
-    }
-
     private Minefield _minefield;
     public Minefield minefield
     {
@@ -209,7 +217,7 @@ public class MinefieldView : Gtk.Widget
             remove_css_class ("explodedField");
             remove_css_class ("completedField");
             mines = new Tile[_minefield.width, _minefield.height];
-            grid.forall ((child) => { grid.remove (child); });
+            init_grid ();
             for (int i = 0; i < _minefield.width; i++)
             {
                 for (int j = 0; j < _minefield.height; j++)


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