[clutter] actor: Add [xy]-align



commit c8659b6ca562154734f10338136aa9d148e0c13f
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Nov 21 17:24:03 2011 +0000

    actor: Add [xy]-align
    
    Allow an actor to define how it should occupy the extra space given to
    by its parent during the allocation.

 clutter/clutter-actor.c |  101 +++++++++++++++++++++++++++++++++++++++++++++++
 clutter/clutter-actor.h |    7 +++
 clutter/clutter-enums.h |   27 ++++++++++++
 3 files changed, 135 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c
index b788819..ecf11e9 100644
--- a/clutter/clutter-actor.c
+++ b/clutter/clutter-actor.c
@@ -525,6 +525,8 @@ struct _ClutterActorPrivate
   guint is_dirty                    : 1;
   guint x_expand                    : 1;
   guint y_expand                    : 1;
+  guint x_align                     : 4;
+  guint y_align                     : 4;
 };
 
 enum
@@ -617,6 +619,8 @@ enum
 
   PROP_X_EXPAND,
   PROP_Y_EXPAND,
+  PROP_X_ALIGN,
+  PROP_Y_ALIGN,
 
   PROP_LAST
 };
@@ -3549,6 +3553,14 @@ clutter_actor_set_property (GObject      *object,
       clutter_actor_set_y_expand (actor, g_value_get_boolean (value));
       break;
 
+    case PROP_X_ALIGN:
+      clutter_actor_set_x_align (actor, g_value_get_enum (value));
+      break;
+
+    case PROP_Y_ALIGN:
+      clutter_actor_set_y_align (actor, g_value_get_enum (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -3826,6 +3838,14 @@ clutter_actor_get_property (GObject    *object,
       g_value_set_boolean (value, priv->y_expand);
       break;
 
+    case PROP_X_ALIGN:
+      g_value_set_enum (value, priv->x_align);
+      break;
+
+    case PROP_Y_ALIGN:
+      g_value_set_enum (value, priv->y_align);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -4894,6 +4914,26 @@ clutter_actor_class_init (ClutterActorClass *klass)
   g_object_class_install_property (object_class, PROP_Y_EXPAND,
                                    obj_props[PROP_Y_EXPAND]);
 
+  obj_props[PROP_X_ALIGN] =
+    g_param_spec_enum ("x-align",
+                       P_("X Alignment"),
+                       P_("The alignment of the actor on the X axis within its allocation"),
+                       CLUTTER_TYPE_ACTOR_ALIGN,
+                       CLUTTER_ACTOR_ALIGN_FILL,
+                       CLUTTER_PARAM_READWRITE);
+  g_object_class_install_property (object_class, PROP_X_ALIGN,
+                                   obj_props[PROP_X_ALIGN]);
+
+  obj_props[PROP_Y_ALIGN] =
+    g_param_spec_enum ("y-align",
+                       P_("Y Alignment"),
+                       P_("The alignment of the actor on the Y axis within its allocation"),
+                       CLUTTER_TYPE_ACTOR_ALIGN,
+                       CLUTTER_ACTOR_ALIGN_FILL,
+                       CLUTTER_PARAM_READWRITE);
+  g_object_class_install_property (object_class, PROP_Y_ALIGN,
+                                   obj_props[PROP_Y_ALIGN]);
+
   /**
    * ClutterActor::destroy:
    * @actor: the #ClutterActor which emitted the signal
@@ -5482,6 +5522,11 @@ clutter_actor_init (ClutterActor *self)
   priv->cached_width_age = 1;
   priv->cached_height_age = 1;
 
+  priv->x_expand = FALSE;
+  priv->y_expand = FALSE;
+  priv->x_align = CLUTTER_ACTOR_ALIGN_FILL;
+  priv->y_align = CLUTTER_ACTOR_ALIGN_FILL;
+
   priv->opacity_override = -1;
   priv->enable_model_view_transform = TRUE;
 
@@ -13162,3 +13207,59 @@ clutter_actor_get_y_expand (ClutterActor *self)
 
   return self->priv->y_expand;
 }
+
+void
+clutter_actor_set_x_align (ClutterActor      *self,
+                           ClutterActorAlign  x_align)
+{
+  ClutterActorPrivate *priv;
+
+  g_return_if_fail (CLUTTER_IS_ACTOR (self));
+
+  priv = self->priv;
+
+  if (priv->x_align != x_align)
+    {
+      priv->x_align = x_align;
+
+      clutter_actor_queue_relayout (self);
+
+      g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_X_ALIGN]);
+    }
+}
+
+ClutterActorAlign
+clutter_actor_get_x_align (ClutterActor *self)
+{
+  g_return_val_if_fail (CLUTTER_IS_ACTOR (self), CLUTTER_ACTOR_ALIGN_FILL);
+
+  return self->priv->x_align;
+}
+
+void
+clutter_actor_set_y_align (ClutterActor      *self,
+                           ClutterActorAlign  y_align)
+{
+  ClutterActorPrivate *priv;
+
+  g_return_if_fail (CLUTTER_IS_ACTOR (self));
+
+  priv = self->priv;
+
+  if (priv->y_align != y_align)
+    {
+      priv->y_align = y_align;
+
+      clutter_actor_queue_relayout (self);
+
+      g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_Y_ALIGN]);
+    }
+}
+
+ClutterActorAlign
+clutter_actor_get_y_align (ClutterActor *self)
+{
+  g_return_val_if_fail (CLUTTER_IS_ACTOR (self), CLUTTER_ACTOR_ALIGN_FILL);
+
+  return self->priv->y_align;
+}
diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h
index 21f17ad..19aa8db 100644
--- a/clutter/clutter-actor.h
+++ b/clutter/clutter-actor.h
@@ -374,6 +374,13 @@ void                  clutter_actor_set_y_expand              (ClutterActor
                                                                gboolean               y_expand);
 gboolean              clutter_actor_get_y_expand              (ClutterActor          *self);
 
+void                  clutter_actor_set_x_align               (ClutterActor          *self,
+                                                               ClutterActorAlign      x_align);
+ClutterActorAlign     clutter_actor_get_x_align               (ClutterActor          *self);
+void                  clutter_actor_set_y_align               (ClutterActor          *self,
+                                                               ClutterActorAlign      y_align);
+ClutterActorAlign     clutter_actor_get_y_align               (ClutterActor          *self);
+
 void                  clutter_actor_set_rotation              (ClutterActor          *self,
                                                                ClutterRotateAxis      axis,
                                                                gdouble                angle,
diff --git a/clutter/clutter-enums.h b/clutter/clutter-enums.h
index bf381f6..cbd450e 100644
--- a/clutter/clutter-enums.h
+++ b/clutter/clutter-enums.h
@@ -1056,6 +1056,33 @@ typedef enum {
   CLUTTER_PATH_REL_CURVE_TO = CLUTTER_PATH_CURVE_TO | CLUTTER_PATH_RELATIVE
 } ClutterPathNodeType;
 
+/**
+ * ClutterActorAlign:
+ * @CLUTTER_ACTOR_ALIGN_FILL: Stretch to cover the whole allocated space
+ * @CLUTTER_ACTOR_ALIGN_START: Snap to left or top side, leaving space
+ *   to the right or bottom. For horizontal layouts, in right-to-left
+ *   locales this should be reversed.
+ * @CLUTTER_ACTOR_ALIGN_CENTER: Center the actor inside the allocation
+ * @CLUTTER_ACTOR_ALIGN_END: Snap to right or bottom side, leaving space
+ *   to the left or top. For horizontal layouts, in right-to-left locales
+ *   this should be reversed.
+ *
+ * Controls how a #ClutterActor should align itself inside the extra space
+ * assigned to it during the allocation.
+ *
+ * Alignment only matters if the allocated space given to an actor is
+ * bigger than its natural size; for example, when the #ClutterActor:x-expand
+ * or the #ClutterActor:y-expand properties of #ClutterActor are set to %TRUE.
+ *
+ * Since: 1.10
+ */
+typedef enum {
+  CLUTTER_ACTOR_ALIGN_FILL,
+  CLUTTER_ACTOR_ALIGN_START,
+  CLUTTER_ACTOR_ALIGN_CENTER,
+  CLUTTER_ACTOR_ALIGN_END
+} ClutterActorAlign;
+
 G_END_DECLS
 
 #endif /* __CLUTTER_ENUMS_H__ */



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