[gnome-todo] widget: Don't depend on custom GTK APIs



commit 91352939939ff6692b85039290674a2f8540a68b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Sep 25 16:18:13 2020 -0300

    widget: Don't depend on custom GTK APIs
    
    Instead, use child widgets to make up for it.

 build-aux/flatpak/adjusted-allocation.patch | 77 -----------------------------
 build-aux/flatpak/org.gnome.Todo.json       |  4 --
 src/animation/gtd-timeline.c                |  4 +-
 src/gui/gtd-bin-layout.c                    | 11 +----
 src/gui/gtd-max-size-layout.c               | 10 +++-
 src/gui/gtd-widget-private.h                | 29 -----------
 src/gui/gtd-widget.c                        | 54 +++-----------------
 tests/interactive/test-animation.c          | 56 +++++++++++++--------
 8 files changed, 56 insertions(+), 189 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.Todo.json b/build-aux/flatpak/org.gnome.Todo.json
index b99a127..303c15f 100644
--- a/build-aux/flatpak/org.gnome.Todo.json
+++ b/build-aux/flatpak/org.gnome.Todo.json
@@ -200,10 +200,6 @@
                 {
                     "type": "git",
                     "url": "https://gitlab.gnome.org/GNOME/gtk.git";
-                },
-                {
-                    "type": "patch",
-                    "path": "adjusted-allocation.patch"
                 }
             ]
         },
diff --git a/src/animation/gtd-timeline.c b/src/animation/gtd-timeline.c
index e3c6428..f41cc7b 100644
--- a/src/animation/gtd-timeline.c
+++ b/src/animation/gtd-timeline.c
@@ -1809,8 +1809,8 @@ struct CollectMarkersClosure
 };
 
 static void
