1
0
Fork 0

Use "" as the default value for the :text property

This follows the convention of GtkLabel/GtkEntry in GTK+ and the old
ClutterEntry.

It makes it easier to use strlen/strcmp etc on the output, since we can
assume that it is always a string.

This commit also updates the test unit for ClutterText to verify that
the clutter_text_get_text() function also returns an empty string when
a ClutterText actor has been created.
This commit is contained in:
Emmanuele Bassi 2008-12-22 13:29:10 +00:00
parent 4a934c363c
commit b021f518c1
2 changed files with 11 additions and 4 deletions

View file

@ -1519,7 +1519,7 @@ clutter_text_class_init (ClutterTextClass *klass)
pspec = g_param_spec_string ("text",
"Text",
"The text to render",
NULL,
"",
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_TEXT, pspec);
@ -1981,7 +1981,11 @@ clutter_text_init (ClutterText *self)
for (i = 0; i < N_CACHED_LAYOUTS; i++)
priv->cached_layouts[i].layout = NULL;
priv->text = NULL;
/* default to "" so that clutter_text_get_text() will
* return a valid string and we can safely call strlen()
* or strcmp() on it
*/
priv->text = g_strdup ("");
priv->text_color = default_text_color;
priv->cursor_color = default_cursor_color;
@ -2640,7 +2644,9 @@ clutter_text_get_text (ClutterText *self)
* @self: a #ClutterText
* @text: the text to set
*
* Sets the contents of a #ClutterText actor.
* Sets the contents of a #ClutterText actor. The @text string
* must not be %NULL; to unset the current contents of the
* #ClutterText actor simply pass "" (an empty string).
*
* Since: 1.0
*/

View file

@ -76,7 +76,8 @@ test_text_empty (TestConformSimpleFixture *fixture,
{
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
g_assert (clutter_text_get_text (text) == NULL);
g_assert_cmpstr (clutter_text_get_text (text), ==, "");
g_assert_cmpint (*clutter_text_get_text (text), ==, '\0');
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
clutter_actor_destroy (CLUTTER_ACTOR (text));