(RGUI) Fix string alignment under UTF8.

This commit is contained in:
Alcaro 2016-02-24 18:50:21 +01:00
parent 67e1c82575
commit d98c7a1c34

View File

@ -192,8 +192,20 @@ static uint32_t string_walk(const char **string)
return ret | (first&15)<<12; return ret | (first&15)<<12;
return ret | (first&7)<<6; return ret | (first&7)<<6;
} }
static size_t utf8len(const char *string)
{
size_t ret = 0;
while (*string)
{
if ((*string & 0xC0) != 0x80) ret++;
string++;
}
return ret;
}
#else #else
#define string_walk string_walkbyte #define string_walk string_walkbyte
#define utf8len strlen
#endif #endif
static void blit_line(int x, int y, static void blit_line(int x, int y,
@ -618,12 +630,13 @@ static void rgui_render(void *data)
snprintf(message, sizeof(message), "%c %-*.*s %-*s", snprintf(message, sizeof(message), "%c %-*.*s %-*s",
entry_selected ? '>' : ' ', entry_selected ? '>' : ' ',
RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2), (int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + strlen(entry_title_buf)),
RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2), (int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + strlen(entry_title_buf)),
entry_title_buf, entry_title_buf,
entry_spacing, entry_spacing,
type_str_buf); type_str_buf);
printf("(%s)%s\n",entry_title_buf,message);
blit_line(x, y, message, blit_line(x, y, message,
entry_selected ? hover_color : normal_color); entry_selected ? hover_color : normal_color);
} }