[gtk/constraint-guide-3: 2/7] Detach guides on unroot



commit 7beca2a33aba2ee883ecb9757b3924b61bd177a2
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jun 27 18:49:54 2019 +0000

    Detach guides on unroot
    
    We don't want to leave constraints behind.

 gtk/gtkconstraintlayout.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkconstraintlayout.c b/gtk/gtkconstraintlayout.c
index 897cfb31e5..13cfad8c78 100644
--- a/gtk/gtkconstraintlayout.c
+++ b/gtk/gtkconstraintlayout.c
@@ -1064,6 +1064,7 @@ gtk_constraint_layout_allocate (GtkLayoutManager *manager,
 
 static void gtk_constraint_guide_update (GtkConstraintGuide *guide,
                                          GuideValue          index);
+static void gtk_constraint_guide_detach (GtkConstraintGuide *guide);
 
 static void
 gtk_constraint_layout_root (GtkLayoutManager *manager)
@@ -1116,6 +1117,13 @@ gtk_constraint_layout_unroot (GtkLayoutManager *manager)
       gtk_constraint_detach (constraint);
     }
 
+  g_hash_table_iter_init (&iter, self->guides);
+  while (g_hash_table_iter_next (&iter, &key, NULL))
+    {
+      GtkConstraintGuide *guide = key;
+      gtk_constraint_guide_detach (guide);
+    }
+
   self->solver = NULL;
 }
 
@@ -1300,6 +1308,28 @@ gtk_constraint_guide_update (GtkConstraintGuide *guide,
                                           weight[index]);
 }
 
+static void
+gtk_constraint_guide_detach (GtkConstraintGuide *guide)
+{
+  GtkConstraintSolver *solver;
+  int i;
+
+  if (!guide->layout)
+    return;
+
+  solver = guide->layout->solver;
+  if (!solver)
+    return;
+
+  for (i = 0; i < LAST_GUIDE_VALUE; i++)
+    {
+      gtk_constraint_solver_remove_constraint (solver, guide->constraints[i]);
+      guide->constraints[i] = NULL;
+    }
+
+  g_hash_table_remove_all (guide->data.bound_attributes);
+}
+
 static void
 gtk_constraint_guide_set_property (GObject      *gobject,
                                    guint         prop_id,
@@ -1450,14 +1480,11 @@ void
 gtk_constraint_layout_remove_guide (GtkConstraintLayout *layout,
                                     GtkConstraintGuide  *guide)
 {
-  GtkConstraintSolver *solver;
-
   g_return_if_fail (GTK_IS_CONSTRAINT_LAYOUT (layout));
   g_return_if_fail (GTK_IS_CONSTRAINT_GUIDE (guide));
   g_return_if_fail (guide->layout == layout);
 
-  solver = gtk_constraint_layout_get_solver (guide->layout);
-  clear_constraint_solver_data (solver, &guide->data);
+  gtk_constraint_guide_detach (guide);
   guide->layout = NULL;
 
   g_hash_table_remove (layout->guides, guide);


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