2009-09-18 12:28:02 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gmodule.h>
|
2011-06-10 12:48:54 -04:00
|
|
|
#include <cairo.h>
|
2009-09-18 12:28:02 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#define N_RECTS 20
|
|
|
|
|
2009-10-06 11:17:16 -04:00
|
|
|
static gboolean is_homogeneous = FALSE;
|
|
|
|
static gboolean vertical = FALSE;
|
|
|
|
static gboolean random_size = FALSE;
|
2010-10-12 09:53:20 -04:00
|
|
|
static gboolean fixed_size = FALSE;
|
2013-05-03 11:53:44 -04:00
|
|
|
static gboolean snap_to_grid = TRUE;
|
2009-10-06 11:17:16 -04:00
|
|
|
|
|
|
|
static gint n_rects = N_RECTS;
|
|
|
|
static gint x_spacing = 0;
|
|
|
|
static gint y_spacing = 0;
|
2009-09-18 12:28:02 -04:00
|
|
|
|
|
|
|
static GOptionEntry entries[] = {
|
|
|
|
{
|
|
|
|
"random-size", 'r',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_NONE,
|
|
|
|
&random_size,
|
|
|
|
"Randomly size the rectangles", NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"num-rects", 'n',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_INT,
|
|
|
|
&n_rects,
|
|
|
|
"Number of rectangles", "RECTS"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"vertical", 'v',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_NONE,
|
|
|
|
&vertical,
|
|
|
|
"Set vertical orientation", NULL
|
|
|
|
},
|
2009-10-06 11:17:16 -04:00
|
|
|
{
|
|
|
|
"homogeneous", 'h',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_NONE,
|
|
|
|
&is_homogeneous,
|
|
|
|
"Whether the layout should be homogeneous", NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"x-spacing", 0,
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_INT,
|
|
|
|
&x_spacing,
|
|
|
|
"Horizontal spacing between elements", "PX"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"y-spacing", 0,
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_INT,
|
|
|
|
&y_spacing,
|
|
|
|
"Vertical spacing between elements", "PX"
|
|
|
|
},
|
2010-03-02 10:08:01 -05:00
|
|
|
{
|
2010-10-12 09:53:20 -04:00
|
|
|
"fixed-size", 'f',
|
2010-03-02 10:08:01 -05:00
|
|
|
0,
|
|
|
|
G_OPTION_ARG_NONE,
|
2010-10-12 09:53:20 -04:00
|
|
|
&fixed_size,
|
|
|
|
"Fix the layout size", NULL
|
2010-03-02 10:08:01 -05:00
|
|
|
},
|
2013-05-03 11:53:44 -04:00
|
|
|
{
|
|
|
|
"no-snap-to-grid", 's',
|
|
|
|
G_OPTION_FLAG_REVERSE,
|
|
|
|
G_OPTION_ARG_NONE,
|
|
|
|
&snap_to_grid,
|
|
|
|
"Don't snap elements to grid", NULL
|
|
|
|
},
|
2009-09-18 12:28:02 -04:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2012-05-02 07:14:45 -04:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2009-09-18 12:28:02 -04:00
|
|
|
{
|
|
|
|
ClutterActor *stage, *box;
|
|
|
|
ClutterLayoutManager *layout;
|
|
|
|
GError *error;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
error = NULL;
|
2011-02-22 07:53:15 -05:00
|
|
|
if (clutter_init_with_args (&argc, &argv,
|
|
|
|
NULL,
|
|
|
|
entries,
|
|
|
|
NULL,
|
|
|
|
&error) != CLUTTER_INIT_SUCCESS)
|
2009-09-18 12:28:02 -04:00
|
|
|
{
|
2012-05-02 07:03:14 -04:00
|
|
|
g_print ("Unable to run flow-layout: %s", error->message);
|
2009-09-18 12:28:02 -04:00
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-11-09 08:41:15 -05:00
|
|
|
stage = clutter_stage_new ();
|
2012-02-13 11:47:17 -05:00
|
|
|
clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue);
|
2009-09-18 12:28:02 -04:00
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Flow Layout");
|
2009-10-07 10:30:29 -04:00
|
|
|
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
|
2011-11-09 08:41:15 -05:00
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
2009-09-18 12:28:02 -04:00
|
|
|
|
|
|
|
layout = clutter_flow_layout_new (vertical ? CLUTTER_FLOW_VERTICAL
|
|
|
|
: CLUTTER_FLOW_HORIZONTAL);
|
2009-10-06 11:17:16 -04:00
|
|
|
clutter_flow_layout_set_homogeneous (CLUTTER_FLOW_LAYOUT (layout),
|
|
|
|
is_homogeneous);
|
|
|
|
clutter_flow_layout_set_column_spacing (CLUTTER_FLOW_LAYOUT (layout),
|
|
|
|
x_spacing);
|
|
|
|
clutter_flow_layout_set_row_spacing (CLUTTER_FLOW_LAYOUT (layout),
|
|
|
|
y_spacing);
|
2013-05-03 11:53:44 -04:00
|
|
|
clutter_flow_layout_set_snap_to_grid (CLUTTER_FLOW_LAYOUT (layout),
|
|
|
|
snap_to_grid);
|
2009-09-18 12:28:02 -04:00
|
|
|
|
2012-05-02 07:03:14 -04:00
|
|
|
box = clutter_actor_new ();
|
|
|
|
clutter_actor_set_layout_manager (box, layout);
|
|
|
|
clutter_actor_set_background_color (box, CLUTTER_COLOR_Aluminium2);
|
|
|
|
clutter_actor_add_child (stage, box);
|
2010-08-10 12:43:56 -04:00
|
|
|
|
2010-10-12 09:53:20 -04:00
|
|
|
if (!fixed_size)
|
2011-01-25 06:10:29 -05:00
|
|
|
clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0));
|
2010-08-10 12:43:56 -04:00
|
|
|
|
2009-09-18 12:28:02 -04:00
|
|
|
clutter_actor_set_position (box, 0, 0);
|
|
|
|
clutter_actor_set_name (box, "box");
|
|
|
|
|
|
|
|
for (i = 0; i < n_rects; i++)
|
|
|
|
{
|
2012-05-02 07:03:14 -04:00
|
|
|
ClutterColor color = CLUTTER_COLOR_INIT (255, 255, 255, 255);
|
|
|
|
gfloat width, height;
|
2009-09-18 12:28:02 -04:00
|
|
|
ClutterActor *rect;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("rect%02d", i);
|
|
|
|
|
|
|
|
clutter_color_from_hls (&color,
|
|
|
|
360.0 / n_rects * i,
|
|
|
|
0.5,
|
|
|
|
0.8);
|
2012-05-02 07:03:14 -04:00
|
|
|
rect = clutter_actor_new ();
|
|
|
|
clutter_actor_set_background_color (rect, &color);
|
2009-09-18 12:28:02 -04:00
|
|
|
|
|
|
|
if (random_size)
|
|
|
|
{
|
|
|
|
width = g_random_int_range (50, 100);
|
|
|
|
height = g_random_int_range (50, 100);
|
|
|
|
}
|
|
|
|
else
|
2012-05-02 07:03:14 -04:00
|
|
|
width = height = 50.f;
|
2009-09-18 12:28:02 -04:00
|
|
|
|
|
|
|
clutter_actor_set_size (rect, width, height);
|
|
|
|
clutter_actor_set_name (rect, name);
|
|
|
|
|
2012-05-02 07:03:14 -04:00
|
|
|
clutter_actor_add_child (box, rect);
|
|
|
|
|
2009-09-18 12:28:02 -04:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2012-06-06 08:36:46 -04:00
|
|
|
clutter_actor_show (stage);
|
2009-09-18 12:28:02 -04:00
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|