Chapter 9. Text editing

Table of Contents

ClutterText

Clutter's ClutterText actor can display text and allow it to be edited. It doesn't have as much functionality as, for instance, GTK+'s GtkTextView widget, but it is enough for displaying information and for simple text entry. Therefore it serves the same purposes as GTK+'s GtkLabel or GtkEntry widgets, with the addition of multi line editing.

There are three ways you might use a ClutterText actor:

  • For a simple label, use clutter_text_new_with_text() or clutter_text_set_markup(). To make it non-editable use clutter_text_set_editable().

  • For single line text entry, similar to a GtkEntry in a normal GTK+ application, create a ClutterText using clutter_text_new() and clutter_text_set_single_line_mode(). You may call clutter_text_set_activatable() and connect to the activate signal to react when the user presses Enter.

  • For full-featured multi-line text editing, ClutterText gives you access to the cursor position using the clutter_text_get/set_cursor_*() functions and to the selection using the clutter_text_get/set_selection*() functions. You can also add and remove text at any position.

ClutterText Reference

[Note] Note

When you want the ClutterText to be editable you must give it key focus using clutter_stage_set_key_focus().

Size Management

To discover the size needed by the text inside a ClutterText actor, you may call will the clutter_actor_get_preferred_height() function. This will provide the vertical space necessary to display all of the text at the currently specified width. Alternatively, you could call clutter_actor_get_preferred_width() to discover the horizontal space necessary for the text at the currently specified height.