Allow using ClutterText as a single line text field. This is useful for
text fields that accept just a single line of contents by default, and
respond to the Enter key press to execute some action.
The :single-line-mode property enables this behaviour inside ClutterText
by clipping and scrolling the contents of the PangoLayout if they do
not fit the allocated width of the Text actor.
When using the delete-prev action from the end of the text we end
up either missing the first glyph we have to delete or falling
through the last one in the text.
This commit fixes both issues.
Since clutter_text_set_text() measures the length of the text
each time, we should use the cached length instead of recomputing
the text length each time. This should save us some time when
dealing with long, multi-byte texts.
Check that the contents of the Text actor are unaffected by the
:password-char property; that the accessors are correct; and finally
that the initial value for a newly constructed Text actor is valid.
Using two properties to set a password entry can be construed as
both cumbersome and a gtk-ism. And rightly so on both counts.
The :text-visible property has also conflicting semantics with the
:cursor-visible one: while the latter hides the cursor, the former
changes the display of the contents of the Text actor. It is, thus,
not a matter of "visibility" but of "rendering".
Instead of setting the :text-visible and :invisible-char properties
to have a password text field, the Text actor should just have a
single :password-char property holding a Unicode character. If the
value of the :password-char is non-zero, the Text actor will use the
Unicode character to render the contents of the text entry.
This commit removes the following methods:
clutter_text_set_text_visible()
clutter_text_get_text_visible()
clutter_text_set_invisible_char()
clutter_text_get_invisible_char()
And the following properties:
ClutterText:text-visible
ClutterText:invisible-char
In favour of:
clutter_text_set_password_char()
clutter_text_get_password_char()
And:
ClutterText:password-char
Thus making obvious what use the property and accessor methods are
for and simplifying the process of creating a simple password text
field to:
text = clutter_text_new ();
clutter_text_set_password_char (CLUTTER_TEXT (text), '*');
The locale translators of Clutter are also the ones that should set
the default direction of the text in a Clutter user interface.
This commit adds a translatable string that defines the direction
of the text; the translation authors will change it to the correct
value and that will determine the default direction.
The default text direction can be overridden by using the
CLUTTER_TEXT_DIRECTION environment variable, or by using the
--clutter-text-direction command line switch. In any other case,
the locale will determine the text direction, as it should.
When updating the PangoContext with the current options (font name,
options, resolution) pass the PangoContext instead of the Clutter
MainContext structure pointer.
When removing a binding entry from the binding pool we should not
only remove it from the hash table, but also from the linked list
we use to iterate over inside the block/unblock_action() pair.
The clutter_binding_pool_list_actions() was not implemented. The
utility of a call listing all the action names is also debatable:
all the functions related to the key bindings take the key symbol
and modifiers -- except the block_action() and unblock_action()
pair.
Sometimes an actor needs to set specific font rendering options on
the PangoContext without changing settings for every other text-rendering
actor.
In order to do this, we need a new public method to create a Pango
context object -- preset with all the default settings -- owned by the
developer and not shared with the rest of Clutter.
This new method is called clutter_actor_create_pango_context(); while
it does not strictly depend on a ClutterActor, it is a good idea to
have it inside the ClutterActor API to map the current get_pango_context()
method and in case we start storing screen-specific data to the Actor
itself during the 1.x API cycle.
The _clutter_context_create_pango_context() should create a new
context; the function returning the PangoContext stored inside the
MainContext structure should be named _get_pango_context() instead.
As of now, a key binding installed into a BindingPool is always there
and cannot be changed.
This is problematic for sub-classes trying to override the callback
or the action for a given key binding.
This commit adds the ability to override the closure for an existing
key binding inside a binding pool -- assumed the caller knows the
key symbol and modifiers used to install the key binding in the first
place.
The direction of the text depends on the locale, and it is the
basic setting needed to enable internationalization of user
interfaces.
This commit allows setting the direction of the PangoContext instance
used by Clutter by using the CLUTTER_TEXT_DIRECTION environment
variable, or by passing the --clutter-text-direction command line
argument. Valid values are:
ltr - for left-to-right locales
rtl - for right-to-left locales
The default is LTR.
Ideally, this should be a value set by the localization teams on the
PO file, but this step requires some build system surgery to allow
the translation of the Clutter strings.
When calling clutter_backend_get_font_name(), if no default font
name has previously been set, we just set the default and return
a pointer to it - like we do for the font options.
Instead of storing the default font name and size as a pre-processor
macro, use the newly added ClutterBackend API to retrieve the current
default font from the backend.
The default backend stores some of the global defaults, like the
font options, text resolution, double click settings. It should also
store the default font name, to allow various text-based actors to
share the same settings.
When the font name changes, the ::font-changed signal is emitted,
to allow actors to pick up the change.
When the ClutterBackend notifies of changes in the resolution or
font options, update the PangoContext stored by Clutter's main
context. This allows changing the backend font-related settings at
runtime.
The PangoContext should be stored once, and inside the main
Clutter context. Each actor for which clutter_actor_get_pango_context()
has been called will hold a reference on the Pango context as well.
This makes it possible to update the text rendering for Clutter
by using only public API.
Rendering text inside an actor is pretty much impossible without
using internal API to create the various pieces like the PangoContext
and the font map.
Each actor should have the ability to create a PangoContext, which
is the only object needed to generate layouts and change the various
Pango settings.
This commit adds a clutter_actor_get_pango_context() function that
creates a PangoContext inside the ClutterActor private data and allows
the creation of PangoLayouts when needed. If the actor already
has a PangoContext, the same instance is returned.
The PangoContext is created only on demand.
The ClutterBackend instance at the moment lacks the ability to
notify runtime changes of the font options and the resolution.
For this reason, this commit adds a ::resolution-changed and a
::font-changed signals to the Backend class.
The ::resolution-changed signal is emitted when set_resolution()
is called with a different DPI; ::font-changed is emitted when the
cairo_font_options_t* changes from the default.
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.
The clutter-private.h header already includes cogl-pango.h with
the correct inclusion path, because the main context stores a
pointer to the font map.
There is no need for clutter-text.c to include cogl-pango.h
again since it already includes clutter-private.h.
After fixing the cursor position issues around the initial
glyph of the layout, the selection position needs fixing as
well.
The fix is similar: check if the position of the selection
is 0 and provide a fast path by setting the offset to 0.
The GTest report output allows the developer to know where exactly
a test unit failure happened. The test-text-cache unit makes it
very hard to pinpoint the exact failure location because it relies
on the output to be printed out - which is not the case when the
tests are run as part of a make check.
This commit makes each sub-test inside the unit fail exactly where
the check function fails, which makes it easier to know which sub-test
did actually fail.
The clutter_text_set_selection() function is a convenience
method for setting the cursor position and the selection
boundary to a given position in a single call, with sanity
checks for the positions.
The clutter_text_get_selection() function was not checking the
passed argument, and was still accessing the contents of the
Text actor using clutter_text_get_text().
This commit also adds the last few gtk-doc annotations missing
from ClutterText.
Instead of repeating the same code for the ::activate signal
emission, use the clutter_text_activate() function inside the
'activate' key binding handler.
The clutter_text_activate() function will emit the ::activate
signal if the :activatable property is set.
This function is useful for subclasses or application code, for
example if we are going to use ::captured-event or ::key-press-event
signal handlers to intercept the Return key and emit the ::activate
signal ourselves.
Instead of installing the line-start and line-end key bindings
using the bare ClutterBindingPool API, we can use the internal
clutter_text_add_move_binding(), which automatically installs
the same key binding with the Shift modifier mask.
This allows selecting when pressing Shift+Home or Shift+End.
The selection behaviour is still incorrect around the zeroeth
position, with all the text after the first line being selected.
We can control the width of the cursor when painting by using
a simple property.
The magic -1 number passed to the setter method will reset the
cursor size to the default one of 2px.
The getter method will return an unsigned integer with the
current size.