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
commit 5e1d40c07b
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"

View File

@ -90,6 +90,7 @@
<xi:include href="xml/clutter-bin-layout.xml"/>
<xi:include href="xml/clutter-flow-layout.xml"/>
<xi:include href="xml/clutter-box-layout.xml"/>
<xi:include href="xml/clutter-table-layout.xml"/>
</chapter>
<chapter>

View File

@ -303,6 +303,7 @@ ClutterAllocationFlags
clutter_actor_allocate
clutter_actor_allocate_preferred_size
clutter_actor_allocate_available_size
clutter_actor_allocate_align_fill
clutter_actor_get_allocation_box
clutter_actor_get_allocation_geometry
clutter_actor_get_allocation_vertices
@ -2067,6 +2068,53 @@ ClutterBoxLayoutPrivate
clutter_box_layout_get_type
</SECTION>
<SECTION>
<FILE>clutter-table-layout</FILE>
ClutterTableAlignment
ClutterTableLayout
ClutterTableLayoutClass
clutter_table_layout_new
clutter_table_layout_set_row_spacing
clutter_table_layout_get_row_spacing
clutter_table_layout_set_column_spacing
clutter_table_layout_get_column_spacing
clutter_table_layout_get_row_count
clutter_table_layout_get_column_count
<SUBSECTION>
clutter_table_layout_pack
<SUBSECTION>
clutter_table_layout_set_alignment
clutter_table_layout_get_alignment
clutter_table_layout_set_expand
clutter_table_layout_get_expand
clutter_table_layout_set_fill
clutter_table_layout_get_fill
clutter_table_layout_get_span
clutter_table_layout_set_span
<SUBSECTION>
clutter_table_layout_set_use_animations
clutter_table_layout_get_use_animations
clutter_table_layout_set_easing_duration
clutter_table_layout_get_easing_duration
clutter_table_layout_set_easing_mode
clutter_table_layout_get_easing_mode
<SUBSECTION Standard>
CLUTTER_TYPE_TABLE_LAYOUT
CLUTTER_TABLE_LAYOUT
CLUTTER_TABLE_LAYOUT_CLASS
CLUTTER_IS_TABLE_LAYOUT
CLUTTER_IS_TABLE_LAYOUT_CLASS
CLUTTER_TABLE_LAYOUT_GET_CLASS
<SUBSECTION Private>
ClutterTableLayoutPrivate
clutter_table_layout_get_type
</SECTION>
<SECTION>
<FILE>clutter-animator</FILE>
<TITLE>ClutterAnimator</TITLE>

View File

@ -56,6 +56,7 @@ clutter_shader_effect_get_type
clutter_stage_get_type
clutter_stage_manager_get_type
clutter_state_get_type
clutter_table_layout_get_type
clutter_text_get_type
clutter_texture_get_type
clutter_timeline_get_type

View File

@ -71,3 +71,4 @@
/test-scrolling
/test-bind
/test-cogl-point-sprites
/test-table-layout

View File

@ -56,7 +56,8 @@ UNIT_TESTS = \
test-constraints.c \
test-scrolling.c \
test-bind.c \
test-cogl-point-sprites.c
test-cogl-point-sprites.c \
test-table-layout.c
if X11_TESTS
UNIT_TESTS += test-pixmap.c

View File

@ -67,22 +67,6 @@ static GOptionEntry entries[] = {
{ NULL }
};
static void
on_stage_resize (ClutterActor *stage,
const ClutterActorBox *allocation,
ClutterAllocationFlags flags,
ClutterActor *box)
{
gfloat width, height;
clutter_actor_box_get_size (allocation, &width, &height);
if (vertical)
clutter_actor_set_height (box, height);
else
clutter_actor_set_width (box, width);
}
G_MODULE_EXPORT int
test_flow_layout_main (int argc, char *argv[])
{
@ -124,6 +108,13 @@ test_flow_layout_main (int argc, char *argv[])
box = clutter_box_new (layout);
clutter_box_set_color (CLUTTER_BOX (box), &box_color);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
if (fit_to_stage)
{
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, 0.0));
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, 0.0));
}
clutter_actor_set_position (box, 0, 0);
clutter_actor_set_name (box, "box");
@ -161,11 +152,6 @@ test_flow_layout_main (int argc, char *argv[])
g_free (name);
}
if (fit_to_stage)
g_signal_connect (stage,
"allocation-changed", G_CALLBACK (on_stage_resize),
box);
clutter_actor_show_all (stage);
clutter_main ();

