From 339beafc12eaed3deee31f4af6f13fd8f9b4f1b6 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Sun, 8 Jun 2014 12:44:28 -0700 Subject: [PATCH] Clicking on left half of character selects before, and right half after --- stb_textedit.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stb_textedit.h b/stb_textedit.h index bfe7967..07fadb6 100644 --- a/stb_textedit.h +++ b/stb_textedit.h @@ -400,8 +400,12 @@ static int stb_text_locate_coord(STB_TEXTEDIT_STRING *str, float x, float y) prev_x = r.x0; for (i=0; i < r.num_chars; ++i) { float w = STB_TEXTEDIT_GETWIDTH(str, k, i); - if (x < prev_x+w) - return k+i; + if (x < prev_x+w) { + if (x < prev_x+w/2) + return k+i; + else + return k+i+1; + } prev_x += w; } // shouldn't happen, but if it does, fall through to end-of-line case