[gnome-shell/wip/gdm-shell: 2/16] st-box-layout: Add methods for fetching sibling actors



commit 5d441f77e727fd333a691bc5e548abf99b738541
Author: Ray Strode <rstrode redhat com>
Date:   Fri Aug 19 13:48:20 2011 -0400

    st-box-layout: Add methods for fetching sibling actors
    
    StBoxLayout currently lets its callers add actors relative
    to other actors in the layout with st_box_layout_insert_actor()
    and st_box_layout_insert_before().
    
    There isn't currently any way to query the adjacent siblings of
    actors already in the list, however.
    
    This commit adds two functions:
    
    st_box_layout_get_actor_before()
    and
    st_box_layout_get_actor_after()
    
    that return the actors respectively before and after a given
    child.

 src/st/st-box-layout.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/st/st-box-layout.h |    5 ++++
 2 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/src/st/st-box-layout.c b/src/st/st-box-layout.c
index 453a3c2..9668f13 100644
--- a/src/st/st-box-layout.c
+++ b/src/st/st-box-layout.c
@@ -1246,3 +1246,57 @@ st_box_layout_insert_before (StBoxLayout  *self,
   clutter_container_add_actor(CLUTTER_CONTAINER (self), actor);
   st_container_move_before (ST_CONTAINER (self), actor, sibling);
 }
+
+/**
+ * st_box_layout_get_actor_before:
+ * @self: A #StBoxLayout
+ * @actor: A previously added #ClutterActor
+ *
+ * Get the actor before @actor in the box layout.
+ *
+ * Returns: (transfer full): the requested #ClutterActor or %NULL if
+ * @actor is the first child in @self.
+ */
+ClutterActor *
+st_box_layout_get_actor_before (StBoxLayout  *self,
+                                ClutterActor *actor)
+{
+  GList *children, *actor_item;
+
+  children = st_container_get_children_list (ST_CONTAINER (self));
+  actor_item = g_list_find (children, actor);
+
+  g_return_val_if_fail (actor_item != NULL, NULL);
+
+  if (actor_item->prev == NULL)
+    return NULL;
+
+  return CLUTTER_ACTOR (g_object_ref (actor_item->prev->data));
+}
+
+/**
+ * st_box_layout_get_actor_after:
+ * @self: A #StBoxLayout
+ * @actor: A previously added #ClutterActor
+ *
+ * Get the actor actor @actor in the box layout.
+ *
+ * Returns: (transfer full): the requested #ClutterActor or %NULL if
+ * @actor is the last child in @self.
+ */
+ClutterActor *
+st_box_layout_get_actor_after  (StBoxLayout  *self,
+                                ClutterActor *actor)
+{
+  GList *children, *actor_item;
+
+  children = st_container_get_children_list (ST_CONTAINER (self));
+  actor_item = g_list_find (children, actor);
+
+  g_return_val_if_fail (actor_item != NULL, NULL);
+
+  if (actor_item->next == NULL)
+    return NULL;
+
+  return CLUTTER_ACTOR (g_object_ref (actor_item->next->data));
+}
diff --git a/src/st/st-box-layout.h b/src/st/st-box-layout.h
index f19a065..b802b58 100644
--- a/src/st/st-box-layout.h
+++ b/src/st/st-box-layout.h
@@ -94,6 +94,11 @@ void     st_box_layout_insert_before (StBoxLayout  *self,
                                       ClutterActor *actor,
                                       ClutterActor *sibling);
 
+ClutterActor *st_box_layout_get_actor_before (StBoxLayout  *self,
+                                              ClutterActor *actor);
+ClutterActor *st_box_layout_get_actor_after  (StBoxLayout  *self,
+                                              ClutterActor *actor);
+
 G_END_DECLS
 
 #endif /* _ST_BOX_LAYOUT_H */



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