View File

@ -0,0 +1,275 @@
#include <stdio.h>
#include <stdlib.h>
#include <gmodule.h>
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "pango/cogl-pango.h"
#define FONT "Sans 12"
static void
set_text (ClutterActor *actor, const gchar *text)
{
GList *children, *l;
children = clutter_container_get_children (CLUTTER_CONTAINER (actor));
for (l = children; l; l = g_list_next (l)) {
if (CLUTTER_IS_TEXT (l->data)) {
clutter_text_set_text (CLUTTER_TEXT (l->data), text);
break;
}
}
g_list_free (children);
}
static void
toggle_expand (ClutterActor *actor, ClutterEvent *event, ClutterBox *box)
{
gboolean x_expand;
gchar *label;
ClutterLayoutManager *layout = clutter_box_get_layout_manager (box);
clutter_layout_manager_child_get (layout, CLUTTER_CONTAINER (box), actor,
"x-expand", &x_expand,
NULL);
x_expand = !x_expand;
clutter_layout_manager_child_set (layout, CLUTTER_CONTAINER (box), actor,
"x-expand", x_expand,
"y-expand", x_expand,
NULL);
label = g_strdup_printf ("Expand = %d", x_expand);
set_text (actor, label);
g_free (label);
}
static const gchar *
get_alignment_name (ClutterTableAlignment alignment)
{
switch (alignment)
{
case CLUTTER_TABLE_ALIGNMENT_START:
return "start";
case CLUTTER_TABLE_ALIGNMENT_CENTER:
return "center";
case CLUTTER_TABLE_ALIGNMENT_END:
return "end";
}
return "undefined";
}
static void
randomise_align (ClutterActor *actor, ClutterEvent *event, ClutterBox *box)
{
ClutterTableAlignment x_align, y_align;
gchar *label;
ClutterLayoutManager *layout;
layout = clutter_box_get_layout_manager (box);
x_align = (ClutterTableAlignment) g_random_int_range (0, 3);
y_align = (ClutterTableAlignment) g_random_int_range (0, 3);
clutter_layout_manager_child_set (layout, CLUTTER_CONTAINER (box), actor,
"x-align", x_align,
"y-align", y_align,
NULL);
label = g_strdup_printf ("Align (%s, %s)",
get_alignment_name (x_align),
get_alignment_name (y_align));
set_text (actor, label);
g_free (label);
}
static void
toggle_visible (ClutterActor *actor, ClutterEvent *event, gpointer userdata)
{
clutter_actor_hide (actor);
}
gboolean drag = FALSE;
static ClutterActor *
create_cell (ClutterActor *actor, const gchar *color_str)
{
ClutterActor *result;
ClutterActor *rectangle;
ClutterColor color;
result =
clutter_box_new (clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
CLUTTER_BIN_ALIGNMENT_FILL));
rectangle = clutter_rectangle_new ();
clutter_color_from_string (&color, color_str);
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rectangle), (const ClutterColor *) &color);
clutter_color_from_string (&color, "#000f");
clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle), (const ClutterColor *) &color);
clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 2);
clutter_actor_show (rectangle);
clutter_actor_set_reactive (result, TRUE);
clutter_container_add_actor (CLUTTER_CONTAINER (result), rectangle);
clutter_box_pack (CLUTTER_BOX (result), actor,
"x-align", CLUTTER_BIN_ALIGNMENT_CENTER,
"y-align", CLUTTER_BIN_ALIGNMENT_CENTER,
NULL);
return result;
}
static ClutterActor *
create_text (const gchar *label, const gchar *color)
{
ClutterActor *text;
ClutterActor *result;
text = clutter_text_new_with_text (FONT, label);
clutter_actor_show (text);
result = create_cell (text, color);
clutter_actor_show (result);
return result;
}
static ClutterActor *
create_image (const gchar *file, const gchar *color)
{
ClutterActor *texture;
ClutterActor *result;
texture = clutter_texture_new_from_file (file, NULL);
g_object_set (G_OBJECT (texture), "keep-aspect-ratio", TRUE, NULL);
clutter_actor_show (texture);
result = create_cell (texture, color);
clutter_actor_show (result);
return result;
}
G_MODULE_EXPORT int
test_table_layout_main (int argc, char *argv[])
{
ClutterActor *stage;
ClutterLayoutManager *layout;
ClutterActor *actor1, *actor2, *actor3, *actor4, *actor5, *actor6, *actor7, *actor8, *actor9, *actor10;
ClutterActor *box;
gchar *file;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "Table Layout");
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
clutter_actor_set_size (stage, 640, 480);
layout = clutter_table_layout_new ();
clutter_table_layout_set_column_spacing (CLUTTER_TABLE_LAYOUT (layout), 10);
clutter_table_layout_set_row_spacing (CLUTTER_TABLE_LAYOUT (layout), 10);
box = clutter_box_new (layout);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, -10.0));
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, -10.0));
actor1 = create_text ("label 1", "#f66f");
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
actor2 = create_image (file, "#bbcf");
g_free (file);
actor3 = create_text ("label 3", "#6f6f");
actor4 = create_text ("Expand = 1", "#66ff");
actor5 = create_text ("label 5", "#f6ff");
actor6 = create_text ("label 6", "#6fff");
actor7 = create_text ("Align (center, center)", "#66ff");
actor8 = create_text ("label 8", "#ffff");
actor9 = create_text ("label 9", "#666f");
actor10 = create_text ("label 10", "#aaaf");
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor1, 0, 0);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor2, 0, 1);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor3, 1, 1);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor4, 2, 0);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor5, 3, 0);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor6, 3, 1);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor7, 4, 1);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor8, 4, 0);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor9, 5, 0);
clutter_table_layout_pack (CLUTTER_TABLE_LAYOUT (layout), actor10, -1, 0);
clutter_table_layout_set_span (CLUTTER_TABLE_LAYOUT (layout), actor1, 2, 1);
clutter_table_layout_set_span (CLUTTER_TABLE_LAYOUT (layout), actor7, 2, 1);
clutter_table_layout_set_span (CLUTTER_TABLE_LAYOUT (layout), actor4, 1, 2);
clutter_actor_set_size (actor1, 100, 100);
clutter_actor_set_width (actor4, 250);
clutter_layout_manager_child_set (CLUTTER_LAYOUT_MANAGER (layout),
CLUTTER_CONTAINER (box),
actor1,
"x-expand", FALSE, "y-expand", FALSE,
NULL);
clutter_layout_manager_child_set (CLUTTER_LAYOUT_MANAGER (layout),
CLUTTER_CONTAINER (box),
actor4,
"x-expand", TRUE, "y-expand", TRUE,
"x-fill", TRUE, "y-fill", TRUE,
NULL);
clutter_layout_manager_child_set (CLUTTER_LAYOUT_MANAGER (layout),
CLUTTER_CONTAINER (box),
actor7,
"x-expand", TRUE, "y-expand", TRUE,
"x-fill", FALSE, "y-fill", FALSE,
NULL);
clutter_layout_manager_child_set (CLUTTER_LAYOUT_MANAGER (layout),
CLUTTER_CONTAINER (box),
actor8,
"x-expand", FALSE, "y-expand", FALSE,
NULL);
clutter_layout_manager_child_set (CLUTTER_LAYOUT_MANAGER (layout),
CLUTTER_CONTAINER (box),
actor9,
"x-expand", FALSE, "y-expand", FALSE,
NULL);
clutter_layout_manager_child_set (CLUTTER_LAYOUT_MANAGER (layout),
CLUTTER_CONTAINER (box),
actor2,
"y-fill", FALSE,
"x-fill", FALSE,
NULL);
clutter_actor_set_position (box, 5, 5);
g_signal_connect (actor4, "button-release-event", G_CALLBACK (toggle_expand), box);
g_signal_connect (actor7, "button-release-event", G_CALLBACK (randomise_align), box);
g_signal_connect (actor10, "button-release-event", G_CALLBACK (toggle_visible), NULL);
/* g_signal_connect (stage, "button-press-event", G_CALLBACK (button_press), */
/* box); */
/* g_signal_connect (stage, "motion-event", G_CALLBACK (motion_event), */
/* box); */
/* g_signal_connect (stage, "button-release-event", G_CALLBACK (button_release), */
/* box); */
clutter_actor_show (stage);
g_debug ("table row count = %d",
clutter_table_layout_get_row_count (CLUTTER_TABLE_LAYOUT (layout)));
g_debug ("table column count = %d",
clutter_table_layout_get_column_count (CLUTTER_TABLE_LAYOUT (layout)));
clutter_main ();
return EXIT_SUCCESS;
}