[layout] Add :homogeneous to FlowLayout
This commit is contained in:
parent
5737cf869f
commit
e5a074fd9e
@ -77,7 +77,8 @@ struct _ClutterFlowLayoutPrivate
|
|||||||
|
|
||||||
gint max_row_items;
|
gint max_row_items;
|
||||||
|
|
||||||
guint layout_wrap : 1;
|
guint layout_wrap : 1;
|
||||||
|
guint is_homogeneous : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -86,6 +87,8 @@ enum
|
|||||||
|
|
||||||
PROP_ORIENTATION,
|
PROP_ORIENTATION,
|
||||||
|
|
||||||
|
PROP_HOMOGENEOUS,
|
||||||
|
|
||||||
PROP_COLUMN_SPACING,
|
PROP_COLUMN_SPACING,
|
||||||
PROP_ROW_SPACING,
|
PROP_ROW_SPACING,
|
||||||
|
|
||||||
@ -272,15 +275,23 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
|
|||||||
line_index += 1;
|
line_index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
clutter_actor_get_preferred_width (child, priv->row_height,
|
if (priv->is_homogeneous)
|
||||||
&child_min,
|
{
|
||||||
&child_natural);
|
item_width = priv->col_width;
|
||||||
item_width = MIN (child_natural, priv->col_width);
|
item_height = priv->row_height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clutter_actor_get_preferred_width (child, priv->row_height,
|
||||||
|
&child_min,
|
||||||
|
&child_natural);
|
||||||
|
item_width = MIN (child_natural, priv->col_width);
|
||||||
|
|
||||||
clutter_actor_get_preferred_height (child, item_width,
|
clutter_actor_get_preferred_height (child, item_width,
|
||||||
&child_min,
|
&child_min,
|
||||||
&child_natural);
|
&child_natural);
|
||||||
item_height = MIN (child_natural, priv->row_height);
|
item_height = MIN (child_natural, priv->row_height);
|
||||||
|
}
|
||||||
|
|
||||||
CLUTTER_NOTE (LAYOUT,
|
CLUTTER_NOTE (LAYOUT,
|
||||||
"flow[line:%d, item:%d/%d] = { %.2f, %.2f, %.2f, %.2f }",
|
"flow[line:%d, item:%d/%d] = { %.2f, %.2f, %.2f, %.2f }",
|
||||||
@ -294,9 +305,9 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
|
|||||||
clutter_actor_allocate (child, &child_alloc, flags);
|
clutter_actor_allocate (child, &child_alloc, flags);
|
||||||
|
|
||||||
if (priv->orientation == CLUTTER_FLOW_HORIZONTAL)
|
if (priv->orientation == CLUTTER_FLOW_HORIZONTAL)
|
||||||
item_x += item_width;
|
item_x += (item_width + priv->col_spacing);
|
||||||
else
|
else
|
||||||
item_y += item_height;
|
item_y += (item_height + priv->row_spacing);
|
||||||
|
|
||||||
line_items_count += 1;
|
line_items_count += 1;
|
||||||
}
|
}
|
||||||
@ -331,6 +342,10 @@ clutter_flow_layout_set_property (GObject *gobject,
|
|||||||
clutter_flow_layout_set_wrap (self, g_value_get_boolean (value));
|
clutter_flow_layout_set_wrap (self, g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_HOMOGENEOUS:
|
||||||
|
clutter_flow_layout_set_homogeneous (self, g_value_get_boolean (value));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_COLUMN_SPACING:
|
case PROP_COLUMN_SPACING:
|
||||||
clutter_flow_layout_set_column_spacing (self, g_value_get_float (value));
|
clutter_flow_layout_set_column_spacing (self, g_value_get_float (value));
|
||||||
break;
|
break;
|
||||||
@ -387,6 +402,10 @@ clutter_flow_layout_get_property (GObject *gobject,
|
|||||||
g_value_set_boolean (value, priv->layout_wrap);
|
g_value_set_boolean (value, priv->layout_wrap);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_HOMOGENEOUS:
|
||||||
|
g_value_set_boolean (value, priv->is_homogeneous);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_COLUMN_SPACING:
|
case PROP_COLUMN_SPACING:
|
||||||
g_value_set_float (value, priv->col_spacing);
|
g_value_set_float (value, priv->col_spacing);
|
||||||
break;
|
break;
|
||||||
@ -459,6 +478,22 @@ clutter_flow_layout_class_init (ClutterFlowLayoutClass *klass)
|
|||||||
G_PARAM_CONSTRUCT);
|
G_PARAM_CONSTRUCT);
|
||||||
g_object_class_install_property (gobject_class, PROP_ORIENTATION, pspec);
|
g_object_class_install_property (gobject_class, PROP_ORIENTATION, pspec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClutterFlowLayout:homogeneous:
|
||||||
|
*
|
||||||
|
* Whether each child inside the #ClutterFlowLayout should receive
|
||||||
|
* the same allocation
|
||||||
|
*
|
||||||
|
* Since: 1.2
|
||||||
|
*/
|
||||||
|
pspec = g_param_spec_boolean ("homogeneous",
|
||||||
|
"Homogeneous",
|
||||||
|
"Whether each item should receive the "
|
||||||
|
"same allocation",
|
||||||
|
FALSE,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class, PROP_HOMOGENEOUS, pspec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClutterFlowLayout:wrap:
|
* ClutterFlowLayout:wrap:
|
||||||
*
|
*
|
||||||
@ -684,6 +719,37 @@ clutter_flow_layout_get_wrap (ClutterFlowLayout *layout)
|
|||||||
return layout->priv->layout_wrap;
|
return layout->priv->layout_wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clutter_flow_layout_set_homogeneous (ClutterFlowLayout *layout,
|
||||||
|
gboolean homogeneous)
|
||||||
|
{
|
||||||
|
ClutterFlowLayoutPrivate *priv;
|
||||||
|
|
||||||
|
g_return_if_fail (CLUTTER_IS_FLOW_LAYOUT (layout));
|
||||||
|
|
||||||
|
priv = layout->priv;
|
||||||
|
|
||||||
|
if (priv->is_homogeneous != homogeneous)
|
||||||
|
{
|
||||||
|
ClutterLayoutManager *manager;
|
||||||
|
|
||||||
|
priv->is_homogeneous = homogeneous;
|
||||||
|
|
||||||
|
manager = CLUTTER_LAYOUT_MANAGER (layout);
|
||||||
|
clutter_layout_manager_layout_changed (manager);
|
||||||
|
|
||||||
|
g_object_notify (G_OBJECT (layout), "homogeneous");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
clutter_flow_layout_get_homogeneous (ClutterFlowLayout *layout)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (CLUTTER_IS_FLOW_LAYOUT (layout), FALSE);
|
||||||
|
|
||||||
|
return layout->priv->is_homogeneous;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
clutter_flow_layout_set_column_spacing (ClutterFlowLayout *layout,
|
clutter_flow_layout_set_column_spacing (ClutterFlowLayout *layout,
|
||||||
gfloat spacing)
|
gfloat spacing)
|
||||||
|
@ -101,6 +101,9 @@ ClutterFlowOrientation clutter_flow_layout_get_orientation (ClutterFlowLayout
|
|||||||
void clutter_flow_layout_set_wrap (ClutterFlowLayout *layout,
|
void clutter_flow_layout_set_wrap (ClutterFlowLayout *layout,
|
||||||
gboolean wrap);
|
gboolean wrap);
|
||||||
gboolean clutter_flow_layout_get_wrap (ClutterFlowLayout *layout);
|
gboolean clutter_flow_layout_get_wrap (ClutterFlowLayout *layout);
|
||||||
|
void clutter_flow_layout_set_homogeneous (ClutterFlowLayout *layout,
|
||||||
|
gboolean homogeneous);
|
||||||
|
gboolean clutter_flow_layout_get_homogeneous (ClutterFlowLayout *layout);
|
||||||
|
|
||||||
void clutter_flow_layout_set_column_spacing (ClutterFlowLayout *layout,
|
void clutter_flow_layout_set_column_spacing (ClutterFlowLayout *layout,
|
||||||
gfloat spacing);
|
gfloat spacing);
|
||||||
|
@ -5,9 +5,13 @@
|
|||||||
|
|
||||||
#define N_RECTS 20
|
#define N_RECTS 20
|
||||||
|
|
||||||
static gboolean vertical = FALSE;
|
static gboolean is_homogeneous = FALSE;
|
||||||
static gboolean random_size = FALSE;
|
static gboolean vertical = FALSE;
|
||||||
static gint n_rects = N_RECTS;
|
static gboolean random_size = FALSE;
|
||||||
|
|
||||||
|
static gint n_rects = N_RECTS;
|
||||||
|
static gint x_spacing = 0;
|
||||||
|
static gint y_spacing = 0;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{
|
{
|
||||||
@ -31,6 +35,27 @@ static GOptionEntry entries[] = {
|
|||||||
&vertical,
|
&vertical,
|
||||||
"Set vertical orientation", NULL
|
"Set vertical orientation", NULL
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,6 +89,12 @@ test_flow_main (int argc, char *argv[])
|
|||||||
|
|
||||||
layout = clutter_flow_layout_new (vertical ? CLUTTER_FLOW_VERTICAL
|
layout = clutter_flow_layout_new (vertical ? CLUTTER_FLOW_VERTICAL
|
||||||
: CLUTTER_FLOW_HORIZONTAL);
|
: CLUTTER_FLOW_HORIZONTAL);
|
||||||
|
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);
|
||||||
|
|
||||||
box = clutter_box_new (layout);
|
box = clutter_box_new (layout);
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user