[gtk/constraint-guide-2: 4/5] constraint guide: Add more private api



commit d4f6ad74ddf5286785d274cd389e2d821698029e
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jun 27 22:06:19 2019 +0000

    constraint guide: Add more private api
    
    This lets us avoid exposing the struct.

 gtk/gtkconstraintguide.c        | 52 +++++++++++++++++++++++++++++++++++++++++
 gtk/gtkconstraintguideprivate.h | 37 ++++++-----------------------
 gtk/gtkconstraintlayout.c       | 29 ++++++-----------------
 3 files changed, 66 insertions(+), 52 deletions(-)
---
diff --git a/gtk/gtkconstraintguide.c b/gtk/gtkconstraintguide.c
index 24a7286746..7856e20b96 100644
--- a/gtk/gtkconstraintguide.c
+++ b/gtk/gtkconstraintguide.c
@@ -31,6 +31,35 @@
 #include "gtkprivate.h"
 
 
+typedef enum {
+  GUIDE_MIN_WIDTH,
+  GUIDE_MIN_HEIGHT,
+  GUIDE_NAT_WIDTH,
+  GUIDE_NAT_HEIGHT,
+  GUIDE_MAX_WIDTH,
+  GUIDE_MAX_HEIGHT,
+  LAST_GUIDE_VALUE
+} GuideValue;
+
+struct _GtkConstraintGuide
+{ 
+  GObject parent_instance;
+
+  int values[LAST_GUIDE_VALUE];
+
+  GtkConstraintLayout *layout;
+
+  /* HashTable<static string, Variable>; a hash table of variables,
+   * one for each attribute; we use these to query and suggest the
+   * values for the solver. The string is static and does not need
+   * to be freed.
+   */
+  GHashTable *bound_attributes;
+
+  GtkConstraintRef *constraints[LAST_GUIDE_VALUE];
+};
+
+
 struct _GtkConstraintGuideClass {
   GObjectClass parent_class;
 };
@@ -146,6 +175,29 @@ gtk_constraint_guide_detach (GtkConstraintGuide *guide)
   g_hash_table_remove_all (guide->bound_attributes);
 }
 