-collect_markers (const gchar *key,
-                 TimelineMarker *marker,
+collect_markers (const gchar                  *key,
+                 TimelineMarker               *marker,
                  struct CollectMarkersClosure *data)
 {
   guint msecs;
diff --git a/src/gui/gtd-bin-layout.c b/src/gui/gtd-bin-layout.c
index 0534639..7f081eb 100644
--- a/src/gui/gtd-bin-layout.c
+++ b/src/gui/gtd-bin-layout.c
@@ -19,7 +19,7 @@
  */
 
 #include "gtd-bin-layout.h"
-#include "gtd-widget-private.h"
+#include "gtd-widget.h"
 
 struct _GtdBinLayout
 {
@@ -84,14 +84,7 @@ gtd_bin_layout_allocate (GtkLayoutManager *layout_manager,
           GskTransform *transform = NULL;
 
           if (GTD_IS_WIDGET (child))
-            {
-              GtkAllocation adjusted;
-
-              gtk_widget_get_adjusted_allocation (child, width, height, &adjusted);
-              gtd_widget_update_pivot_for_geometry (GTD_WIDGET (child), &adjusted);
-
-              transform = gtd_widget_apply_transform (GTD_WIDGET (child), NULL);
-            }
+            transform = gtd_widget_apply_transform (GTD_WIDGET (child), NULL);
 
           gtk_widget_allocate (child, width, height, baseline, transform);
         }
diff --git a/src/gui/gtd-max-size-layout.c b/src/gui/gtd-max-size-layout.c
index 169bce9..391b08f 100644
--- a/src/gui/gtd-max-size-layout.c
+++ b/src/gui/gtd-max-size-layout.c
@@ -19,6 +19,7 @@
  */
 
 #include "gtd-max-size-layout.h"
+#include "gtd-widget.h"
 
 struct _GtdMaxSizeLayout
 {
@@ -148,7 +149,14 @@ gtd_max_size_layout_allocate (GtkLayoutManager *layout_manager,
        child = gtk_widget_get_next_sibling (child))
     {
       if (child && gtk_widget_should_layout (child))
-        gtk_widget_allocate (child, width, height, baseline, NULL);
+        {
+          GskTransform *transform = NULL;
+
+          if (GTD_IS_WIDGET (child))
+            transform = gtd_widget_apply_transform (GTD_WIDGET (child), NULL);
+
+          gtk_widget_allocate (child, width, height, baseline, transform);
+        }
     }
 }
 
diff --git a/src/gui/gtd-widget.c b/src/gui/gtd-widget.c
index 6b3334b..63917bd 100644
--- a/src/gui/gtd-widget.c
+++ b/src/gui/gtd-widget.c
@@ -25,7 +25,6 @@
 #include "gtd-interval.h"
 #include "gtd-timeline-private.h"
 #include "gtd-property-transition.h"
-#include "gtd-widget-private.h"
 
 #include <graphene-gobject.h>
 #include <gobject/gvaluecollector.h>
@@ -57,7 +56,6 @@ typedef struct
   gfloat              scale[3];
   graphene_point3d_t  translation;
 
-  GtkAllocation       geometry;
   GskTransform       *cached_transform;
 } GtdWidgetPrivate;
 
@@ -342,30 +340,6 @@ create_transition (GtdWidget  *self,
       gtd_timeline_set_duration (timeline, priv->animation.current_state->easing_duration);
       gtd_timeline_set_progress_mode (timeline, priv->animation.current_state->easing_mode);
 
-#ifdef GTD_ENABLE_DEBUG
-      if (GTD_HAS_DEBUG (ANIMATION))
-        {
-          gchar *initial_v, *final_v;
-
-          initial_v = g_strdup_value_contents (&initial);
-          final_v = g_strdup_value_contents (&final);
-
-          GTD_TRACE_MSG ("[animation] "
-                         "Created transition for %p:%s "
-                         "(len:%u, mode:%s, delay:%u) "
-                         "initial:%s, final:%s",
-                         self,
-                         pspec->name,
-                         priv->animation.current_state->easing_duration,
-                         gtd_get_easing_name_for_mode (priv->animation.current_state->easing_mode),
-                         priv->animation.current_state->easing_delay,
-                         initial_v, final_v);
-
-          g_free (initial_v);
-          g_free (final_v);
-        }
-#endif /* GTD_ENABLE_DEBUG */
-
       /* this will start the transition as well */
       add_transition_to_widget (self, pspec->name, res);
 
@@ -421,20 +395,23 @@ calculate_transform (GtdWidget *self)
   graphene_point3d_t pivot;
   GskTransform *transform;
   gboolean pivot_is_zero;
+  gint height;
+  gint width;
 
   transform = NULL;
+  width = gtk_widget_get_width (GTK_WIDGET (self));
+  height = gtk_widget_get_height (GTK_WIDGET (self));
 
   /* Pivot point */
   pivot_is_zero = graphene_point3d_equal (&priv->pivot_point, graphene_point3d_zero ());
-  pivot = GRAPHENE_POINT3D_INIT (priv->geometry.x + priv->geometry.width * priv->pivot_point.x,
-                                 priv->geometry.y + priv->geometry.height * priv->pivot_point.y,
+  pivot = GRAPHENE_POINT3D_INIT (width * priv->pivot_point.x,
+                                 height * priv->pivot_point.y,
                                  priv->pivot_point.z);
   if (!pivot_is_zero)
     transform = gsk_transform_translate_3d (transform, &pivot);
 
   /* Perspective */
-  transform = gsk_transform_perspective (transform,
-                                         2 * MAX (priv->geometry.width, priv->geometry.height));
+  transform = gsk_transform_perspective (transform, 2 * MAX (width, height));
 
   /* Translation */
   if (G_APPROX_VALUE (priv->translation.z, 0.f, FLT_EPSILON))
@@ -1262,22 +1239,6 @@ gtd_widget_apply_transform (GtdWidget    *self,
   return gsk_transform_transform (transform, priv->cached_transform);
 }
 
-void
-gtd_widget_update_pivot_for_geometry (GtdWidget           *self,
-                                      const GtkAllocation *geometry)
-{
-  GtdWidgetPrivate *priv = gtd_widget_get_instance_private (self);
-
-  if (priv->geometry.x != geometry->x ||
-      priv->geometry.y != geometry->y ||
-      priv->geometry.width != geometry->width ||
-      priv->geometry.height != geometry->height)
-    {
-      invalidate_cached_transform (self);
-      priv->geometry = *geometry;
-    }
-}
-
 /**
  * gtd_widget_add_transition:
  * @self: a #GtdWidget
@@ -1707,4 +1668,3 @@ gtd_widget_restore_easing_state (GtdWidget *self)
       priv->animation.current_state = NULL;
     }
 }
-
diff --git a/tests/interactive/test-animation.c b/tests/interactive/test-animation.c
index 1fd2253..011497d 100644
--- a/tests/interactive/test-animation.c
+++ b/tests/interactive/test-animation.c
@@ -51,43 +51,59 @@ static const char *ui =
 "          <object class='GtdWidget'>"
 "            <property name='hexpand'>true</property>"
 "            <child>"
-"              <object class='GtdWidget' id='translated'>"
-"                <property name='css-name'>translated</property>"
+"              <object class='GtdWidget'>"
 "                <property name='halign'>center</property>"
 "                <property name='valign'>center</property>"
-"                <property name='width-request'>30</property>"
-"                <property name='height-request'>30</property>"
+"                <child>"
+"                  <object class='GtdWidget' id='translated'>"
+"                    <property name='css-name'>translated</property>"
+"                    <property name='width-request'>30</property>"
+"                    <property name='height-request'>30</property>"
+"                  </object>"
+"                </child>"
 "              </object>"
 "            </child>"
 "            <child>"
-"              <object class='GtdWidget' id='wiggler'>"
-"                <property name='css-name'>wiggler</property>"
-"                <property name='translation-y'>40</property>"
+"              <object class='GtdWidget'>"
 "                <property name='halign'>center</property>"
 "                <property name='valign'>start</property>"
-"                <property name='width-request'>300</property>"
-"                <property name='height-request'>40</property>"
+"                <child>"
+"                  <object class='GtdWidget' id='wiggler'>"
+"                    <property name='css-name'>wiggler</property>"
+"                    <property name='translation-y'>40</property>"
+"                    <property name='width-request'>300</property>"
+"                    <property name='height-request'>40</property>"
+"                  </object>"
+"                </child>"
 "              </object>"
 "            </child>"
 "            <child>"
-"              <object class='GtdWidget' id='rotated'>"
-"                <property name='css-name'>rotated</property>"
-"                <property name='translation-y'>-80</property>"
+"              <object class='GtdWidget'>"
 "                <property name='halign'>center</property>"
 "                <property name='valign'>end</property>"
-"                <property name='width-request'>40</property>"
-"                <property name='height-request'>40</property>"
+"                <child>"
+"                  <object class='GtdWidget' id='rotated'>"
+"                    <property name='css-name'>rotated</property>"
+"                    <property name='translation-y'>-80</property>"
+"                    <property name='width-request'>40</property>"
+"                    <property name='height-request'>40</property>"
+"                  </object>"
+"                </child>"
 "              </object>"
 "            </child>"
 "            <child>"
-"              <object class='GtdWidget' id='mover'>"
-"                <property name='css-name'>mover</property>"
-"                <property name='translation-x'>-200</property>"
-"                <property name='translation-y'>-40</property>"
+"              <object class='GtdWidget'>"
 "                <property name='halign'>center</property>"
 "                <property name='valign'>end</property>"
-"                <property name='width-request'>50</property>"
-"                <property name='height-request'>50</property>"
+"                <child>"
+"                  <object class='GtdWidget' id='mover'>"
+"                    <property name='css-name'>mover</property>"
+"                    <property name='translation-x'>-200</property>"
+"                    <property name='translation-y'>-40</property>"
+"                    <property name='width-request'>50</property>"
+"                    <property name='height-request'>50</property>"
+"                  </object>"
+"                </child>"
 "              </object>"
 "            </child>"
 "          </object>"


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