1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-28 09:30:56 +01:00

ColorEdit4(): removed unnecessary calls to scanf() when idle in hexadecimal edit mode.

This commit is contained in:
ocornut 2016-01-23 11:29:22 +00:00
parent 56927cbb54
commit 2a505ebb9a

View File

@ -8580,18 +8580,19 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
else
ImFormatString(buf, IM_ARRAYSIZE(buf), "#%02X%02X%02X", i[0], i[1], i[2]);
ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x);
value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
if (ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase))
{
value_changed |= true;
char* p = buf;
while (*p == '#' || ImCharIsSpace(*p))
p++;
i[0] = i[1] = i[2] = i[3] = 0;
if (alpha)
sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2], (unsigned int*)&i[3]); // Treat at unsigned (%X is unsigned)
else
sscanf(p, "%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2]);
}
ImGui::PopItemWidth();
char* p = buf;
while (*p == '#' || ImCharIsSpace(*p))
p++;
// Treat at unsigned (%X is unsigned)
i[0] = i[1] = i[2] = i[3] = 0;
if (alpha)
sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2], (unsigned int*)&i[3]);
else
sscanf(p, "%02X%02X%02X", (unsigned int*)&i[0], (unsigned int*)&i[1], (unsigned int*)&i[2]);
}
break;
}