* it must contain the center of rotation as described by two coordinates:
* Y and Z for "x-axis"; X and Z for "y-axis"; and X and Y for
* "z-axis".</para>
+ * <para>#ClutterActor also defines a scriptable "margin" property which
+ * follows the CSS "margin" shorthand.
+ * <informalexample>
+ * <programlisting>
+ * // 4 values
+ * "margin" : [ <top>, <right>, <bottom> <left> ]
+ * // 3 values
+ * "margin" : [ <top>, <left/right>, <bottom> ]
+ * // 2 values
+ * "margin" : [ <top/bottom>, <left/right> ]
+ * // 1 value
+ * "margin" : [ <top/right/bottom/left> ]
+ * </programlisting>
+ * </informalexample>
+ * </para>
* <para>#ClutterActor will also parse every positional and dimensional
* property defined as a string through clutter_units_from_string(); you
* should read the documentation for the #ClutterUnits parser format for
return g_slist_reverse (retval);
}
+static ClutterMargin *
+parse_margin (ClutterActor *self,
+ JsonNode *node)
+{
+ ClutterMargin *margin;
+ JsonArray *array;
+
+ if (!JSON_NODE_HOLDS_ARRAY (node))
+ {
+ g_warning ("The margin property must be an array of 1 to 4 elements");
+ return NULL;
+ }
+
+ margin = clutter_margin_new ();
+ array = json_node_get_array (node);
+ switch (json_array_get_length (array))
+ {
+ case 1:
+ margin->top = margin->right = margin->bottom = margin->left =
+ parse_units (self, 0, json_array_get_element (array, 0));
+ break;
+
+ case 2:
+ margin->top = margin->bottom =
+ parse_units (self, 0, json_array_get_element (array, 0));
+ margin->right = margin->left =
+ parse_units (self, 0, json_array_get_element (array, 1));
+ break;
+
+ case 3:
+ margin->top =
+ parse_units (self, 0, json_array_get_element (array, 0));
+ margin->right = margin->left =
+ parse_units (self, 0, json_array_get_element (array, 1));
+ margin->bottom =
+ parse_units (self, 0, json_array_get_element (array, 2));
+ break;
+
+ case 4:
+ margin->top =
+ parse_units (self, 0, json_array_get_element (array, 0));
+ margin->right =
+ parse_units (self, 0, json_array_get_element (array, 1));
+ margin->bottom =
+ parse_units (self, 0, json_array_get_element (array, 2));
+ margin->left =
+ parse_units (self, 0, json_array_get_element (array, 3));
+ break;
+
+ default:
+ g_warning ("The margin property must be an array of 1 to 4 elements");
+ clutter_margin_free (margin);
+ return NULL;
+ }
+ return margin;
+}
+
static gboolean
clutter_actor_parse_custom_node (ClutterScriptable *scriptable,
ClutterScript *script,
retval = TRUE;
}
+ else if (strcmp (name, "margin") == 0)
+ {
+ ClutterMargin *margin = parse_margin (actor, node);
+
+ if (margin)
+ {
+ g_value_init (value, CLUTTER_TYPE_MARGIN);
+ g_value_set_boxed (value, margin);
+ retval = TRUE;
+ }
+ }
return retval;
}
return;
}
+ if (strcmp (name, "margin") == 0)
+ {
+ clutter_actor_set_margin (actor, g_value_get_boxed (value));
+ return;
+ }
g_object_set_property (G_OBJECT (scriptable), name, value);
}
g_object_unref (script);
}
+
+script_margin (TestConformSimpleFixture *fixture,
+ gpointer dummy)
+{
+ ClutterScript *script = clutter_script_new ();
+ ClutterActor *actor;
+ gchar *test_file;
+ GError *error = NULL;
+
+ test_file = clutter_test_get_data_file ("test-script-margin.json");
+ clutter_script_load_from_file (script, test_file, &error);
+ if (g_test_verbose () && error)
+ g_print ("Error: %s", error->message);
+
+ g_assert_no_error (error);
+
+ actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-1"));
+ g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 10.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 10.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 10.0f);
+
+ actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-2"));
+ g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 10.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 20.0f);
+
+ actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-3"));
+ g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 30.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 20.0f);
+
+ actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-4"));
+ g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 30.0f);
+ g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 40.0f);
+
+ g_object_unref (script);
+ g_free (test_file);
+}
+
TEST_CONFORM_SIMPLE ("/script", animator_properties);
TEST_CONFORM_SIMPLE ("/script", animator_multi_properties);
TEST_CONFORM_SIMPLE ("/script", state_base);
+ TEST_CONFORM_SIMPLE ("/script", script_margin);
TEST_CONFORM_SIMPLE ("/timeline", timeline_base);
TEST_CONFORM_SIMPLE ("/timeline", timeline_markers_from_script);
test-animator-3.json \
test-state-1.json \
test-script-timeline-markers.json \
+ test-script-margin.json \
$(NULL)
png_files = \
--- /dev/null
+[
+ {
+ "id" : "actor-1",
+ "type" : "ClutterActor",
+ "margin" : [ 10 ]
+ },
+ {
+ "id" : "actor-2",
+ "type" : "ClutterActor",
+ "margin" : [ 10, 20 ]
+ },
+ {
+ "id" : "actor-3",
+ "type" : "ClutterActor",
+ "margin" : [ 10, 20, 30 ]
+ },
+ {
+ "id" : "actor-4",
+ "type" : "ClutterActor",
+ "margin" : [ 10, 20, 30, 40]
+ }
+]