From 2999410af69bff5e27e1203d2288a938bcee8604 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 31 Jul 2012 21:04:20 +0100 Subject: When a text input widget has its text set, and it has the caret, move the caret to the end. --- framebuffer/fbtk/text.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'framebuffer') diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c index 34cb1f9f3..69e82153d 100644 --- a/framebuffer/fbtk/text.c +++ b/framebuffer/fbtk/text.c @@ -461,6 +461,11 @@ fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw) void fbtk_set_text(fbtk_widget_t *widget, const char *text) { + plot_font_style_t font_style; + int c_x, c_y, c_h; + int fh; + int border; + if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_TEXT)) return; if (widget->u.text.text != NULL) { @@ -472,6 +477,22 @@ fbtk_set_text(fbtk_widget_t *widget, const char *text) widget->u.text.len = strlen(text); widget->u.text.idx = widget->u.text.len; + + fb_text_font_style(widget, &fh, &border, &font_style); + nsfont.font_width(&font_style, widget->u.text.text, + widget->u.text.len, &widget->u.text.width); + nsfont.font_width(&font_style, widget->u.text.text, + widget->u.text.idx, &widget->u.text.idx_offset); + + if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) { + /* Widget has caret; move it to end of new string */ + fbtk_set_caret(widget, true, + widget->u.text.idx_offset + border, + border, + widget->height - border - border, + fb_text_input_remove_caret_cb); + } + fbtk_request_redraw(widget); } -- cgit v1.2.3