diff options
author | Dave Davenport <qball@gmpclient.org> | 2017-06-03 18:39:37 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2017-06-03 18:39:37 +0200 |
commit | 5bc8ea29a507888c6ccd11daa198c1bb02fdc544 (patch) | |
tree | ac09a9d662238ca1b7ad5c48192090cf29cd196e | |
parent | 8b7ceb92865e34aaf1db018582d05f7166962c4c (diff) |
Fix converting x,y to cursor position.
-rw-r--r-- | source/widgets/textbox.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 56bc8837..ac4ecfa0 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -115,8 +115,17 @@ static WidgetTriggerActionResult textbox_editable_trigger_action ( widget *wid, case MOUSE_CLICK_DOWN: { gint i; - pango_layout_xy_to_index ( tb->layout, x * PANGO_SCALE, y * PANGO_SCALE, &i, NULL ); - textbox_cursor ( tb, i ); + // substract padding on left. + x -= widget_padding_get_left ( wid ); + gint max = textbox_get_font_width ( tb ); + // Right of text, move to end. + if ( x >= max ){ + textbox_cursor_end ( tb ); + } else if ( x > 0 ) { + // If in range, get index. + pango_layout_xy_to_index ( tb->layout, x * PANGO_SCALE, y * PANGO_SCALE, &i, NULL ); + textbox_cursor ( tb, i ); + } return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; } case MOUSE_CLICK_UP: |