Merge branch 'wip/table-layout'

* wip/table-layout:
  Add ClutterTableLayout, a layout showing children in rows and columns
  box-layout: Use allocate_align_fill()
  bin-layout: Migrate to allocate_align_fill()
  actor: Add allocate_align_fill()
  test-flow-layout: Use BindConstraints
This commit is contained in:
Emmanuele Bassi
2010-08-11 11:32:44 +01:00
15 changed files with 3329 additions and 202 deletions

View File

@@ -133,6 +133,7 @@ source_h = \
$(srcdir)/clutter-stage-manager.h \
$(srcdir)/clutter-stage-window.h \
$(srcdir)/clutter-state.h \
$(srcdir)/clutter-table-layout.h \
$(srcdir)/clutter-texture.h \
$(srcdir)/clutter-text.h \
$(srcdir)/clutter-timeline.h \
@@ -227,6 +228,7 @@ source_c = \
$(srcdir)/clutter-stage-manager.c \
$(srcdir)/clutter-stage-window.c \
$(srcdir)/clutter-state.c \
$(srcdir)/clutter-table-layout.c \
$(srcdir)/clutter-texture.c \
$(srcdir)/clutter-text.c \
$(srcdir)/clutter-timeline.c \

View File

@@ -10028,6 +10028,145 @@ clutter_actor_allocate_preferred_size (ClutterActor *self,
clutter_actor_allocate (self, &actor_box, flags);
}
/**
* clutter_actor_allocate_align_fill:
* @self: a #ClutterActor
* @box: a #ClutterActorBox, containing the available width and height
* @x_align: the horizontal alignment, between 0 and 1
* @y_align: the vertical alignment, between 0 and 1
* @x_fill: whether the actor should fill horizontally
* @y_fill: whether the actor should fill vertically
* @flags: allocation flags to be passed to clutter_actor_allocate()
*
* Allocates @self by taking into consideration the available allocation
* area; an alignment factor on either axis; and whether the actor should
* fill the allocation on either axis.
*
* The @box should contain the available allocation width and height;
* if the x1 and y1 members of #ClutterActorBox are not set to 0, the
* allocation will be offset by their value.
*
* This function takes into consideration the geometry request specified by
* the #ClutterActor:request-mode property, and the text direction.
*
* This function is useful for fluid layout managers, like #ClutterBinLayout
* or #ClutterTableLayout
*
* Since: 1.4
*/
void
clutter_actor_allocate_align_fill (ClutterActor *self,
const ClutterActorBox *box,
gdouble x_align,
gdouble y_align,
gboolean x_fill,
gboolean y_fill,
ClutterAllocationFlags flags)
{
ClutterActorPrivate *priv;
ClutterActorBox allocation = { 0, };
gfloat x_offset, y_offset;
gfloat available_width, available_height;
gfloat child_width, child_height;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
g_return_if_fail (box != NULL);
g_return_if_fail (x_align >= 0.0 && x_align <= 1.0);
g_return_if_fail (y_align >= 0.0 && y_align <= 1.0);
priv = self->priv;
clutter_actor_box_get_origin (box, &x_offset, &y_offset);
clutter_actor_box_get_size (box, &available_width, &available_height);
if (available_width < 0)
available_width = 0;
if (available_height < 0)
available_height = 0;
if (x_fill)
{
allocation.x1 = x_offset;
allocation.x2 = allocation.x1 + available_width;
}
if (y_fill)
{
allocation.y1 = y_offset;
allocation.y2 = allocation.y1 + available_height;
}
/* if we are filling horizontally and vertically then we're done */
if (x_fill && y_fill)
goto out;
child_width = child_height = 0.0f;
if (priv->request_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
{
gfloat min_width, natural_width;
gfloat min_height, natural_height;
clutter_actor_get_preferred_width (self, available_height,
&min_width,
&natural_width);
child_width = CLAMP (natural_width, min_width, available_width);
if (!y_fill)
{
clutter_actor_get_preferred_height (self, child_width,
&min_height,
&natural_height);
child_height = CLAMP (natural_height, min_height, available_height);
}
}
else
{
gfloat min_width, natural_width;
gfloat min_height, natural_height;
clutter_actor_get_preferred_height (self, available_width,
&min_height,
&natural_height);
child_height = CLAMP (natural_height, min_height, available_height);
if (!x_fill)
{
clutter_actor_get_preferred_width (self, child_height,
&min_width,
&natural_width);
child_width = CLAMP (natural_width, min_width, available_width);
}
}
/* invert the horizontal alignment for RTL languages */
if (priv->text_direction == CLUTTER_TEXT_DIRECTION_RTL)
x_align = 1.0 - x_align;
if (!x_fill)
{
allocation.x1 = box->x1
+ ((available_width - child_width) * x_align);
allocation.x2 = allocation.x1 + child_width;
}
if (!y_fill)
{
allocation.y1 = box->y1
+ ((available_height - child_height) * y_align);
allocation.y2 = allocation.y1 + child_height;
}
out:
clutter_actor_box_clamp_to_pixel (&allocation);
clutter_actor_allocate (self, &allocation, flags);
}
/**
* clutter_actor_grab_key_focus:
* @self: a #ClutterActor

View File

@@ -361,6 +361,13 @@ void clutter_actor_allocate_available_size (ClutterActor
gfloat available_width,
gfloat available_height,
ClutterAllocationFlags flags);
void clutter_actor_allocate_align_fill (ClutterActor *self,
const ClutterActorBox *box,
gdouble x_align,
gdouble y_align,
gboolean x_fill,
gboolean y_fill,
ClutterAllocationFlags flags);
void clutter_actor_get_allocation_box (ClutterActor *self,
ClutterActorBox *box);
void clutter_actor_get_allocation_geometry (ClutterActor *self,

View File

@@ -435,102 +435,36 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
ClutterLayoutMeta *meta;
ClutterBinLayer *layer;
ClutterActorBox child_alloc = { 0, };
gfloat child_width, child_height;
ClutterRequestMode request;
gdouble x_align, y_align;
gboolean x_fill, y_fill;
meta = clutter_layout_manager_get_child_meta (manager,
container,
child);
layer = CLUTTER_BIN_LAYER (meta);
if (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL)
{
child_alloc.x1 = 0;
child_alloc.x2 = ceilf (available_w);
}
if (layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL)
{
child_alloc.y1 = 0;
child_alloc.y2 = ceilf (available_h);
}
/* if we are filling horizontally and vertically then we
* can break here because we already have a full allocation
*/
if (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL &&
layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL)
{
clutter_actor_allocate (child, &child_alloc, flags);
continue;
}
child_width = child_height = 0;
request = clutter_actor_get_request_mode (child);
if (request == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
{
gfloat min_width, nat_width;
gfloat min_height, nat_height;
clutter_actor_get_preferred_width (child, available_h,
&min_width,
&nat_width);
child_width = CLAMP (nat_width, min_width, available_w);
clutter_actor_get_preferred_height (child, child_width,
&min_height,
&nat_height);
child_height = CLAMP (nat_height, min_height, available_h);
}
else if (request == CLUTTER_REQUEST_WIDTH_FOR_HEIGHT)
{
gfloat min_width, nat_width;
gfloat min_height, nat_height;
clutter_actor_get_preferred_height (child, available_w,
&min_height,
&nat_height);
child_height = CLAMP (nat_height, min_height, available_h);
clutter_actor_get_preferred_width (child, child_height,
&min_width,
&nat_width);
child_width = CLAMP (nat_width, min_width, available_w);
}
if (layer->x_align == CLUTTER_BIN_ALIGNMENT_FIXED)
{
child_alloc.x1 = ceilf (clutter_actor_get_x (child));
child_alloc.x2 = ceilf (child_alloc.x1 + child_width);
}
child_alloc.x1 = clutter_actor_get_x (child);
else
{
gdouble x_align = get_bin_alignment_factor (layer->x_align);
if (layer->x_align != CLUTTER_BIN_ALIGNMENT_FILL)
{
child_alloc.x1 = ceilf ((available_w - child_width) * x_align);
child_alloc.x2 = ceilf (child_alloc.x1 + child_width);
}
}
child_alloc.x1 = 0.0f;
if (layer->y_align == CLUTTER_BIN_ALIGNMENT_FIXED)
{
child_alloc.y1 = ceilf (clutter_actor_get_y (child));
child_alloc.y2 = ceilf (child_alloc.y1 + child_height);
}
child_alloc.y1 = clutter_actor_get_y (child);
else
{
gdouble y_align = get_bin_alignment_factor (layer->y_align);
child_alloc.y1 = 0.0f;
if (layer->y_align != CLUTTER_BIN_ALIGNMENT_FILL)
{
child_alloc.y1 = ceilf ((available_h - child_height) * y_align);
child_alloc.y2 = ceilf (child_alloc.y1 + child_height);
}
}
child_alloc.x2 = available_w;
child_alloc.y2 = available_h;
clutter_actor_allocate (child, &child_alloc, flags);
x_fill = (layer->x_align == CLUTTER_BIN_ALIGNMENT_FILL);
y_fill = (layer->y_align == CLUTTER_BIN_ALIGNMENT_FILL);
x_align = get_bin_alignment_factor (layer->x_align);
y_align = get_bin_alignment_factor (layer->y_align);
clutter_actor_allocate_align_fill (child, &child_alloc,
x_align, y_align,
x_fill, y_fill,
flags);
}
g_list_free (children);

View File

@@ -437,106 +437,22 @@ clutter_box_child_init (ClutterBoxChild *self)
self->last_allocation = NULL;
}
static inline void
allocate_fill (ClutterActor *child,
ClutterActorBox *childbox,
ClutterBoxChild *box_child)
static gdouble
get_box_alignment_factor (ClutterBoxAlignment alignment)
{
gfloat natural_width, natural_height;
gfloat min_width, min_height;
gfloat child_width, child_height;
gfloat available_width, available_height;
ClutterRequestMode request;
ClutterActorBox allocation = { 0, };
gdouble x_align, y_align;
if (box_child->x_align == CLUTTER_BOX_ALIGNMENT_START)
x_align = 0.0;
else if (box_child->x_align == CLUTTER_BOX_ALIGNMENT_CENTER)
x_align = 0.5;
else
x_align = 1.0;
if (box_child->y_align == CLUTTER_BOX_ALIGNMENT_START)
y_align = 0.0;
else if (box_child->y_align == CLUTTER_BOX_ALIGNMENT_CENTER)
y_align = 0.5;
else
y_align = 1.0;
available_width = childbox->x2 - childbox->x1;
available_height = childbox->y2 - childbox->y1;
if (available_width < 0)
available_width = 0;
if (available_height < 0)
available_height = 0;
if (box_child->x_fill)
switch (alignment)
{
allocation.x1 = childbox->x1;
allocation.x2 = ceilf (allocation.x1 + available_width);
case CLUTTER_BOX_ALIGNMENT_CENTER:
return 0.5;
case CLUTTER_BOX_ALIGNMENT_START:
return 0.0;
case CLUTTER_BOX_ALIGNMENT_END:
return 1.0;
}
if (box_child->y_fill)
{
allocation.y1 = childbox->y1;
allocation.y2 = ceilf (allocation.y1 + available_height);
}
/* if we are filling horizontally and vertically then we're done */
if (box_child->x_fill && box_child->y_fill)
{
*childbox = allocation;
return;
}
request = clutter_actor_get_request_mode (child);
if (request == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
{
clutter_actor_get_preferred_width (child, available_height,
&min_width,
&natural_width);
child_width = CLAMP (natural_width, min_width, available_width);
clutter_actor_get_preferred_height (child, child_width,
&min_height,
&natural_height);
child_height = CLAMP (natural_height, min_height, available_height);
}
else
{
clutter_actor_get_preferred_height (child, available_width,
&min_height,
&natural_height);
child_height = CLAMP (natural_height, min_height, available_height);
clutter_actor_get_preferred_width (child, child_height,
&min_width,
&natural_width);
child_width = CLAMP (natural_width, min_width, available_width);
}
if (!box_child->x_fill)
{
allocation.x1 = ceilf (childbox->x1
+ ((available_width - child_width) * x_align));
allocation.x2 = ceilf (allocation.x1 + child_width);
}
if (!box_child->y_fill)
{
allocation.y1 = ceilf (childbox->y1
+ ((available_height - child_height) * y_align));
allocation.y2 = ceilf (allocation.y1 + child_height);
}
*childbox = allocation;
return 0.0;
}
static GType
@@ -784,7 +700,17 @@ allocate_box_child (ClutterBoxLayout *self,
child_box.y2 = floorf (avail_height + 0.5);
}
allocate_fill (child, &child_box, box_child);
clutter_actor_allocate_align_fill (child, &child_box,
get_box_alignment_factor (box_child->x_align),
get_box_alignment_factor (box_child->y_align),
box_child->x_fill,
box_child->y_fill,
flags);
/* retrieve the allocation computed and set by allocate_align_fill();
* since we call this *after* allocate(), it's just a cheap copy
*/
clutter_actor_get_allocation_box (child, &child_box);
if (priv->use_animations && priv->is_animating)
{

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,163 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2010 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:
* Jose Dapena Paz <jdapena@igalia.com>
*
* Based on the MX MxTable actor by:
* Thomas Wood <thomas.wood@intel.com>
*/
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#ifndef __CLUTTER_TABLE_LAYOUT_H__
#define __CLUTTER_TABLE_LAYOUT_H__
#include <clutter/clutter-layout-manager.h>
G_BEGIN_DECLS
#define CLUTTER_TYPE_TABLE_LAYOUT (clutter_table_layout_get_type ())
#define CLUTTER_TABLE_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_TABLE_LAYOUT, ClutterTableLayout))
#define CLUTTER_IS_TABLE_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_TABLE_LAYOUT))
#define CLUTTER_TABLE_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_TABLE_LAYOUT, ClutterTableLayoutClass))
#define CLUTTER_IS_TABLE_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_TABLE_LAYOUT))
#define CLUTTER_TABLE_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_TABLE_LAYOUT, ClutterTableLayoutClass))
typedef struct _ClutterTableLayout ClutterTableLayout;
typedef struct _ClutterTableLayoutPrivate ClutterTableLayoutPrivate;
typedef struct _ClutterTableLayoutClass ClutterTableLayoutClass;
/**
* ClutterTableAlignment:
* @CLUTTER_TABLE_ALIGNMENT_START: Align the child to the top or to the
* left of a cell in the table, depending on the axis
* @CLUTTER_TABLE_ALIGNMENT_CENTER: Align the child to the center of
* a cell in the table
* @CLUTTER_TABLE_ALIGNMENT_END: Align the child to the bottom or to the
* right of a cell in the table, depending on the axis
*
* The alignment policies available on each axis of the #ClutterTableLayout
*
* Since: 1.4
*/
typedef enum {
CLUTTER_TABLE_ALIGNMENT_START,
CLUTTER_TABLE_ALIGNMENT_CENTER,
CLUTTER_TABLE_ALIGNMENT_END
} ClutterTableAlignment;
/**
* ClutterTableLayout:
*
* The #ClutterTableLayout structure contains only private data
* and should be accessed using the provided API
*
* Since: 1.4
*/
struct _ClutterTableLayout
{
/*< private >*/
ClutterLayoutManager parent_instance;
ClutterTableLayoutPrivate *priv;
};
/**
* ClutterTableLayoutClass:
*
* The #ClutterTableLayoutClass structure contains only private
* data and should be accessed using the provided API
*
* Since: 1.4
*/
struct _ClutterTableLayoutClass
{
/*< private >*/
ClutterLayoutManagerClass parent_class;
};
GType clutter_table_layout_get_type (void) G_GNUC_CONST;
ClutterLayoutManager *clutter_table_layout_new (void);
void clutter_table_layout_pack (ClutterTableLayout *layout,
ClutterActor *actor,
gint row,
gint column);
void clutter_table_layout_set_column_spacing (ClutterTableLayout *layout,
guint spacing);
void clutter_table_layout_set_row_spacing (ClutterTableLayout *layout,
guint spacing);
guint clutter_table_layout_get_column_spacing (ClutterTableLayout *layout);
guint clutter_table_layout_get_row_spacing (ClutterTableLayout *layout);
void clutter_table_layout_set_span (ClutterTableLayout *layout,
ClutterActor *actor,
gint column_span,
gint row_span);
void clutter_table_layout_get_span (ClutterTableLayout *layout,
ClutterActor *actor,
gint *column_span,
gint *row_span);
void clutter_table_layout_set_alignment (ClutterTableLayout *layout,
ClutterActor *actor,
ClutterTableAlignment x_align,
ClutterTableAlignment y_align);
void clutter_table_layout_get_alignment (ClutterTableLayout *layout,
ClutterActor *actor,
ClutterTableAlignment *x_align,
ClutterTableAlignment *y_align);
void clutter_table_layout_set_fill (ClutterTableLayout *layout,
ClutterActor *actor,
gboolean x_fill,
gboolean y_fill);
void clutter_table_layout_get_fill (ClutterTableLayout *layout,
ClutterActor *actor,
gboolean *x_fill,
gboolean *y_fill);
void clutter_table_layout_set_expand (ClutterTableLayout *layout,
ClutterActor *actor,
gboolean x_expand,
gboolean y_expand);
void clutter_table_layout_get_expand (ClutterTableLayout *layout,
ClutterActor *actor,
gboolean *x_expand,
gboolean *y_expand);
gint clutter_table_layout_get_row_count (ClutterTableLayout *layout);
gint clutter_table_layout_get_column_count (ClutterTableLayout *layout);
void clutter_table_layout_set_use_animations (ClutterTableLayout *layout,
gboolean animate);
gboolean clutter_table_layout_get_use_animations (ClutterTableLayout *layout);
void clutter_table_layout_set_easing_mode (ClutterTableLayout *layout,
gulong mode);
gulong clutter_table_layout_get_easing_mode (ClutterTableLayout *layout);
void clutter_table_layout_set_easing_duration (ClutterTableLayout *layout,
guint msecs);
guint clutter_table_layout_get_easing_duration (ClutterTableLayout *layout);
G_END_DECLS
#endif /* __CLUTTER_TABLE_LAYOUT_H__ */

View File

@@ -95,6 +95,7 @@
#include "clutter-stage-manager.h"
#include "clutter-stage-window.h"
#include "clutter-state.h"
#include "clutter-table-layout.h"
#include "clutter-texture.h"
#include "clutter-text.h"
#include "clutter-timeline.h"