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