[text] scroll to the cursor position if it is outside the allocation

Adjust the text offset to keep the cursor within the allocation. This means
the text will scroll per character
This commit is contained in:
Thomas Wood 2009-05-14 13:31:51 +01:00
parent cf6c2d9721
commit a3a5fe5594

View File

@ -1368,7 +1368,7 @@ clutter_text_paint (ClutterActor *self)
if (actor_width < text_width) if (actor_width < text_width)
{ {
gint cursor_x = priv->cursor_pos.x; gint cursor_x = priv->cursor_pos.x - alloc.x1;
if (priv->position == -1) if (priv->position == -1)
{ {
@ -1380,16 +1380,19 @@ clutter_text_paint (ClutterActor *self)
} }
else else
{ {
if (text_x <= 0) if (cursor_x < 0)
{ {
gint diff = -1 * text_x; text_x = text_x - cursor_x - TEXT_PADDING;
}
if (cursor_x < diff) else if (cursor_x > actor_width)
text_x += diff - cursor_x; {
else if (cursor_x > (diff + actor_width)) text_x = text_x + (actor_width - cursor_x) - TEXT_PADDING;
text_x -= cursor_x - (diff - actor_width);
} }
} }
/* Update the absolute cursor position as it may have moved due to
* scrolling */
clutter_text_ensure_cursor_position (text);
} }
else else
{ {
@ -1399,6 +1402,8 @@ clutter_text_paint (ClutterActor *self)
else else
text_x = 0; text_x = 0;
priv->text_x = text_x;
cursor_paint (text); cursor_paint (text);
real_opacity = clutter_actor_get_paint_opacity (self) real_opacity = clutter_actor_get_paint_opacity (self)
@ -1417,7 +1422,6 @@ clutter_text_paint (ClutterActor *self)
if (clip_set) if (clip_set)
cogl_clip_pop (); cogl_clip_pop ();
priv->text_x = text_x;
} }
static void static void