mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 17:40:40 -05:00
layout: Add BoxLayout, a single line layout manager
The BoxLayout layout manager implements a layout policy for arranging children on a single line, either alongside the X axis or alongside the Y axis.
This commit is contained in:
parent
c4b2d4ce79
commit
b526b76593
1
.gitignore
vendored
1
.gitignore
vendored
@ -135,6 +135,7 @@ TAGS
|
||||
/tests/interactive/test-clutter-cairo-flowers
|
||||
/tests/interactive/test-bin-layout
|
||||
/tests/interactive/test-flow-layout
|
||||
/tests/interactive/test-box-layout
|
||||
/tests/conform/stamp-test-conformance
|
||||
/tests/conform/test-anchors
|
||||
/tests/conform/test-conformance
|
||||
|
@ -67,6 +67,7 @@ source_h = \
|
||||
$(srcdir)/clutter-binding-pool.h \
|
||||
$(srcdir)/clutter-bin-layout.h \
|
||||
$(srcdir)/clutter-box.h \
|
||||
$(srcdir)/clutter-box-layout.h \
|
||||
$(srcdir)/clutter-cairo-texture.h \
|
||||
$(srcdir)/clutter-child-meta.h \
|
||||
$(srcdir)/clutter-clone.h \
|
||||
@ -137,6 +138,7 @@ source_c = \
|
||||
$(srcdir)/clutter-binding-pool.c \
|
||||
$(srcdir)/clutter-bin-layout.c \
|
||||
$(srcdir)/clutter-box.c \
|
||||
$(srcdir)/clutter-box-layout.c \
|
||||
$(srcdir)/clutter-cairo-texture.c \
|
||||
$(srcdir)/clutter-child-meta.c \
|
||||
$(srcdir)/clutter-clone.c \
|
||||
|
1496
clutter/clutter-box-layout.c
Normal file
1496
clutter/clutter-box-layout.c
Normal file
File diff suppressed because it is too large
Load Diff
143
clutter/clutter-box-layout.h
Normal file
143
clutter/clutter-box-layout.h
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 NBTK NbtkBoxLayout 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_BOX_LAYOUT_H__
|
||||
#define __CLUTTER_BOX_LAYOUT_H__
|
||||
|
||||
#include <clutter/clutter-layout-manager.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_BOX_LAYOUT (clutter_box_layout_get_type ())
|
||||
#define CLUTTER_BOX_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BOX_LAYOUT, ClutterBoxLayout))
|
||||
#define CLUTTER_IS_BOX_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BOX_LAYOUT))
|
||||
#define CLUTTER_BOX_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BOX_LAYOUT, ClutterBoxLayoutClass))
|
||||
#define CLUTTER_IS_BOX_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_BOX_LAYOUT))
|
||||
#define CLUTTER_BOX_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_BOX_LAYOUT, ClutterBoxLayoutClass))
|
||||
|
||||
typedef struct _ClutterBoxLayout ClutterBoxLayout;
|
||||
typedef struct _ClutterBoxLayoutPrivate ClutterBoxLayoutPrivate;
|
||||
typedef struct _ClutterBoxLayoutClass ClutterBoxLayoutClass;
|
||||
|
||||
/**
|
||||
* ClutterBoxAlignment:
|
||||
* @CLUTTER_BOX_ALIGNMENT_START: Align the child to the top or to
|
||||
* to the left, depending on the used axis
|
||||
* @CLUTTER_BOX_ALIGNMENT_CENTER: Align the child to the center
|
||||
* @CLUTTER_BOX_ALIGNMENT_END: Align the child to the bottom or to
|
||||
* the right, depending on the used axis
|
||||
*
|
||||
* The alignment policies available on each axis of the #ClutterBoxLayout
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
typedef enum {
|
||||
CLUTTER_BOX_ALIGNMENT_START,
|
||||
CLUTTER_BOX_ALIGNMENT_END,
|
||||
CLUTTER_BOX_ALIGNMENT_CENTER
|
||||
} ClutterBoxAlignment;
|
||||
|
||||
/**
|
||||
* ClutterBoxLayout:
|
||||
*
|
||||
* The #ClutterBoxLayout structure contains only private data
|
||||
* and should be accessed using the provided API
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
struct _ClutterBoxLayout
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterLayoutManager parent_instance;
|
||||
|
||||
ClutterBoxLayoutPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* ClutterBoxLayoutClass:
|
||||
*
|
||||
* The #ClutterBoxLayoutClass structure contains only private
|
||||
* data and should be accessed using the provided API
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
struct _ClutterBoxLayoutClass
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterLayoutManagerClass parent_class;
|
||||
};
|
||||
|
||||
GType clutter_box_layout_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterLayoutManager *clutter_box_layout_new (void);
|
||||
|
||||
void clutter_box_layout_set_spacing (ClutterBoxLayout *layout,
|
||||
guint spacing);
|
||||
guint clutter_box_layout_get_spacing (ClutterBoxLayout *layout);
|
||||
void clutter_box_layout_set_vertical (ClutterBoxLayout *layout,
|
||||
gboolean vertical);
|
||||
gboolean clutter_box_layout_get_vertical (ClutterBoxLayout *layout);
|
||||
void clutter_box_layout_set_pack_start (ClutterBoxLayout *layout,
|
||||
gboolean pack_start);
|
||||
gboolean clutter_box_layout_get_pack_start (ClutterBoxLayout *layout);
|
||||
|
||||
void clutter_box_layout_pack (ClutterBoxLayout *layout,
|
||||
ClutterActor *actor,
|
||||
gboolean expand,
|
||||
gboolean x_fill,
|
||||
gboolean y_fill,
|
||||
ClutterBoxAlignment x_align,
|
||||
ClutterBoxAlignment y_align);
|
||||
void clutter_box_layout_set_alignment (ClutterBoxLayout *layout,
|
||||
ClutterActor *actor,
|
||||
ClutterBoxAlignment x_align,
|
||||
ClutterBoxAlignment y_align);
|
||||
void clutter_box_layout_get_alignment (ClutterBoxLayout *layout,
|
||||
ClutterActor *actor,
|
||||
ClutterBoxAlignment *x_align,
|
||||
ClutterBoxAlignment *y_align);
|
||||
void clutter_box_layout_set_fill (ClutterBoxLayout *layout,
|
||||
ClutterActor *actor,
|
||||
gboolean x_fill,
|
||||
gboolean y_fill);
|
||||
void clutter_box_layout_get_fill (ClutterBoxLayout *layout,
|
||||
ClutterActor *actor,
|
||||
gboolean *x_fill,
|
||||
gboolean *y_fill);
|
||||
void clutter_box_layout_set_expand (ClutterBoxLayout *layout,
|
||||
ClutterActor *actor,
|
||||
gboolean expand);
|
||||
gboolean clutter_box_layout_get_expand (ClutterBoxLayout *layout,
|
||||
ClutterActor *actor);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_BOX_LAYOUT_H__ */
|
@ -45,6 +45,7 @@
|
||||
#include "clutter-binding-pool.h"
|
||||
#include "clutter-bin-layout.h"
|
||||
#include "clutter-box.h"
|
||||
#include "clutter-box-layout.h"
|
||||
#include "clutter-cairo-texture.h"
|
||||
#include "clutter-child-meta.h"
|
||||
#include "clutter-clone.h"
|
||||
|
@ -45,7 +45,8 @@ UNIT_TESTS = \
|
||||
test-clutter-cairo-flowers.c \
|
||||
test-cogl-vertex-buffer.c \
|
||||
test-bin-layout.c \
|
||||
test-flow-layout.c
|
||||
test-flow-layout.c \
|
||||
test-box-layout.c
|
||||
|
||||
if X11_TESTS
|
||||
UNIT_TESTS += test-pixmap.c
|
||||
|
207
tests/interactive/test-box-layout.c
Normal file
207
tests/interactive/test-box-layout.c
Normal file
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2009 Intel Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU Lesser General Public License,
|
||||
* version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gmodule.h>
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
static ClutterActor *hover_actor = NULL;
|
||||
|
||||
static void
|
||||
enter_event (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer data)
|
||||
{
|
||||
ClutterColor color = { 0x00, 0x00, 0x00, 0xff };
|
||||
|
||||
clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (actor), 2);
|
||||
clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (actor), &color);
|
||||
|
||||
hover_actor = actor;
|
||||
}
|
||||
|
||||
static void
|
||||
leave_event (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer data)
|
||||
{
|
||||
clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (actor), 0);
|
||||
|
||||
hover_actor = NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
button_release_event (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
ClutterBoxLayout *box)
|
||||
{
|
||||
gboolean xfill, yfill;
|
||||
ClutterBoxAlignment xalign, yalign;
|
||||
gint button;
|
||||
|
||||
button = clutter_event_get_button (event);
|
||||
|
||||
if (button == 1)
|
||||
{
|
||||
clutter_box_layout_get_fill (box, actor, &xfill, &yfill);
|
||||
clutter_box_layout_set_fill (box, actor,
|
||||
xfill ? FALSE : TRUE,
|
||||
yfill ? FALSE : TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
clutter_box_layout_get_alignment (box, actor, &xalign, &yalign);
|
||||
|
||||
if (xalign < 2)
|
||||
xalign += 1;
|
||||
else
|
||||
xalign = 0;
|
||||
|
||||
if (yalign < 2)
|
||||
yalign += 1;
|
||||
else
|
||||
yalign = 0;
|
||||
|
||||
clutter_box_layout_set_alignment (box, actor, xalign, yalign);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
add_actor (ClutterBoxLayout *box)
|
||||
{
|
||||
ClutterActor *rect;
|
||||
ClutterColor color = { 0xff, 0xff, 0xff, 255 };
|
||||
static gboolean expand = TRUE;
|
||||
|
||||
clutter_color_from_hls (&color,
|
||||
g_random_double_range (0.0, 360.0),
|
||||
0.5,
|
||||
0.5);
|
||||
|
||||
rect = clutter_rectangle_new_with_color (&color);
|
||||
clutter_actor_set_size (rect, 32, 64);
|
||||
clutter_box_layout_pack (box, rect, expand,
|
||||
FALSE, /* x-fill */
|
||||
FALSE, /* y-fill */
|
||||
CLUTTER_BOX_ALIGNMENT_CENTER,
|
||||
CLUTTER_BOX_ALIGNMENT_CENTER);
|
||||
|
||||
clutter_actor_set_reactive (rect, TRUE);
|
||||
g_signal_connect (rect, "enter-event", G_CALLBACK (enter_event), NULL);
|
||||
g_signal_connect (rect, "leave-event", G_CALLBACK (leave_event), NULL);
|
||||
g_signal_connect (rect, "button-release-event",
|
||||
G_CALLBACK (button_release_event),
|
||||
box);
|
||||
|
||||
expand = !expand;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
key_release_cb (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
ClutterBoxLayout *layout)
|
||||
{
|
||||
gboolean toggle;
|
||||
guint spacing;
|
||||
|
||||
switch (clutter_event_get_key_symbol (event))
|
||||
{
|
||||
case CLUTTER_v:
|
||||
toggle = clutter_box_layout_get_vertical (layout);
|
||||
clutter_box_layout_set_vertical (layout, !toggle);
|
||||
break;
|
||||
|
||||
case CLUTTER_p:
|
||||
toggle = clutter_box_layout_get_pack_start (layout);
|
||||
clutter_box_layout_set_pack_start (layout, !toggle);
|
||||
break;
|
||||
|
||||
case CLUTTER_s:
|
||||
spacing = clutter_box_layout_get_spacing (layout);
|
||||
|
||||
if (spacing > 12)
|
||||
spacing = 0;
|
||||
else
|
||||
spacing++;
|
||||
|
||||
clutter_box_layout_set_spacing (layout, spacing);
|
||||
break;
|
||||
|
||||
case '+':
|
||||
add_actor (layout);
|
||||
break;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
stage_size_changed_cb (ClutterActor *stage,
|
||||
const ClutterActorBox *allocation,
|
||||
ClutterAllocationFlags flags,
|
||||
ClutterActor *box)
|
||||
{
|
||||
gfloat width, height;
|
||||
|
||||
clutter_actor_box_get_size (allocation, &width, &height);
|
||||
clutter_actor_set_size (box, width - 100, height - 100);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT int
|
||||
test_box_layout_main (int argc, char *argv[])
|
||||
{
|
||||
ClutterActor *stage, *box;
|
||||
ClutterLayoutManager *layout;
|
||||
gint i;
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_stage_set_title (CLUTTER_STAGE (stage), "Box Layout");
|
||||
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
|
||||
clutter_actor_set_size (stage, 640, 480);
|
||||
|
||||
layout = clutter_box_layout_new ();
|
||||
|
||||
box = clutter_box_new (layout);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
||||
|
||||
for (i = 0; i < 5; i++)
|
||||
add_actor (CLUTTER_BOX_LAYOUT (layout));
|
||||
|
||||
g_signal_connect (stage, "key-release-event",
|
||||
G_CALLBACK (key_release_cb),
|
||||
layout);
|
||||
g_signal_connect (stage, "allocation-changed",
|
||||
G_CALLBACK (stage_size_changed_cb),
|
||||
box);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user