Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clutter/actor: Allow specifying the layout manager for an actor type #709

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion clutter/clutter/clutter-actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@
* and realizes its children if they are visible. Does nothing if the
* actor is not visible.
*
* Calling this function is strongly disencouraged: the default

Check failure on line 1677 in clutter/clutter/clutter-actor.c

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-amd64, Mint 22, true) / Mint 22

disencouraged ==> discouraged
* implementation of #ClutterActorClass.map() will map all the children
* of an actor when mapping its parent.
*
Expand Down Expand Up @@ -2693,7 +2693,7 @@
* twice, or without entering an allocation loop.
*
* for the first two points, we check if the class of the actor is
* overridding the ::allocate() virtual function; if it isn't, then we

Check failure on line 2696 in clutter/clutter/clutter-actor.c

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-amd64, Mint 22, true) / Mint 22

overridding ==> overriding
* follow through with checking whether we have children and a layout
* manager, and eventually calling clutter_layout_manager_allocate().
*
Expand Down Expand Up @@ -6325,7 +6325,7 @@
}

static AtkObject *
_clutter_actor_ref_accessible (AtkImplementor *implementor)

Check failure on line 6328 in clutter/clutter/clutter-actor.c

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-amd64, Mint 22, true) / Mint 22

implementor ==> implementer
{
AtkObject *accessible;

Expand Down Expand Up @@ -6555,11 +6555,19 @@

if (self->priv->layout_manager == NULL)
{
ClutterActorClass *actor_class;
ClutterLayoutManager *default_layout;
GType layout_manager_type;

actor_class = CLUTTER_ACTOR_GET_CLASS (self);

layout_manager_type = clutter_actor_class_get_layout_manager_type (actor_class);
if (layout_manager_type == G_TYPE_INVALID)
layout_manager_type = CLUTTER_TYPE_FIXED_LAYOUT;

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

default_layout = clutter_fixed_layout_new ();
default_layout = g_object_new (layout_manager_type, NULL);
clutter_actor_set_layout_manager (self, default_layout);
}

Expand Down Expand Up @@ -6616,6 +6624,8 @@
klass->paint = clutter_actor_real_paint;
klass->destroy = clutter_actor_real_destroy;

klass->layout_manager_type = G_TYPE_INVALID;

/**
* ClutterActor:x:
*
Expand Down Expand Up @@ -18305,12 +18315,25 @@
ClutterLayoutManager *manager)
{
ClutterActorPrivate *priv;
GType expected_type, manager_type;

g_return_if_fail (CLUTTER_IS_ACTOR (self));
g_return_if_fail (manager == NULL || CLUTTER_IS_LAYOUT_MANAGER (manager));

priv = self->priv;

expected_type = clutter_actor_class_get_layout_manager_type (CLUTTER_ACTOR_GET_CLASS (self));
manager_type = manager != NULL ? G_TYPE_FROM_INSTANCE (manager) : G_TYPE_INVALID;

if (expected_type != G_TYPE_INVALID &&
manager_type != G_TYPE_INVALID &&
!g_type_is_a (manager_type, expected_type))
{
g_warning ("Trying to set layout manager of type %s, but actor only accepts %s",
g_type_name (manager_type), g_type_name (expected_type));
return;
}

if (priv->layout_manager != NULL)
{
g_signal_handlers_disconnect_by_func (priv->layout_manager,
Expand Down Expand Up @@ -21415,3 +21438,43 @@

return TRUE;
}

/**
* clutter_actor_class_set_layout_manager_type
* @actor_class: A #ClutterActor class
* @type: A #GType
*
* Sets the type to be used for creating layout managers for
* actors of @actor_class.
*
* The given @type must be a subtype of [class@Clutter.LayoutManager].
*
* This function should only be called from class init functions of actors.
*/
void
clutter_actor_class_set_layout_manager_type (ClutterActorClass *actor_class,
GType type)
{
g_return_if_fail (CLUTTER_IS_ACTOR_CLASS (actor_class));
g_return_if_fail (g_type_is_a (type, CLUTTER_TYPE_LAYOUT_MANAGER));

actor_class->layout_manager_type = type;
}
/**
* clutter_actor_class_get_layout_manager_type
* @actor_class: A #ClutterActor class
*
* Retrieves the type of the [class@Clutter.LayoutManager]
* used by actors of class @actor_class.
*
* See also: [method@Clutter.ActorClass.set_layout_manager_type].
*
* Returns: type of a `ClutterLayoutManager` subclass, or %G_TYPE_INVALID
*/
GType
clutter_actor_class_get_layout_manager_type (ClutterActorClass *actor_class)
{
g_return_val_if_fail (CLUTTER_IS_ACTOR_CLASS (actor_class), G_TYPE_INVALID);

return actor_class->layout_manager_type;
}
9 changes: 9 additions & 0 deletions clutter/clutter/clutter-actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ struct _ClutterActorClass

/*< private >*/
/* padding for future expansion */
GType layout_manager_type;

gpointer _padding_dummy[25];
};

Expand Down Expand Up @@ -926,6 +928,13 @@ void clutter_actor_pick_box (ClutterActor *self,
ClutterPickContext *pick_context,
const ClutterActorBox *box);

CLUTTER_EXPORT
void clutter_actor_class_set_layout_manager_type (ClutterActorClass *actor_class,
GType type);

CLUTTER_EXPORT
GType clutter_actor_class_get_layout_manager_type (ClutterActorClass *actor_class);

G_END_DECLS

#endif /* __CLUTTER_ACTOR_H__ */
2 changes: 2 additions & 0 deletions debian/libmuffin0.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ libmuffin-clutter-0.so.0 libmuffin0 #MINVER#
clutter_actor_box_set_origin@Base 5.3.0
clutter_actor_box_set_size@Base 5.3.0
clutter_actor_box_union@Base 5.3.0
clutter_actor_class_get_layout_manager_type@Base 6.4.0
clutter_actor_class_set_layout_manager_type@Base 6.4.0
clutter_actor_clear_actions@Base 5.3.0
clutter_actor_clear_constraints@Base 5.3.0
clutter_actor_clear_effects@Base 5.3.0
Expand Down
Loading