[clutter/clutter-1.14] clutter-text: Allow setting attributes for editable text
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/clutter-1.14] clutter-text: Allow setting attributes for editable text
- Date: Wed, 16 Jan 2013 22:56:01 +0000 (UTC)
commit 900832383bbe9fc3fccd1a6f947e273dffd9ff8f
Author: Nirbheek Chauhan <nirbheek chauhan collabora co uk>
Date: Tue Dec 18 00:26:57 2012 +0530
clutter-text: Allow setting attributes for editable text
The behaviour imitates GtkEntry and ignores attributes from markup because Pango
barfs on invalid markup. Also add an example to the text-field interactive test.
https://bugzilla.gnome.org/show_bug.cgi?id=686477
clutter/clutter-text.c | 24 +++++++++++-------------
tests/interactive/test-text-field.c | 11 +++++++++--
2 files changed, 20 insertions(+), 15 deletions(-)
---
diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c
index a228c0c..9f50263 100644
--- a/clutter/clutter-text.c
+++ b/clutter/clutter-text.c
@@ -408,15 +408,16 @@ clutter_text_ensure_effective_attributes (ClutterText *self)
if (priv->effective_attrs != NULL)
return;
- /* same as if we don't have any attribute at all */
- if (priv->attrs == NULL && priv->markup_attrs == NULL)
+ /* Same as if we don't have any attribute at all.
+ * We also ignore markup attributes for editable. */
+ if (priv->attrs == NULL && (priv->editable || priv->markup_attrs == NULL))
return;
if (priv->attrs != NULL)
{
- /* If there are no markup attributes then we can just use
- these attributes directly */
- if (priv->markup_attrs == NULL)
+ /* If there are no markup attributes, or if this is editable (in which
+ * case we ignore markup), then we can just use these attrs directly */
+ if (priv->editable || priv->markup_attrs == NULL)
priv->effective_attrs = pango_attr_list_ref (priv->attrs);
else
{
@@ -507,15 +508,12 @@ clutter_text_create_layout_no_cache (ClutterText *text,
else
pango_layout_set_text (layout, contents, contents_len);
- if (!priv->editable)
- {
- /* This will merge the markup attributes and the attributes
- property if needed */
- clutter_text_ensure_effective_attributes (text);
+ /* This will merge the markup attributes and the attributes
+ * property if needed */
+ clutter_text_ensure_effective_attributes (text);
- if (priv->effective_attrs != NULL)
- pango_layout_set_attributes (layout, priv->effective_attrs);
- }
+ if (priv->effective_attrs != NULL)
+ pango_layout_set_attributes (layout, priv->effective_attrs);
pango_layout_set_alignment (layout, priv->alignment);
pango_layout_set_single_paragraph_mode (layout, priv->single_line_mode);
diff --git a/tests/interactive/test-text-field.c b/tests/interactive/test-text-field.c
index 74d7120..18cdfcb 100644
--- a/tests/interactive/test-text-field.c
+++ b/tests/interactive/test-text-field.c
@@ -207,6 +207,7 @@ create_label (const ClutterColor *color,
static ClutterActor *
create_entry (const ClutterColor *color,
const gchar *text,
+ PangoAttrList *attrs,
gunichar password_char,
gint max_length)
{
@@ -227,6 +228,8 @@ create_entry (const ClutterColor *color,
clutter_text_set_max_length (CLUTTER_TEXT (retval), max_length);
clutter_text_set_selected_text_color (CLUTTER_TEXT (retval), &selected_text);
clutter_actor_set_background_color (retval, CLUTTER_COLOR_LightGray);
+ if (attrs)
+ clutter_text_set_attributes (CLUTTER_TEXT (retval), attrs);
g_signal_connect (retval, "activate",
G_CALLBACK (on_entry_activate),
@@ -245,6 +248,7 @@ test_text_field_main (gint argc,
ClutterActor *stage;
ClutterActor *box, *label, *entry;
ClutterLayoutManager *table;
+ PangoAttrList *entry_attrs;
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return EXIT_FAILURE;
@@ -275,7 +279,10 @@ test_text_field_main (gint argc,
"y-expand", FALSE,
NULL);
- entry = create_entry (CLUTTER_COLOR_Black, "<i>some</i> text", 0, 0);
+ entry_attrs = pango_attr_list_new ();
+ pango_attr_list_insert (entry_attrs, pango_attr_underline_new (PANGO_UNDERLINE_ERROR));
+ pango_attr_list_insert (entry_attrs, pango_attr_underline_color_new (65535, 0, 0));
+ entry = create_entry (CLUTTER_COLOR_Black, "somme misspeeled textt", entry_attrs, 0, 0);
clutter_actor_add_child (box, entry);
clutter_layout_manager_child_set (table, CLUTTER_CONTAINER (box), entry,
"row", 0,
@@ -295,7 +302,7 @@ test_text_field_main (gint argc,
"y-expand", FALSE,
NULL);
- entry = create_entry (CLUTTER_COLOR_Black, "password", '*', 8);
+ entry = create_entry (CLUTTER_COLOR_Black, "password", NULL, '*', 8);
clutter_actor_add_child (box, entry);
clutter_layout_manager_child_set (table, CLUTTER_CONTAINER (box), entry,
"row", 1,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]