mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
31341986b1
ClutterFixedLayout is the default layout manager for ClutterActor. Existing subclasses of ClutterActor will get a fixed layout manager regardless of whether they are going to use it, but since it sets the CLUTTER_ACTOR_NO_LAYOUT flag, it will introduce regressions on actors that perform their own layout management. The CLUTTER_ACTOR_NO_LAYOUT flag was a bit of a mistake in the first place, as it was introduced as a last minute workaround in the 1.0 process to deal with broken stuff in Moblin. It's going to be a target for deprecation towards a removal when we start the 2.0 process.
181 lines
5.1 KiB
C
181 lines
5.1 KiB
C
/*
|
|
* Clutter.
|
|
*
|
|
* An OpenGL based 'interactive canvas' library.
|
|
*
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Author:
|
|
* Emmanuele Bassi <ebassi@linux.intel.com>
|
|
*
|
|
* Based on the fixed layout code inside clutter-group.c
|
|
*/
|
|
|
|
/**
|
|
* SECTION:clutter-fixed-layout
|
|
* @short_description: A fixed layout manager
|
|
*
|
|
* #ClutterFixedLayout is a layout manager implementing the same
|
|
* layout policies as #ClutterGroup.
|
|
*
|
|
* #ClutterFixedLayout is available since Clutter 1.2
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include "clutter-debug.h"
|
|
#include "clutter-fixed-layout.h"
|
|
#include "clutter-private.h"
|
|
|
|
G_DEFINE_TYPE (ClutterFixedLayout,
|
|
clutter_fixed_layout,
|
|
CLUTTER_TYPE_LAYOUT_MANAGER);
|
|
|
|
static void
|
|
clutter_fixed_layout_get_preferred_width (ClutterLayoutManager *manager,
|
|
ClutterContainer *container,
|
|
gfloat for_height,
|
|
gfloat *min_width_p,
|
|
gfloat *nat_width_p)
|
|
{
|
|
ClutterActor *actor, *child;
|
|
gdouble min_right;
|
|
gdouble natural_right;
|
|
|
|
min_right = 0;
|
|
natural_right = 0;
|
|
|
|
actor = CLUTTER_ACTOR (container);
|
|
|
|
for (child = clutter_actor_get_first_child (actor);
|
|
child != NULL;
|
|
child = clutter_actor_get_next_sibling (child))
|
|
{
|
|
gfloat child_x, child_min, child_natural;
|
|
|
|
child_x = clutter_actor_get_x (child);
|
|
|
|
clutter_actor_get_preferred_size (child,
|
|
&child_min, NULL,
|
|
&child_natural, NULL);
|
|
|
|
if (child_x + child_min > min_right)
|
|
min_right = child_x + child_min;
|
|
|
|
if (child_x + child_natural > natural_right)
|
|
natural_right = child_x + child_natural;
|
|
}
|
|
|
|
if (min_width_p)
|
|
*min_width_p = min_right;
|
|
|
|
if (nat_width_p)
|
|
*nat_width_p = natural_right;
|
|
}
|
|
|
|
static void
|
|
clutter_fixed_layout_get_preferred_height (ClutterLayoutManager *manager,
|
|
ClutterContainer *container,
|
|
gfloat for_width,
|
|
gfloat *min_height_p,
|
|
gfloat *nat_height_p)
|
|
{
|
|
ClutterActor *actor, *child;
|
|
gdouble min_bottom;
|
|
gdouble natural_bottom;
|
|
|
|
min_bottom = 0;
|
|
natural_bottom = 0;
|
|
|
|
actor = CLUTTER_ACTOR (container);
|
|
|
|
for (child = clutter_actor_get_first_child (actor);
|
|
child != NULL;
|
|
child = clutter_actor_get_next_sibling (child))
|
|
{
|
|
gfloat child_y, child_min, child_natural;
|
|
|
|
child_y = clutter_actor_get_y (child);
|
|
|
|
clutter_actor_get_preferred_size (child,
|
|
NULL, &child_min,
|
|
NULL, &child_natural);
|
|
|
|
if (child_y + child_min > min_bottom)
|
|
min_bottom = child_y + child_min;
|
|
|
|
if (child_y + child_natural > natural_bottom)
|
|
natural_bottom = child_y + child_natural;
|
|
}
|
|
|
|
if (min_height_p)
|
|
*min_height_p = min_bottom;
|
|
|
|
if (nat_height_p)
|
|
*nat_height_p = natural_bottom;
|
|
}
|
|
|
|
static void
|
|
clutter_fixed_layout_allocate (ClutterLayoutManager *manager,
|
|
ClutterContainer *container,
|
|
const ClutterActorBox *allocation,
|
|
ClutterAllocationFlags flags)
|
|
{
|
|
ClutterActor *child;
|
|
|
|
for (child = clutter_actor_get_first_child (CLUTTER_ACTOR (container));
|
|
child != NULL;
|
|
child = clutter_actor_get_next_sibling (child))
|
|
{
|
|
clutter_actor_allocate_preferred_size (child, flags);
|
|
}
|
|
}
|
|
|
|
static void
|
|
clutter_fixed_layout_class_init (ClutterFixedLayoutClass *klass)
|
|
{
|
|
ClutterLayoutManagerClass *manager_class =
|
|
CLUTTER_LAYOUT_MANAGER_CLASS (klass);
|
|
|
|
manager_class->get_preferred_width =
|
|
clutter_fixed_layout_get_preferred_width;
|
|
manager_class->get_preferred_height =
|
|
clutter_fixed_layout_get_preferred_height;
|
|
manager_class->allocate = clutter_fixed_layout_allocate;
|
|
}
|
|
|
|
static void
|
|
clutter_fixed_layout_init (ClutterFixedLayout *self)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* clutter_fixed_layout_new:
|
|
*
|
|
* Creates a new #ClutterFixedLayout
|
|
*
|
|
* Return value: the newly created #ClutterFixedLayout
|
|
*
|
|
* Since: 1.2
|
|
*/
|
|
ClutterLayoutManager *
|
|
clutter_fixed_layout_new (void)
|
|
{
|
|
return g_object_new (CLUTTER_TYPE_FIXED_LAYOUT, NULL);
|
|
}
|