clutter/bin-layout: Remove custom alignment properties

The layout manager takes the generic ClutterActor expand/align
properties into account. Everyone should already use those instead
of the custom layout/child properties, so removing them should have
little fallout, while making for a nice cleanup.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3382>
This commit is contained in:
Florian Müllner 2023-11-10 00:24:26 +01:00
parent 84c3a3fbef
commit b611569b26
4 changed files with 10 additions and 414 deletions

View File

@ -58,226 +58,15 @@
#include "clutter/clutter-layout-meta.h" #include "clutter/clutter-layout-meta.h"
#include "clutter/clutter-private.h" #include "clutter/clutter-private.h"
#define CLUTTER_TYPE_BIN_LAYER (clutter_bin_layer_get_type ())
#define CLUTTER_BIN_LAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BIN_LAYER, ClutterBinLayer))
#define CLUTTER_IS_BIN_LAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BIN_LAYER))
typedef struct _ClutterBinLayer ClutterBinLayer;
typedef struct _ClutterLayoutMetaClass ClutterBinLayerClass;
struct _ClutterBinLayoutPrivate struct _ClutterBinLayoutPrivate
{ {
ClutterBinAlignment x_align;
ClutterBinAlignment y_align;
ClutterContainer *container; ClutterContainer *container;
}; };
struct _ClutterBinLayer
{
ClutterLayoutMeta parent_instance;
ClutterBinAlignment x_align;
ClutterBinAlignment y_align;
};
enum
{
PROP_LAYER_0,
PROP_LAYER_X_ALIGN,
PROP_LAYER_Y_ALIGN,
PROP_LAYER_LAST
};
enum
{
PROP_0,
PROP_X_ALIGN,
PROP_Y_ALIGN,
PROP_LAST
};
static GParamSpec *layer_props[PROP_LAYER_LAST] = { NULL, };
static GParamSpec *bin_props[PROP_LAST] = { NULL, };
GType clutter_bin_layer_get_type (void);
G_DEFINE_TYPE (ClutterBinLayer,
clutter_bin_layer,
CLUTTER_TYPE_LAYOUT_META)
G_DEFINE_TYPE_WITH_PRIVATE (ClutterBinLayout, G_DEFINE_TYPE_WITH_PRIVATE (ClutterBinLayout,
clutter_bin_layout, clutter_bin_layout,
CLUTTER_TYPE_LAYOUT_MANAGER) CLUTTER_TYPE_LAYOUT_MANAGER)
/*
* ClutterBinLayer
*/
static void
set_layer_x_align (ClutterBinLayer *self,
ClutterBinAlignment alignment)
{
ClutterLayoutManager *manager;
ClutterLayoutMeta *meta;
if (self->x_align == alignment)
return;
self->x_align = alignment;
meta = CLUTTER_LAYOUT_META (self);
manager = clutter_layout_meta_get_manager (meta);
clutter_layout_manager_layout_changed (manager);
g_object_notify_by_pspec (G_OBJECT (self), layer_props[PROP_LAYER_X_ALIGN]);
}
static void
set_layer_y_align (ClutterBinLayer *self,
ClutterBinAlignment alignment)
{
ClutterLayoutManager *manager;
ClutterLayoutMeta *meta;
if (self->y_align == alignment)
return;
self->y_align = alignment;
meta = CLUTTER_LAYOUT_META (self);
manager = clutter_layout_meta_get_manager (meta);
clutter_layout_manager_layout_changed (manager);
g_object_notify_by_pspec (G_OBJECT (self), layer_props[PROP_LAYER_Y_ALIGN]);
}
static void
clutter_bin_layer_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterBinLayer *layer = CLUTTER_BIN_LAYER (gobject);
switch (prop_id)
{
case PROP_LAYER_X_ALIGN:
set_layer_x_align (layer, g_value_get_enum (value));
break;
case PROP_LAYER_Y_ALIGN:
set_layer_y_align (layer, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
static void
clutter_bin_layer_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterBinLayer *layer = CLUTTER_BIN_LAYER (gobject);
switch (prop_id)
{
case PROP_LAYER_X_ALIGN:
g_value_set_enum (value, layer->x_align);
break;
case PROP_LAYER_Y_ALIGN:
g_value_set_enum (value, layer->y_align);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
static void
clutter_bin_layer_class_init (ClutterBinLayerClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = clutter_bin_layer_set_property;
gobject_class->get_property = clutter_bin_layer_get_property;
layer_props[PROP_LAYER_X_ALIGN] =
g_param_spec_enum ("x-align", NULL, NULL,
CLUTTER_TYPE_BIN_ALIGNMENT,
CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_PARAM_READWRITE);
layer_props[PROP_LAYER_Y_ALIGN] =
g_param_spec_enum ("y-align", NULL, NULL,
CLUTTER_TYPE_BIN_ALIGNMENT,
CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_PARAM_READWRITE);
g_object_class_install_properties (gobject_class,
PROP_LAYER_LAST,
layer_props);
}
static void
clutter_bin_layer_init (ClutterBinLayer *layer)
{
layer->x_align = CLUTTER_BIN_ALIGNMENT_CENTER;
layer->y_align = CLUTTER_BIN_ALIGNMENT_CENTER;
}
/*
* ClutterBinLayout
*/
static void
set_x_align (ClutterBinLayout *self,
ClutterBinAlignment alignment)
{
ClutterBinLayoutPrivate *priv = self->priv;
if (priv->x_align != alignment)
{
ClutterLayoutManager *manager;
priv->x_align = alignment;
manager = CLUTTER_LAYOUT_MANAGER (self);
clutter_layout_manager_layout_changed (manager);
g_object_notify_by_pspec (G_OBJECT (self), bin_props[PROP_X_ALIGN]);
}
}
static void
set_y_align (ClutterBinLayout *self,
ClutterBinAlignment alignment)
{
ClutterBinLayoutPrivate *priv = self->priv;
if (priv->y_align != alignment)
{
ClutterLayoutManager *manager;
priv->y_align = alignment;
manager = CLUTTER_LAYOUT_MANAGER (self);
clutter_layout_manager_layout_changed (manager);
g_object_notify_by_pspec (G_OBJECT (self), bin_props[PROP_Y_ALIGN]);
}
}
static void static void
clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager, clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
ClutterContainer *container, ClutterContainer *container,
@ -352,29 +141,6 @@ clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
*nat_height_p = nat_height; *nat_height_p = nat_height;
} }
static gdouble
get_bin_alignment_factor (ClutterBinAlignment alignment,
ClutterTextDirection text_dir)
{
switch (alignment)
{
case CLUTTER_BIN_ALIGNMENT_CENTER:
return 0.5;
case CLUTTER_BIN_ALIGNMENT_START:
return text_dir == CLUTTER_TEXT_DIRECTION_LTR ? 0.0 : 1.0;
case CLUTTER_BIN_ALIGNMENT_END:
return text_dir == CLUTTER_TEXT_DIRECTION_LTR ? 1.0 : 0.0;
case CLUTTER_BIN_ALIGNMENT_FIXED:
case CLUTTER_BIN_ALIGNMENT_FILL:
return 0.0;
}
return 0.0;
}
static gdouble static gdouble
get_actor_align_factor (ClutterActorAlign alignment) get_actor_align_factor (ClutterActorAlign alignment)
{ {
@ -414,8 +180,6 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
clutter_actor_iter_init (&iter, actor); clutter_actor_iter_init (&iter, actor);
while (clutter_actor_iter_next (&iter, &child)) while (clutter_actor_iter_next (&iter, &child))
{ {
ClutterLayoutMeta *meta;
ClutterBinLayer *layer;
ClutterActorBox child_alloc = { 0, }; ClutterActorBox child_alloc = { 0, };
gdouble x_align, y_align; gdouble x_align, y_align;
gboolean x_fill, y_fill, is_fixed_position_set; gboolean x_fill, y_fill, is_fixed_position_set;
@ -424,11 +188,6 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
if (!clutter_actor_is_visible (child)) if (!clutter_actor_is_visible (child))
continue; continue;
meta = clutter_layout_manager_get_child_meta (manager,
container,
child);
layer = CLUTTER_BIN_LAYER (meta);
fixed_x = fixed_y = 0.f; fixed_x = fixed_y = 0.f;
g_object_get (child, g_object_get (child,
"fixed-position-set", &is_fixed_position_set, "fixed-position-set", &is_fixed_position_set,
@ -436,11 +195,7 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
"fixed-y", &fixed_y, "fixed-y", &fixed_y,
NULL); NULL);
/* XXX:2.0 - remove the FIXED alignment, and just use the fixed position if (is_fixed_position_set)
* of the actor if one is set
*/
if (is_fixed_position_set ||
layer->x_align == CLUTTER_BIN_ALIGNMENT_FIXED)
{ {
if (is_fixed_position_set) if (is_fixed_position_set)
child_alloc.x1 = fixed_x; child_alloc.x1 = fixed_x;
@ -450,8 +205,7 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
else else
child_alloc.x1 = allocation_x; child_alloc.x1 = allocation_x;
if (is_fixed_position_set || if (is_fixed_position_set)
layer->y_align == CLUTTER_BIN_ALIGNMENT_FIXED)
{ {
if (is_fixed_position_set) if (is_fixed_position_set)
child_alloc.y1 = fixed_y; child_alloc.y1 = fixed_y;
@ -474,14 +228,10 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
} }
else else
{ {
ClutterTextDirection text_dir; x_fill = FALSE;
x_fill = (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL);
text_dir = clutter_actor_get_text_direction (child);
if (!is_fixed_position_set) if (!is_fixed_position_set)
x_align = get_bin_alignment_factor (layer->x_align, text_dir); x_align = 0.5;
else else
x_align = 0.0; x_align = 0.0;
} }
@ -496,11 +246,10 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
} }
else else
{ {
y_fill = (layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL); y_fill = FALSE;
if (!is_fixed_position_set) if (!is_fixed_position_set)
y_align = get_bin_alignment_factor (layer->y_align, y_align = 0.5;
CLUTTER_TEXT_DIRECTION_LTR);
else else
y_align = 0.0; y_align = 0.0;
} }
@ -511,30 +260,6 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
} }
} }
static GType
clutter_bin_layout_get_child_meta_type (ClutterLayoutManager *manager)
{
return CLUTTER_TYPE_BIN_LAYER;
}
static ClutterLayoutMeta *
clutter_bin_layout_create_child_meta (ClutterLayoutManager *manager,
ClutterContainer *container,
ClutterActor *actor)
{
ClutterBinLayoutPrivate *priv;
priv = CLUTTER_BIN_LAYOUT (manager)->priv;
return g_object_new (CLUTTER_TYPE_BIN_LAYER,
"container", container,
"actor", actor,
"manager", manager,
"x-align", priv->x_align,
"y_align", priv->y_align,
NULL);
}
static void static void
clutter_bin_layout_set_container (ClutterLayoutManager *manager, clutter_bin_layout_set_container (ClutterLayoutManager *manager,
ClutterContainer *container) ClutterContainer *container)
@ -549,102 +274,15 @@ clutter_bin_layout_set_container (ClutterLayoutManager *manager,
parent_class->set_container (manager, container); parent_class->set_container (manager, container);
} }
static void
clutter_bin_layout_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (gobject);
switch (prop_id)
{
case PROP_X_ALIGN:
set_x_align (layout, g_value_get_enum (value));
break;
case PROP_Y_ALIGN:
set_y_align (layout, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
static void
clutter_bin_layout_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterBinLayoutPrivate *priv;
priv = CLUTTER_BIN_LAYOUT (gobject)->priv;
switch (prop_id)
{
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 (gobject, prop_id, pspec);
break;
}
}
static void static void
clutter_bin_layout_class_init (ClutterBinLayoutClass *klass) clutter_bin_layout_class_init (ClutterBinLayoutClass *klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterLayoutManagerClass *layout_class = ClutterLayoutManagerClass *layout_class =
CLUTTER_LAYOUT_MANAGER_CLASS (klass); CLUTTER_LAYOUT_MANAGER_CLASS (klass);
/**
* ClutterBinLayout:x-align:
*
* The default horizontal alignment policy for actors managed
* by the #ClutterBinLayout
*
* Deprecated: 1.12: Use the #ClutterActor:x-expand and the
* #ClutterActor:x-align properties on #ClutterActor instead.
*/
bin_props[PROP_X_ALIGN] =
g_param_spec_enum ("x-align", NULL, NULL,
CLUTTER_TYPE_BIN_ALIGNMENT,
CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_PARAM_READWRITE);
/**
* ClutterBinLayout:y-align:
*
* The default vertical alignment policy for actors managed
* by the #ClutterBinLayout
*
* Deprecated: 1.12: Use the #ClutterActor:y-expand and the
* #ClutterActor:y-align properties on #ClutterActor instead.
*/
bin_props[PROP_Y_ALIGN] =
g_param_spec_enum ("y-align", NULL, NULL,
CLUTTER_TYPE_BIN_ALIGNMENT,
CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_PARAM_READWRITE);
gobject_class->set_property = clutter_bin_layout_set_property;
gobject_class->get_property = clutter_bin_layout_get_property;
g_object_class_install_properties (gobject_class, PROP_LAST, bin_props);
layout_class->get_preferred_width = clutter_bin_layout_get_preferred_width; layout_class->get_preferred_width = clutter_bin_layout_get_preferred_width;
layout_class->get_preferred_height = clutter_bin_layout_get_preferred_height; layout_class->get_preferred_height = clutter_bin_layout_get_preferred_height;
layout_class->allocate = clutter_bin_layout_allocate; layout_class->allocate = clutter_bin_layout_allocate;
layout_class->create_child_meta = clutter_bin_layout_create_child_meta;
layout_class->get_child_meta_type = clutter_bin_layout_get_child_meta_type;
layout_class->set_container = clutter_bin_layout_set_container; layout_class->set_container = clutter_bin_layout_set_container;
} }
@ -652,28 +290,18 @@ static void
clutter_bin_layout_init (ClutterBinLayout *self) clutter_bin_layout_init (ClutterBinLayout *self)
{ {
self->priv = clutter_bin_layout_get_instance_private (self); self->priv = clutter_bin_layout_get_instance_private (self);
self->priv->x_align = CLUTTER_BIN_ALIGNMENT_CENTER;
self->priv->y_align = CLUTTER_BIN_ALIGNMENT_CENTER;
} }
/** /**
* clutter_bin_layout_new: * clutter_bin_layout_new:
* @x_align: the default alignment policy to be used on the
* horizontal axis
* @y_align: the default alignment policy to be used on the
* vertical axis
* *
* Creates a new #ClutterBinLayout layout manager * Creates a new #ClutterBinLayout layout manager
* *
* Return value: the newly created layout manager * Return value: the newly created layout manager
*/ */
ClutterLayoutManager * ClutterLayoutManager *
clutter_bin_layout_new (ClutterBinAlignment x_align, clutter_bin_layout_new (void)
ClutterBinAlignment y_align)
{ {
return g_object_new (CLUTTER_TYPE_BIN_LAYOUT, return g_object_new (CLUTTER_TYPE_BIN_LAYOUT,
"x-align", x_align,
"y-align", y_align,
NULL); NULL);
} }

