[gtk/constraint-guide-3] constrainttree: Make each drag a single edit



commit aed7d32cde49acebabf81e6e15f83218db6869b8
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 28 17:09:38 2019 +0000

    constrainttree: Make each drag a single edit
    
    Repeat suggestions work now, so we can implement
    this as it is intended to, and have a single
    edit phase for the entire drag operation.

 tests/constrainttree.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/tests/constrainttree.c b/tests/constrainttree.c
index 44d0238aea..6ce3f3bc6e 100644
--- a/tests/constrainttree.c
+++ b/tests/constrainttree.c
@@ -211,6 +211,14 @@ drag_begin (GtkGestureDrag *drag,
   drag_start_x = start_x;
   drag_start_y = start_y;
   gtk_widget_queue_draw (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (drag)));
+
+  gtk_constraint_solver_add_edit_variable (solver,
+                                           drag_node->x_var,
+                                           GTK_CONSTRAINT_WEIGHT_REQUIRED);
+  gtk_constraint_solver_add_edit_variable (solver,
+                                           drag_node->y_var,
+                                           GTK_CONSTRAINT_WEIGHT_REQUIRED);
+  gtk_constraint_solver_begin_edit (solver);
 }
 
 static void
@@ -235,13 +243,6 @@ drag_update (GtkGestureDrag *drag,
   if (!drag_node)
     return;
 
-  gtk_constraint_solver_add_edit_variable (solver,
-                                           drag_node->x_var,
-                                           GTK_CONSTRAINT_WEIGHT_REQUIRED);
-  gtk_constraint_solver_add_edit_variable (solver,
-                                           drag_node->y_var,
-                                           GTK_CONSTRAINT_WEIGHT_REQUIRED);
-  gtk_constraint_solver_begin_edit (solver);
   gtk_constraint_solver_suggest_value (solver,
                                        drag_node->x_var,
                                        drag_start_x + offset_x);
@@ -252,9 +253,6 @@ drag_update (GtkGestureDrag *drag,
 
   update_tree (tree);
 
-  gtk_constraint_solver_remove_edit_variable (solver, drag_node->x_var);
-  gtk_constraint_solver_remove_edit_variable (solver, drag_node->y_var);
-  gtk_constraint_solver_end_edit (solver);
   gtk_widget_queue_draw (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (drag)));
 }
 
@@ -267,6 +265,9 @@ drag_end (GtkGestureDrag *drag,
   if (!drag_node)
     return;
 
+  gtk_constraint_solver_remove_edit_variable (solver, drag_node->x_var);
+  gtk_constraint_solver_remove_edit_variable (solver, drag_node->y_var);
+  gtk_constraint_solver_end_edit (solver);
 
   drag_node = NULL;
 


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