CalcTextSize*() tweaks. ImTextCharFromUtf8() return 1 for a zero character now.

This commit is contained in:
ocornut 2015-02-11 12:23:38 +00:00
parent 1da8a52ce7
commit ea94835834

View File

@ -5402,10 +5402,9 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT
for (const char* s = clipboard; *s; ) for (const char* s = clipboard; *s; )
{ {
unsigned int c; unsigned int c;
const int bytes_count = ImTextCharFromUtf8(&c, s, NULL); s += ImTextCharFromUtf8(&c, s, NULL);
if (bytes_count <= 0) if (c == 0)
break; break;
s += bytes_count;
if (c >= 0x10000) if (c >= 0x10000)
continue; continue;
if (InputTextFilterCharacter((ImWchar)c, flags)) if (InputTextFilterCharacter((ImWchar)c, flags))
@ -7351,8 +7350,6 @@ const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
// Convert UTF-8 to 32-bits character, process single character input. // Convert UTF-8 to 32-bits character, process single character input.
// Based on stb_from_utf8() from github.com/nothings/stb/ // Based on stb_from_utf8() from github.com/nothings/stb/
static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end) static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
{
if (*in_text != 0)
{ {
unsigned int c = (unsigned int)-1; unsigned int c = (unsigned int)-1;
const unsigned char* str = (const unsigned char*)in_text; const unsigned char* str = (const unsigned char*)in_text;
@ -7403,7 +7400,6 @@ static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const
*out_char = c; *out_char = c;
return 4; return 4;
} }
}
*out_char = 0; *out_char = 0;
return 0; return 0;
} }
@ -7535,8 +7531,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
while (s < text_end) while (s < text_end)
{ {
unsigned int c; unsigned int c;
const int bytes_count = ImTextCharFromUtf8(&c, s, text_end); const char* next_s = s + ImTextCharFromUtf8(&c, s, text_end);
const char* next_s = s + (bytes_count > 0 ? bytes_count : 1);
if (c == '\n') if (c == '\n')
{ {
@ -7637,8 +7632,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
// Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte) // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
unsigned int c; unsigned int c;
const int bytes_count = ImTextCharFromUtf8(&c, s, text_end); s += ImTextCharFromUtf8(&c, s, text_end);
s += bytes_count > 0 ? bytes_count : 1;
if (c == '\n') if (c == '\n')
{ {
@ -7767,8 +7761,7 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re
// Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte) // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
unsigned int c; unsigned int c;
const int bytes_count = ImTextCharFromUtf8(&c, s, text_end); s += ImTextCharFromUtf8(&c, s, text_end);
s += bytes_count > 0 ? bytes_count : 1;
if (c == '\n') if (c == '\n')
{ {