From a3a5fe5594301778ec78f161dfeffac113d89901 Mon Sep 17 00:00:00 2001 From: Thomas Wood Date: Thu, 14 May 2009 13:31:51 +0100 Subject: [PATCH] [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 --- clutter/clutter-text.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index 3594e5ec2..e82793ae3 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -1368,7 +1368,7 @@ clutter_text_paint (ClutterActor *self) 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) { @@ -1380,16 +1380,19 @@ clutter_text_paint (ClutterActor *self) } else { - if (text_x <= 0) + if (cursor_x < 0) { - gint diff = -1 * text_x; - - if (cursor_x < diff) - text_x += diff - cursor_x; - else if (cursor_x > (diff + actor_width)) - text_x -= cursor_x - (diff - actor_width); + text_x = text_x - cursor_x - TEXT_PADDING; + } + else if (cursor_x > actor_width) + { + text_x = text_x + (actor_width - cursor_x) - TEXT_PADDING; } } + /* Update the absolute cursor position as it may have moved due to + * scrolling */ + clutter_text_ensure_cursor_position (text); + } else { @@ -1399,6 +1402,8 @@ clutter_text_paint (ClutterActor *self) else text_x = 0; + priv->text_x = text_x; + cursor_paint (text); real_opacity = clutter_actor_get_paint_opacity (self) @@ -1417,7 +1422,6 @@ clutter_text_paint (ClutterActor *self) if (clip_set) cogl_clip_pop (); - priv->text_x = text_x; } static void