View File

@ -67,7 +67,6 @@ CLUTTER_EXPORT
GType clutter_bin_layout_get_type (void) G_GNUC_CONST; GType clutter_bin_layout_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT CLUTTER_EXPORT
ClutterLayoutManager * clutter_bin_layout_new (ClutterBinAlignment x_align, ClutterLayoutManager * clutter_bin_layout_new (void);
ClutterBinAlignment y_align);
G_END_DECLS G_END_DECLS

View File

@ -466,33 +466,6 @@ typedef enum /*< prefix=CLUTTER_ALIGN >*/
CLUTTER_ALIGN_BOTH CLUTTER_ALIGN_BOTH
} ClutterAlignAxis; } ClutterAlignAxis;
/**
* ClutterBinAlignment:
* @CLUTTER_BIN_ALIGNMENT_FIXED: Fixed position alignment; the
* #ClutterBinLayout will honour the fixed position provided
* by the actors themselves when allocating them
* @CLUTTER_BIN_ALIGNMENT_FILL: Fill the allocation size
* @CLUTTER_BIN_ALIGNMENT_START: Position the actors at the top
* or left side of the container, depending on the axis
* @CLUTTER_BIN_ALIGNMENT_END: Position the actors at the bottom
* or right side of the container, depending on the axis
* @CLUTTER_BIN_ALIGNMENT_CENTER: Position the actors at the
* center of the container, depending on the axis
*
* The alignment policies available on each axis for #ClutterBinLayout
*
* Deprecated: 1.12: Use #ClutterActorAlign and the #ClutterActor
* API instead
*/
typedef enum
{
CLUTTER_BIN_ALIGNMENT_FIXED,
CLUTTER_BIN_ALIGNMENT_FILL,
CLUTTER_BIN_ALIGNMENT_START,
CLUTTER_BIN_ALIGNMENT_END,
CLUTTER_BIN_ALIGNMENT_CENTER
} ClutterBinAlignment;
/** /**
* ClutterBindCoordinate: * ClutterBindCoordinate:
* @CLUTTER_BIND_X: Bind the X coordinate * @CLUTTER_BIND_X: Bind the X coordinate

View File

@ -46,9 +46,7 @@ test_stage_sizing_main (int argc, char *argv[])
clutter_actor_add_child (stage, box); clutter_actor_add_child (stage, box);
rect = clutter_actor_new (); rect = clutter_actor_new ();
clutter_actor_set_layout_manager (rect, clutter_actor_set_layout_manager (rect, clutter_bin_layout_new ());
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_BIN_ALIGNMENT_CENTER));
clutter_actor_set_background_color (rect, CLUTTER_COLOR_SkyBlue); clutter_actor_set_background_color (rect, CLUTTER_COLOR_SkyBlue);
clutter_actor_set_reactive (rect, TRUE); clutter_actor_set_reactive (rect, TRUE);
g_signal_connect_swapped (rect, "button-press-event", g_signal_connect_swapped (rect, "button-press-event",
@ -59,9 +57,7 @@ test_stage_sizing_main (int argc, char *argv[])
clutter_actor_add_child (box, rect); clutter_actor_add_child (box, rect);
rect = clutter_actor_new (); rect = clutter_actor_new ();
clutter_actor_set_layout_manager (rect, clutter_actor_set_layout_manager (rect, clutter_bin_layout_new ());
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_BIN_ALIGNMENT_CENTER));
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Butter); clutter_actor_set_background_color (rect, CLUTTER_COLOR_Butter);
clutter_actor_set_reactive (rect, TRUE); clutter_actor_set_reactive (rect, TRUE);
g_signal_connect_swapped (rect, "button-press-event", g_signal_connect_swapped (rect, "button-press-event",