Skip to content

Commit bc449de

Browse files
authored
clutter/actor: Allow specifying the layout manager for an actor type (#709)
Some actors have a well-defined layout manager other than FixedLayout. If they do, we can handle the layout manager creation at the ClutterActor instantiation, like GTK does for widget layout managers.
1 parent 6f16b7f commit bc449de

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

clutter/clutter/clutter-actor.c

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6555,11 +6555,19 @@ clutter_actor_constructor (GType gtype,
65556555

65566556
if (self->priv->layout_manager == NULL)
65576557
{
6558+
ClutterActorClass *actor_class;
65586559
ClutterLayoutManager *default_layout;
6560+
GType layout_manager_type;
6561+
6562+
actor_class = CLUTTER_ACTOR_GET_CLASS (self);
6563+
6564+
layout_manager_type = clutter_actor_class_get_layout_manager_type (actor_class);
6565+
if (layout_manager_type == G_TYPE_INVALID)
6566+
layout_manager_type = CLUTTER_TYPE_FIXED_LAYOUT;
65596567

65606568
CLUTTER_NOTE (LAYOUT, "Creating default layout manager");
65616569

6562-
default_layout = clutter_fixed_layout_new ();
6570+
default_layout = g_object_new (layout_manager_type, NULL);
65636571
clutter_actor_set_layout_manager (self, default_layout);
65646572
}
65656573

@@ -6616,6 +6624,8 @@ clutter_actor_class_init (ClutterActorClass *klass)
66166624
klass->paint = clutter_actor_real_paint;
66176625
klass->destroy = clutter_actor_real_destroy;
66186626

6627+
klass->layout_manager_type = G_TYPE_INVALID;
6628+
66196629
/**
66206630
* ClutterActor:x:
66216631
*
@@ -18305,12 +18315,25 @@ clutter_actor_set_layout_manager (ClutterActor *self,
1830518315
ClutterLayoutManager *manager)
1830618316
{
1830718317
ClutterActorPrivate *priv;
18318+
GType expected_type, manager_type;
1830818319

1830918320
g_return_if_fail (CLUTTER_IS_ACTOR (self));
1831018321
g_return_if_fail (manager == NULL || CLUTTER_IS_LAYOUT_MANAGER (manager));
1831118322

1831218323
priv = self->priv;
1831318324

18325+
expected_type = clutter_actor_class_get_layout_manager_type (CLUTTER_ACTOR_GET_CLASS (self));
18326+
manager_type = manager != NULL ? G_TYPE_FROM_INSTANCE (manager) : G_TYPE_INVALID;
18327+
18328+
if (expected_type != G_TYPE_INVALID &&
18329+
manager_type != G_TYPE_INVALID &&
18330+
!g_type_is_a (manager_type, expected_type))
18331+
{
18332+
g_warning ("Trying to set layout manager of type %s, but actor only accepts %s",
18333+
g_type_name (manager_type), g_type_name (expected_type));
18334+
return;
18335+
}
18336+
1831418337
if (priv->layout_manager != NULL)
1831518338
{
1831618339
g_signal_handlers_disconnect_by_func (priv->layout_manager,
@@ -21415,3 +21438,43 @@ clutter_actor_has_accessible (ClutterActor *actor)
2141521438

2141621439
return TRUE;
2141721440
}
21441+
21442+
/**
21443+
* clutter_actor_class_set_layout_manager_type
21444+
* @actor_class: A #ClutterActor class
21445+
* @type: A #GType
21446+
*
21447+
* Sets the type to be used for creating layout managers for
21448+
* actors of @actor_class.
21449+
*
21450+
* The given @type must be a subtype of [[email protected]].
21451+
*
21452+
* This function should only be called from class init functions of actors.
21453+
*/
21454+
void
21455+
clutter_actor_class_set_layout_manager_type (ClutterActorClass *actor_class,
21456+
GType type)
21457+
{
21458+
g_return_if_fail (CLUTTER_IS_ACTOR_CLASS (actor_class));
21459+
g_return_if_fail (g_type_is_a (type, CLUTTER_TYPE_LAYOUT_MANAGER));
21460+
21461+
actor_class->layout_manager_type = type;
21462+
}
21463+
/**
21464+
* clutter_actor_class_get_layout_manager_type
21465+
* @actor_class: A #ClutterActor class
21466+
*
21467+
* Retrieves the type of the [[email protected]]
21468+
* used by actors of class @actor_class.
21469+
*
21470+
* See also: [[email protected]_layout_manager_type].
21471+
*
21472+
* Returns: type of a `ClutterLayoutManager` subclass, or %G_TYPE_INVALID
21473+
*/
21474+
GType
21475+
clutter_actor_class_get_layout_manager_type (ClutterActorClass *actor_class)
21476+
{
21477+
g_return_val_if_fail (CLUTTER_IS_ACTOR_CLASS (actor_class), G_TYPE_INVALID);
21478+
21479+
return actor_class->layout_manager_type;
21480+
}

clutter/clutter/clutter-actor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ struct _ClutterActorClass
303303

304304
/*< private >*/
305305
/* padding for future expansion */
306+
GType layout_manager_type;
307+
306308
gpointer _padding_dummy[25];
307309
};
308310

@@ -926,6 +928,13 @@ void clutter_actor_pick_box (ClutterActor *self,
926928
ClutterPickContext *pick_context,
927929
const ClutterActorBox *box);
928930

931+
CLUTTER_EXPORT
932+
void clutter_actor_class_set_layout_manager_type (ClutterActorClass *actor_class,
933+
GType type);
934+
935+
CLUTTER_EXPORT
936+
GType clutter_actor_class_get_layout_manager_type (ClutterActorClass *actor_class);
937+
929938
G_END_DECLS
930939

931940
#endif /* __CLUTTER_ACTOR_H__ */

debian/libmuffin0.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ libmuffin-clutter-0.so.0 libmuffin0 #MINVER#
106106
clutter_actor_box_set_origin@Base 5.3.0
107107
clutter_actor_box_set_size@Base 5.3.0
108108
clutter_actor_box_union@Base 5.3.0
109+
clutter_actor_class_get_layout_manager_type@Base 6.4.0
110+
clutter_actor_class_set_layout_manager_type@Base 6.4.0
109111
clutter_actor_clear_actions@Base 5.3.0
110112
clutter_actor_clear_constraints@Base 5.3.0
111113
clutter_actor_clear_effects@Base 5.3.0

0 commit comments

Comments
 (0)