[layout] Add :homogeneous to FlowLayout
This commit is contained in:
parent
5737cf869f
commit
e5a074fd9e
@ -77,7 +77,8 @@ struct _ClutterFlowLayoutPrivate
|
||||
|
||||
gint max_row_items;
|
||||
|
||||
guint layout_wrap : 1;
|
||||
guint layout_wrap : 1;
|
||||
guint is_homogeneous : 1;
|
||||
};
|
||||
|
||||
enum
|
||||
@ -86,6 +87,8 @@ enum
|
||||
|
||||
PROP_ORIENTATION,
|
||||
|
||||
PROP_HOMOGENEOUS,
|
||||
|
||||
PROP_COLUMN_SPACING,
|
||||
PROP_ROW_SPACING,
|
||||
|
||||
@ -272,15 +275,23 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
|
||||
line_index += 1;
|
||||
}
|
||||
|
||||
clutter_actor_get_preferred_width (child, priv->row_height,
|
||||
&child_min,
|
||||
&child_natural);
|
||||
item_width = MIN (child_natural, priv->col_width);
|
||||
if (priv->is_homogeneous)
|
||||
{
|
||||
item_width = 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,
|
||||
&child_min,
|
||||
&child_natural);
|
||||
item_height = MIN (child_natural, priv->row_height);
|
||||
clutter_actor_get_preferred_height (child, item_width,
|
||||
&child_min,
|
||||
&child_natural);
|
||||
item_height = MIN (child_natural, priv->row_height);
|
||||
}
|
||||
|
||||
CLUTTER_NOTE (LAYOUT,
|
||||
"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);
|
||||
|
||||
if (priv->orientation == CLUTTER_FLOW_HORIZONTAL)
|
||||
item_x += item_width;
|
||||
item_x += (item_width + priv->col_spacing);
|
||||
else
|
||||
item_y += item_height;
|
||||
item_y += (item_height + priv->row_spacing);
|
||||
|
||||
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));
|
||||
break;
|
||||
|
||||
case PROP_HOMOGENEOUS:
|
||||
clutter_flow_layout_set_homogeneous (self, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_COLUMN_SPACING:
|
||||
clutter_flow_layout_set_column_spacing (self, g_value_get_float (value));
|
||||
break;
|
||||
@ -387,6 +402,10 @@ clutter_flow_layout_get_property (GObject *gobject,
|
||||
g_value_set_boolean (value, priv->layout_wrap);
|
||||
break;
|
||||
|
||||
case PROP_HOMOGENEOUS:
|
||||
g_value_set_boolean (value, priv->is_homogeneous);
|
||||
break;
|
||||
|
||||
case PROP_COLUMN_SPACING:
|
||||
g_value_set_float (value, priv->col_spacing);
|
||||
break;
|
||||
@ -459,6 +478,22 @@ clutter_flow_layout_class_init (ClutterFlowLayoutClass *klass)
|
||||
G_PARAM_CONSTRUCT);
|
||||
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:
|
||||
*
|
||||
@ -684,6 +719,37 @@ clutter_flow_layout_get_wrap (ClutterFlowLayout *layout)
|
||||
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
|
||||
clutter_flow_layout_set_column_spacing (ClutterFlowLayout *layout,
|
||||
gfloat spacing)
|
||||
|
@ -101,6 +101,9 @@ ClutterFlowOrientation clutter_flow_layout_get_orientation (ClutterFlowLayout
|
||||
void clutter_flow_layout_set_wrap (ClutterFlowLayout *layout,
|
||||
gboolean wrap);
|
||||
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,
|
||||
gfloat spacing);
|
||||
|
@ -5,9 +5,13 @@
|
||||
|
||||
#define N_RECTS 20
|
||||
|
||||
static gboolean vertical = FALSE;
|
||||
static gboolean random_size = FALSE;
|
||||
static gint n_rects = N_RECTS;
|
||||
static gboolean is_homogeneous = FALSE;
|
||||
static gboolean vertical = FALSE;
|
||||
static gboolean random_size = FALSE;
|
||||
|
||||
static gint n_rects = N_RECTS;
|
||||
static gint x_spacing = 0;
|
||||
static gint y_spacing = 0;
|
||||
|
||||
static GOptionEntry entries[] = {
|
||||
{
|
||||
@ -31,6 +35,27 @@ static GOptionEntry entries[] = {
|
||||
&vertical,
|
||||
"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 }
|
||||
};
|
||||
|
||||
@ -64,6 +89,12 @@ test_flow_main (int argc, char *argv[])
|
||||
|
||||
layout = clutter_flow_layout_new (vertical ? CLUTTER_FLOW_VERTICAL
|
||||
: 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);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
||||
|
Loading…
x
Reference in New Issue
Block a user