UI: Small Corrections to Text Caret Placement

This PR has very slight corrections to text cursor placement in input
widgets. The most important is a check for the situation where the
right edge of the current character can be greater than the left edge
of the next character. This can happen for some thin characters before
a space. Otherwise the code assumes RTL direction and gives an
incorrect placement. This also slightly tightens the position when at
the start of string, just after a space, or at end of the string.

Pull Request: https://projects.blender.org/blender/blender/pulls/127662
This commit is contained in:
Harley Acheson
2024-09-15 21:43:49 +02:00
committed by Harley Acheson
parent 13d30e22a1
commit 2278f8eb1b

View File

@@ -1187,15 +1187,15 @@ int blf_str_offset_to_cursor(
if ((prev.xmax == prev.xmin) && next.xmax) {
/* Nothing (or a space) to the left, so align to right character. */
return next.xmin - int(cursor_width);
return int(float(next.xmin) - (cursor_width / 2.0f));
}
if ((prev.xmax != prev.xmin) && !next.xmax) {
/* End of string, so align to last character. */
return prev.xmax;
return int(float(prev.xmax) - (cursor_width / 2.0f));
}
if (prev.xmax && next.xmax) {
/* Between two characters, so use the center. */
if (next.xmin >= prev.xmax) {
if (next.xmin >= prev.xmax || next.xmin == next.xmax) {
return int((float(prev.xmax + next.xmin) - cursor_width) / 2.0f);
}
/* A nicer center if reversed order - RTL. */