我已经用 5a2b1e8 修复了这个问题。
自动回归测试:
https://github.com/ocornut/imgui_test_engine/commit/aa143e9bb4dccf2422bc5aad9d124de95dcb49f5
需要明确的是,我相信这正在改进对接受用户不保留其数据的某种不符合规范的功能的支持,但我确实理解,在没有“延迟提交”/“无实时编辑”的情况下标记可能需要利用这一点。
当/如果我们添加该选项时,根据 InputText() 重写的状态,我们可能希望或需要放弃对用户不保留其数据的支持,如果发生这种情况,我将在其他地方发布说明。
下面是一个交互式测试平台:
ImGui::Begin("#4714");
ImGui::Button("Dummy"); // Dummy button to test earlier item stealing active id without reusing InputText() internal buffer.
{
static ImVec4 color0(1.0f, 0.0f, 0.0f, 1.0f);
static ImVec4 color1(0.0f, 1.0f, 0.0f, 1.0f);
static int edited_ret_frame = -1;
static int edited_ret_field = 0;
static int edited_query_frame = -1;
static int edited_query_field = 0;
static int deactivated_frame = -1;
static int deactivated_field = 0;
if (ImGui::ColorEdit4("color0", &color0.x)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 0; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 0; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 0; }
if (ImGui::ColorEdit4("color1", &color1.x)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 1; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 1; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 1; }
ImGui::Text("Edited (ret) frame %d, field %d", edited_ret_frame, edited_ret_field);
ImGui::Text("Edited (query) frame %d, field %d", edited_query_frame, edited_query_field);
ImGui::Text("Deactivated frame %d, field %d", deactivated_frame, deactivated_field);
}
ImGui::Separator();
{
static ImVec4 w;
static int activated_frame = -1;
static int activated_field = 0;
static int deactivated_frame = -1;
static int deactivated_field = 0;
ImGui::InputFloat("w.x", &w.x, 0, 0, "%.3f", 0);
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 0; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 0; }
ImGui::InputFloat("w.y", &w.y, 0, 0, "%.3f", 0);
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 1; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 1; }
ImGui::InputFloat("w.z", &w.z, 0, 0, "%.3f", 0);
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 2; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 2; }
ImGui::Text("w %.3f %.3f %.3f %.3f", w.x, w.y, w.z, w.w);
ImGui::Text("Activated frame %d, field %d", activated_frame, activated_field);
ImGui::Text("Deactivated frame %d, field %d", deactivated_frame, deactivated_field);
}
ImGui::Separator();
{
static ImVec4 temp;
static int activated_frame = -1;
static int activated_field = 0;
static int edited_ret_frame = -1;
static int edited_ret_field = 0;
static int edited_query_frame = -1;
static int edited_query_field = 0;
static int deactivated_frame = -1;
static int deactivated_field = 0;
ImVec4 v = temp;
//ImVec4& v = temp;
if (ImGui::InputFloat("temp##f4x", &v.x, 0, 0, "%.3f", 0)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 0; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 0; }
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 0; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 0; }
if (ImGui::IsItemDeactivatedAfterEdit())
{
temp = v;
}
if (ImGui::InputFloat("##f4y", &v.y, 0, 0, "%.3f", 0)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 1; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 1; }
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 1; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 1; }
if (ImGui::IsItemDeactivatedAfterEdit())
{
temp = v;
}
if (ImGui::InputFloat("##f4z", &v.z, 0, 0, "%.3f", 0)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 2; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 2; }
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 2; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 2; }
if (ImGui::IsItemDeactivatedAfterEdit())
{
temp = v;
}
ImGui::Text("Temp %.3f %.3f %.3f %.3f", temp.x, temp.y, temp.z, temp.w);
ImGui::Text("Activated frame %d, field %d", activated_frame, activated_field);
ImGui::Text("Edited (ret) frame %d, field %d", edited_ret_frame, edited_ret_field);
ImGui::Text("Edited (query) frame %d, field %d", edited_query_frame, edited_query_field);
ImGui::Text("Deactivated frame %d, field %d", deactivated_frame, deactivated_field);
}
ImGui::Separator();
{
static char buf1[100];
static char buf2[100];
static char buf3[100];
static int activated_frame = -1;
static int activated_field = 0;
static int edited_ret_frame = -1;
static int edited_ret_field = 0;
static int edited_query_frame = -1;
static int edited_query_field = 0;
static int deactivated_frame = -1;
static int deactivated_field = 0;
//ImVec4 v = temp;
//ImVec4& v = temp;
if (ImGui::InputText("##str1", buf1, 100)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 0; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 0; }
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 0; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 0; }
if (ImGui::InputText("##str2", buf2, 100)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 1; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 1; }
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 1; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 1; }
if (ImGui::InputText("##str3", buf3, 100)) { edited_ret_frame = ImGui::GetFrameCount(); edited_ret_field = 2; }
if (ImGui::IsItemEdited()) { edited_query_frame = ImGui::GetFrameCount(); edited_query_field = 2; }
if (ImGui::IsItemActivated()) { activated_frame = ImGui::GetFrameCount(); activated_field = 2; }
if (ImGui::IsItemDeactivatedAfterEdit()) { deactivated_frame = ImGui::GetFrameCount(); deactivated_field = 2; }
ImGui::Text("bufs: \"%s\" \"%s\" \"%s\"", buf1, buf2, buf3);
ImGui::Text("Activated frame %d, field %d", activated_frame, activated_field);
ImGui::Text("Edited (ret) frame %d, field %d", edited_ret_frame, edited_ret_field);
ImGui::Text("Edited (query) frame %d, field %d", edited_query_frame, edited_query_field);
ImGui::Text("Deactivated frame %d, field %d", deactivated_frame, deactivated_field);
}
ImGui::Button("Dummy2");
ImGui::End();