+GtkConstraintVariable *
+gtk_constraint_guide_get_attribute (GtkConstraintGuide     *guide,
+                                    GtkConstraintAttribute  attr)
+{
+  GtkLayoutManager *manager = GTK_LAYOUT_MANAGER (guide->layout);
+  GtkWidget *widget = gtk_layout_manager_get_widget (manager);
+
+  return gtk_constraint_layout_get_attribute (guide->layout, attr, "guide", widget, guide->bound_attributes);
+}
+
+GtkConstraintLayout *
+gtk_constraint_guide_get_layout (GtkConstraintGuide *guide)
+{
+  return guide->layout;
+}
+
+void
+gtk_constraint_guide_set_layout (GtkConstraintGuide  *guide,
+                                 GtkConstraintLayout *layout)
+{
+  guide->layout = layout;
+}
+
 static void
 gtk_constraint_guide_set_property (GObject      *gobject,
                                    guint         prop_id,
diff --git a/gtk/gtkconstraintguideprivate.h b/gtk/gtkconstraintguideprivate.h
index ad6d5cef76..69c7e5f2c4 100644
--- a/gtk/gtkconstraintguideprivate.h
+++ b/gtk/gtkconstraintguideprivate.h
@@ -25,37 +25,14 @@
 
 G_BEGIN_DECLS
 
-typedef enum {
-  GUIDE_MIN_WIDTH,
-  GUIDE_MIN_HEIGHT,
-  GUIDE_NAT_WIDTH,
-  GUIDE_NAT_HEIGHT,
-  GUIDE_MAX_WIDTH,
-  GUIDE_MAX_HEIGHT,
-  LAST_GUIDE_VALUE
-} GuideValue;
+void                   gtk_constraint_guide_update        (GtkConstraintGuide     *guide);
+void                   gtk_constraint_guide_detach        (GtkConstraintGuide     *guide);
 
-struct _GtkConstraintGuide
-{
-  GObject parent_instance;
-
-  int values[LAST_GUIDE_VALUE];
-
-  GtkConstraintLayout *layout;
-
-  /* HashTable<static string, Variable>; a hash table of variables,
-   * one for each attribute; we use these to query and suggest the
-   * values for the solver. The string is static and does not need
-   * to be freed.
-   */
-  GHashTable *bound_attributes;
-
-  GtkConstraintRef *constraints[LAST_GUIDE_VALUE];
-};
-
-void gtk_constraint_guide_update (GtkConstraintGuide *guide,
-                                  GuideValue          index);
-void gtk_constraint_guide_detach (GtkConstraintGuide *guide);
+GtkConstraintVariable *gtk_constraint_guide_get_attribute (GtkConstraintGuide      *guide,
+                                                           GtkConstraintAttribute  attr);
 
+GtkConstraintLayout   *gtk_constraint_guide_get_layout    (GtkConstraintGuide     *guide);
+void                   gtk_constraint_guide_set_layout    (GtkConstraintGuide     *guide,
+                                                           GtkConstraintLayout    *layout);
 
 G_END_DECLS
diff --git a/gtk/gtkconstraintlayout.c b/gtk/gtkconstraintlayout.c
index f4a4d81d27..0fb24ee5dd 100644
--- a/gtk/gtkconstraintlayout.c
+++ b/gtk/gtkconstraintlayout.c
@@ -354,17 +354,6 @@ get_child_attribute (GtkConstraintLayout    *layout,
   return gtk_constraint_layout_get_attribute (layout, attr, prefix, widget, child_info->bound_attributes);
 }
 
-static GtkConstraintVariable *
-get_guide_attribute (GtkConstraintLayout    *layout,
-                     GtkConstraintGuide     *guide,
-                     GtkConstraintAttribute  attr)
-{
-  GtkLayoutManager *manager = GTK_LAYOUT_MANAGER (layout);
-  GtkWidget *widget = gtk_layout_manager_get_widget (manager);
-
-  return gtk_constraint_layout_get_attribute (layout, attr, "guide", widget, guide->bound_attributes);
-}
-
 static void
 gtk_constraint_layout_child_finalize (GObject *gobject)
 {
@@ -629,7 +618,7 @@ layout_add_constraint (GtkConstraintLayout *self,
       GtkConstraintGuide *guide;
 
       guide = (GtkConstraintGuide*)g_hash_table_lookup (self->guides, target);
-      target_attr = get_guide_attribute (self, guide, attr);
+      target_attr = gtk_constraint_guide_get_attribute (guide, attr);
     }
   else
     {
@@ -664,7 +653,7 @@ layout_add_constraint (GtkConstraintLayout *self,
           GtkConstraintGuide *guide;
 
           guide = (GtkConstraintGuide*)g_hash_table_lookup (self->guides, source);
-          source_attr = get_guide_attribute (self, guide, attr);
+          source_attr = gtk_constraint_guide_get_attribute (guide, attr);
         }
       else
         {
@@ -1034,10 +1023,7 @@ gtk_constraint_layout_root (GtkLayoutManager *manager)
   while (g_hash_table_iter_next (&iter, &key, NULL))
     {
       GtkConstraintGuide *guide = key;
-      gtk_constraint_guide_update (guide, GUIDE_MIN_WIDTH);
-      gtk_constraint_guide_update (guide, GUIDE_MIN_HEIGHT);
-      gtk_constraint_guide_update (guide, GUIDE_NAT_WIDTH);
-      gtk_constraint_guide_update (guide, GUIDE_NAT_HEIGHT);
+      gtk_constraint_guide_update (guide);
     }
 }
 
@@ -1191,10 +1177,9 @@ gtk_constraint_layout_add_guide (GtkConstraintLayout *layout,
 {
   g_return_if_fail (GTK_IS_CONSTRAINT_LAYOUT (layout));
   g_return_if_fail (GTK_IS_CONSTRAINT_GUIDE (guide));
-  g_return_if_fail (guide->layout == NULL);
-
-  guide->layout = layout;
+  g_return_if_fail (gtk_constraint_guide_get_layout (guide) == NULL);
 
+  gtk_constraint_guide_set_layout (guide, layout);
   g_hash_table_add (layout->guides, guide);
 
   gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (layout));
@@ -1214,11 +1199,11 @@ gtk_constraint_layout_remove_guide (GtkConstraintLayout *layout,
 {
   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);
+  g_return_if_fail (gtk_constraint_guide_get_layout (guide) == layout);
 
   gtk_constraint_guide_detach (guide);
-  guide->layout = NULL;
 
+  gtk_constraint_guide_set_layout (guide, NULL);
   g_hash_table_remove (layout->guides, guide);
 
   gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (layout));


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