[mutter/gbsneto/more-clutter-api: 1/3] clutter/content: Add clutter_content_invalidate_size()



commit 8093f973c8ed386f0fa07dbbb82020f6cee9007b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Dec 26 23:17:29 2018 -0200

    clutter/content: Add clutter_content_invalidate_size()
    
    ClutterContent has the ability to dictate the layout of any
    given actor, through the CLUTTER_REQUEST_CONTENT_SIZE request
    mode.
    
    However, there is no way for ClutterContent implementations
    to notify their attached actors that the content size changed.
    
    Add a new optional ClutterContent.invalidate_size() vfunc and
    clutter_content_invalidate_size().

 clutter/clutter/clutter-content.c | 48 +++++++++++++++++++++++++++++++++++++++
 clutter/clutter/clutter-content.h |  5 ++++
 2 files changed, 53 insertions(+)
---
diff --git a/clutter/clutter/clutter-content.c b/clutter/clutter/clutter-content.c
index 35419305e..5db6788b8 100644
--- a/clutter/clutter/clutter-content.c
+++ b/clutter/clutter/clutter-content.c
@@ -91,6 +91,11 @@ clutter_content_real_invalidate (ClutterContent *content)
 {
 }
 
+static void
+clutter_content_real_invalidate_size (ClutterContent *content)
+{
+}
+
 static void
 clutter_content_real_paint_content (ClutterContent   *content,
                                     ClutterActor     *actor,
@@ -108,6 +113,7 @@ clutter_content_default_init (ClutterContentInterface *iface)
   iface->attached = clutter_content_real_attached;
   iface->detached = clutter_content_real_detached;
   iface->invalidate = clutter_content_real_invalidate;
+  iface->invalidate_size = clutter_content_real_invalidate_size;
 
   /**
    * ClutterContent::attached:
@@ -188,6 +194,48 @@ clutter_content_invalidate (ClutterContent *content)
     }
 }
 
+/**
+ * clutter_content_invalidate_size:
+ * @content: a #ClutterContent
+ *
+ * Signals that @content's size changed. Attached actors with request mode
+ * set to %CLUTTER_REQUEST_CONTENT_SIZE will have a relayout queued.
+ *
+ * Attached actors with other request modes are not redrawn. To redraw them
+ * too, use clutter_content_invalidate().
+ */
+void
+clutter_content_invalidate_size (ClutterContent *content)
+{
+  GHashTable *actors;
+  GHashTableIter iter;
+  gpointer key_p, value_p;
+
+  g_return_if_fail (CLUTTER_IS_CONTENT (content));
+
+  CLUTTER_CONTENT_GET_IFACE (content)->invalidate_size (content);
+
+  actors = g_object_get_qdata (G_OBJECT (content), quark_content_actors);
+  if (actors == NULL)
+    return;
+
+  g_hash_table_iter_init (&iter, actors);
+  while (g_hash_table_iter_next (&iter, &key_p, &value_p))
+    {
+      ClutterRequestMode request_mode;
+      ClutterActor *actor = key_p;
+
+      g_assert (actor != NULL);
+
+      request_mode = clutter_actor_get_request_mode (actor);
+
+      if (request_mode != CLUTTER_REQUEST_CONTENT_SIZE)
+        continue;
+
+      clutter_actor_queue_relayout (actor);
+    }
+}
+
 /*< private >
  * _clutter_content_attached:
  * @content: a #ClutterContent
diff --git a/clutter/clutter/clutter-content.h b/clutter/clutter/clutter-content.h
index 69836d5a1..0b676f6e3 100644
--- a/clutter/clutter/clutter-content.h
+++ b/clutter/clutter/clutter-content.h
@@ -86,6 +86,8 @@ struct _ClutterContentIface
                                          ClutterActor     *actor);
 
   void          (* invalidate)          (ClutterContent   *content);
+
+  void          (* invalidate_size)     (ClutterContent   *content);
 };
 
 CLUTTER_EXPORT
@@ -98,6 +100,9 @@ gboolean        clutter_content_get_preferred_size      (ClutterContent *content
 CLUTTER_EXPORT
 void            clutter_content_invalidate              (ClutterContent *content);
 
+CLUTTER_EXPORT
+void            clutter_content_invalidate_size         (ClutterContent *content);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_CONTENT_H__ */


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