clutter/flow-layout: Use Orientation enum

Instead of having a custom FlowOrientation one

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3573>
This commit is contained in:
Bilal Elmoussaoui 2024-02-09 14:32:10 +01:00
parent 9bf55cd054
commit cc1957a4ba
6 changed files with 24 additions and 40 deletions

View File

@ -733,22 +733,6 @@ typedef enum /*< prefix=CLUTTER_SCROLL >*/
CLUTTER_SCROLL_SMOOTH CLUTTER_SCROLL_SMOOTH
} ClutterScrollDirection; } ClutterScrollDirection;
/**
* ClutterFlowOrientation:
* @CLUTTER_FLOW_HORIZONTAL: Arrange the children of the flow layout
* horizontally first
* @CLUTTER_FLOW_VERTICAL: Arrange the children of the flow layout
* vertically first
*
* The direction of the arrangement of the children inside
* a #ClutterFlowLayout
*/
typedef enum /*< prefix=CLUTTER_FLOW >*/
{
CLUTTER_FLOW_HORIZONTAL,
CLUTTER_FLOW_VERTICAL
} ClutterFlowOrientation;
/** /**
* ClutterInputDeviceCapabilities: * ClutterInputDeviceCapabilities:
* @CLUTTER_INPUT_CAPABILITY_NONE: No capabilities * @CLUTTER_INPUT_CAPABILITY_NONE: No capabilities

View File

@ -66,7 +66,7 @@ struct _ClutterFlowLayout
ClutterActor *container; ClutterActor *container;
ClutterFlowOrientation orientation; ClutterOrientation orientation;
gfloat col_spacing; gfloat col_spacing;
gfloat row_spacing; gfloat row_spacing;
@ -165,7 +165,7 @@ compute_lines (ClutterFlowLayout *self,
gfloat avail_width, gfloat avail_width,
gfloat avail_height) gfloat avail_height)
{ {
if (self->orientation == CLUTTER_FLOW_HORIZONTAL) if (self->orientation == CLUTTER_ORIENTATION_HORIZONTAL)
return get_columns (self, avail_width); return get_columns (self, avail_width);
else else
return get_rows (self, avail_height); return get_rows (self, avail_height);
@ -230,7 +230,7 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
if (!clutter_actor_is_visible (child)) if (!clutter_actor_is_visible (child))
continue; continue;
if (self->orientation == CLUTTER_FLOW_VERTICAL && for_height > 0) if (self->orientation == CLUTTER_ORIENTATION_VERTICAL && for_height > 0)
{ {
clutter_actor_get_preferred_height (child, -1, clutter_actor_get_preferred_height (child, -1,
&child_min, &child_min,
@ -302,7 +302,7 @@ clutter_flow_layout_get_preferred_width (ClutterLayoutManager *manager,
if (self->col_width < self->min_col_width) if (self->col_width < self->min_col_width)
self->col_width = self->min_col_width; self->col_width = self->min_col_width;
if (self->orientation == CLUTTER_FLOW_VERTICAL && for_height > 0) if (self->orientation == CLUTTER_ORIENTATION_VERTICAL && for_height > 0)
{ {
/* if we have a non-full row we need to add it */ /* if we have a non-full row we need to add it */
if (line_item_count > 0) if (line_item_count > 0)
@ -421,7 +421,7 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
if (!clutter_actor_is_visible (child)) if (!clutter_actor_is_visible (child))
continue; continue;
if (self->orientation == CLUTTER_FLOW_HORIZONTAL && for_width > 0) if (self->orientation == CLUTTER_ORIENTATION_HORIZONTAL && for_width > 0)
{ {
clutter_actor_get_preferred_width (child, -1, clutter_actor_get_preferred_width (child, -1,
&child_min, &child_min,
@ -494,7 +494,7 @@ clutter_flow_layout_get_preferred_height (ClutterLayoutManager *manager,
if (self->row_height < self->min_row_height) if (self->row_height < self->min_row_height)
self->row_height = self->min_row_height; self->row_height = self->min_row_height;
if (self->orientation == CLUTTER_FLOW_HORIZONTAL && for_width > 0) if (self->orientation == CLUTTER_ORIENTATION_HORIZONTAL && for_width > 0)
{ {
/* if we have a non-full row we need to add it */ /* if we have a non-full row we need to add it */
if (line_item_count > 0) if (line_item_count > 0)
@ -618,7 +618,7 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
&item_width, &item_width,
&item_height); &item_height);
if (self->orientation == CLUTTER_FLOW_HORIZONTAL) if (self->orientation == CLUTTER_ORIENTATION_HORIZONTAL)
{ {
if ((self->snap_to_grid && if ((self->snap_to_grid &&
line_item_count == items_per_line && line_item_count > 0) || line_item_count == items_per_line && line_item_count > 0) ||
@ -720,7 +720,7 @@ clutter_flow_layout_allocate (ClutterLayoutManager *manager,
child_alloc.y2 = ceil (child_alloc.y1 + item_height); child_alloc.y2 = ceil (child_alloc.y1 + item_height);
clutter_actor_allocate (child, &child_alloc); clutter_actor_allocate (child, &child_alloc);
if (self->orientation == CLUTTER_FLOW_HORIZONTAL) if (self->orientation == CLUTTER_ORIENTATION_HORIZONTAL)
item_x = new_x; item_x = new_x;
else else
item_y = new_y; item_y = new_y;
@ -745,7 +745,7 @@ clutter_flow_layout_set_container (ClutterLayoutManager *manager,
/* we need to change the :request-mode of the container /* we need to change the :request-mode of the container
* to match the orientation * to match the orientation
*/ */
request_mode = (self->orientation == CLUTTER_FLOW_HORIZONTAL) request_mode = (self->orientation == CLUTTER_ORIENTATION_HORIZONTAL)
? CLUTTER_REQUEST_HEIGHT_FOR_WIDTH ? CLUTTER_REQUEST_HEIGHT_FOR_WIDTH
: CLUTTER_REQUEST_WIDTH_FOR_HEIGHT; : CLUTTER_REQUEST_WIDTH_FOR_HEIGHT;
clutter_actor_set_request_mode (CLUTTER_ACTOR (self->container), clutter_actor_set_request_mode (CLUTTER_ACTOR (self->container),
@ -909,8 +909,8 @@ clutter_flow_layout_class_init (ClutterFlowLayoutClass *klass)
*/ */
flow_properties[PROP_ORIENTATION] = flow_properties[PROP_ORIENTATION] =
g_param_spec_enum ("orientation", NULL, NULL, g_param_spec_enum ("orientation", NULL, NULL,
CLUTTER_TYPE_FLOW_ORIENTATION, CLUTTER_TYPE_ORIENTATION,
CLUTTER_FLOW_HORIZONTAL, CLUTTER_ORIENTATION_HORIZONTAL,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS | G_PARAM_STATIC_STRINGS |
G_PARAM_CONSTRUCT); G_PARAM_CONSTRUCT);
@ -1028,7 +1028,7 @@ clutter_flow_layout_class_init (ClutterFlowLayoutClass *klass)
static void static void
clutter_flow_layout_init (ClutterFlowLayout *self) clutter_flow_layout_init (ClutterFlowLayout *self)
{ {
self->orientation = CLUTTER_FLOW_HORIZONTAL; self->orientation = CLUTTER_ORIENTATION_HORIZONTAL;
self->col_spacing = 0; self->col_spacing = 0;
self->row_spacing = 0; self->row_spacing = 0;
@ -1050,7 +1050,7 @@ clutter_flow_layout_init (ClutterFlowLayout *self)
* Return value: the newly created #ClutterFlowLayout * Return value: the newly created #ClutterFlowLayout
*/ */
ClutterLayoutManager * ClutterLayoutManager *
clutter_flow_layout_new (ClutterFlowOrientation orientation) clutter_flow_layout_new (ClutterOrientation orientation)
{ {
return g_object_new (CLUTTER_TYPE_FLOW_LAYOUT, return g_object_new (CLUTTER_TYPE_FLOW_LAYOUT,
"orientation", orientation, "orientation", orientation,
@ -1070,7 +1070,7 @@ clutter_flow_layout_new (ClutterFlowOrientation orientation)
*/ */
void void
clutter_flow_layout_set_orientation (ClutterFlowLayout *layout, clutter_flow_layout_set_orientation (ClutterFlowLayout *layout,
ClutterFlowOrientation orientation) ClutterOrientation orientation)
{ {
g_return_if_fail (CLUTTER_IS_FLOW_LAYOUT (layout)); g_return_if_fail (CLUTTER_IS_FLOW_LAYOUT (layout));
@ -1087,7 +1087,7 @@ clutter_flow_layout_set_orientation (ClutterFlowLayout *layout,
/* we need to change the :request-mode of the container /* we need to change the :request-mode of the container
* to match the orientation * to match the orientation
*/ */
request_mode = (layout->orientation == CLUTTER_FLOW_HORIZONTAL) request_mode = (layout->orientation == CLUTTER_ORIENTATION_HORIZONTAL)
? CLUTTER_REQUEST_HEIGHT_FOR_WIDTH ? CLUTTER_REQUEST_HEIGHT_FOR_WIDTH
: CLUTTER_REQUEST_WIDTH_FOR_HEIGHT; : CLUTTER_REQUEST_WIDTH_FOR_HEIGHT;
clutter_actor_set_request_mode (CLUTTER_ACTOR (layout->container), clutter_actor_set_request_mode (CLUTTER_ACTOR (layout->container),
@ -1110,11 +1110,11 @@ clutter_flow_layout_set_orientation (ClutterFlowLayout *layout,
* *
* Return value: the orientation of the #ClutterFlowLayout * Return value: the orientation of the #ClutterFlowLayout
*/ */
ClutterFlowOrientation ClutterOrientation
clutter_flow_layout_get_orientation (ClutterFlowLayout *layout) clutter_flow_layout_get_orientation (ClutterFlowLayout *layout)
{ {
g_return_val_if_fail (CLUTTER_IS_FLOW_LAYOUT (layout), g_return_val_if_fail (CLUTTER_IS_FLOW_LAYOUT (layout),
CLUTTER_FLOW_HORIZONTAL); CLUTTER_ORIENTATION_HORIZONTAL);
return layout->orientation; return layout->orientation;
} }

View File

@ -41,13 +41,13 @@ G_DECLARE_FINAL_TYPE (ClutterFlowLayout,
ClutterLayoutManager) ClutterLayoutManager)
CLUTTER_EXPORT CLUTTER_EXPORT
ClutterLayoutManager * clutter_flow_layout_new (ClutterFlowOrientation orientation); ClutterLayoutManager * clutter_flow_layout_new (ClutterOrientation orientation);
CLUTTER_EXPORT CLUTTER_EXPORT
void clutter_flow_layout_set_orientation (ClutterFlowLayout *layout, void clutter_flow_layout_set_orientation (ClutterFlowLayout *layout,
ClutterFlowOrientation orientation); ClutterOrientation orientation);
CLUTTER_EXPORT CLUTTER_EXPORT
ClutterFlowOrientation clutter_flow_layout_get_orientation (ClutterFlowLayout *layout); ClutterOrientation clutter_flow_layout_get_orientation (ClutterFlowLayout *layout);
CLUTTER_EXPORT CLUTTER_EXPORT
void clutter_flow_layout_set_homogeneous (ClutterFlowLayout *layout, void clutter_flow_layout_set_homogeneous (ClutterFlowLayout *layout,
gboolean homogeneous); gboolean homogeneous);

View File

@ -12,7 +12,7 @@ actor_basic_layout (void)
vase = clutter_actor_new (); vase = clutter_actor_new ();
clutter_actor_set_name (vase, "Vase"); clutter_actor_set_name (vase, "Vase");
clutter_actor_set_layout_manager (vase, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); clutter_actor_set_layout_manager (vase, clutter_flow_layout_new (CLUTTER_ORIENTATION_HORIZONTAL));
clutter_actor_add_child (stage, vase); clutter_actor_add_child (stage, vase);
flower[0] = clutter_actor_new (); flower[0] = clutter_actor_new ();

View File

@ -192,7 +192,7 @@ test_content_main (int argc, char *argv[])
clutter_actor_set_margin_right (grid, 12); clutter_actor_set_margin_right (grid, 12);
clutter_actor_set_margin_bottom (grid, 12); clutter_actor_set_margin_bottom (grid, 12);
clutter_actor_set_margin_left (grid, 12); clutter_actor_set_margin_left (grid, 12);
clutter_actor_set_layout_manager (grid, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); clutter_actor_set_layout_manager (grid, clutter_flow_layout_new (CLUTTER_ORIENTATION_HORIZONTAL));
clutter_actor_add_constraint (grid, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0)); clutter_actor_add_constraint (grid, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0));
clutter_actor_add_child (stage, grid); clutter_actor_add_child (stage, grid);

View File

@ -200,7 +200,7 @@ test_image_main (int argc, char *argv[])
clutter_actor_set_margin_right (grid, 12); clutter_actor_set_margin_right (grid, 12);
clutter_actor_set_margin_bottom (grid, 12); clutter_actor_set_margin_bottom (grid, 12);
clutter_actor_set_margin_left (grid, 12); clutter_actor_set_margin_left (grid, 12);
clutter_actor_set_layout_manager (grid, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); clutter_actor_set_layout_manager (grid, clutter_flow_layout_new (CLUTTER_ORIENTATION_HORIZONTAL));
clutter_actor_add_constraint (grid, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0)); clutter_actor_add_constraint (grid, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0));
clutter_actor_add_child (stage, grid); clutter_actor_add_child (stage, grid);