Skip to content

IsItemEdited() and IsItemDeactivatedAfterEdit() unexpected behavior #5777

Closed

Description

@ozlb

Version/Branch of Dear ImGui:
Dear ImGui 1.89 WIP (18830)

Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_opengl2 (not relevant)
Operating System: linux / Win11 (not relevant)

My Issue/Question:
ImGui::IsItemEdited() and ImGui::IsItemDeactivatedAfterEdit() called after ImGui::InputFloat or ImGui::InputInt return false if the value is "changed" with the same value but only when this is less than 10.

With no ImGuiInputTextFlags_:

Initial value == 0
Input 1 -> ImGui::IsItemEdited() == true ... ok
Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok
Input again 1 -> ImGui::IsItemEdited() == false ... ?!?
Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == false ... ?!?

Input 9 -> ImGui::IsItemEdited() == true ... ok
Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok
Input again 9 -> ImGui::IsItemEdited() == false ... ?!?
Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == false ... ?!?

Input 11 -> ImGui::IsItemEdited() == true (2 times)... ok
Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok
Input again 11 -> ImGui::IsItemEdited() == true (2 times)... ok
Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok

Note: Same behavior occurs with negative values > -10

With flag ImGuiInputTextFlags_EnterReturnsTrue:

Initial value == 0
Input 1 -> ImGui::IsItemEdited() == false
Enter/Return key -> ImGui::IsItemEdited() == true and ImGui::IsItemDeactivatedAfterEdit() == true ... ok
Input again 1 -> ImGui::IsItemEdited() == false
Enter/Return key -> ImGui::IsItemEdited() == false and ImGui::IsItemDeactivatedAfterEdit() == false ... ?!?

Input 9 -> ImGui::IsItemEdited() == false
Enter/Return key -> ImGui::IsItemEdited() == true and ImGui::IsItemDeactivatedAfterEdit() == true ... ok
Input again 9 -> ImGui::IsItemEdited() == false
Enter/Return key -> ImGui::IsItemEdited() == false and ImGui::IsItemDeactivatedAfterEdit() == false ... ?!?

Input 11 -> ImGui::IsItemEdited() == false
Enter/Return key -> ImGui::IsItemEdited() == true and ImGui::IsItemDeactivatedAfterEdit() == true ... ok
Input again 11 -> ImGui::IsItemEdited() == false
Enter/Return key -> ImGui::IsItemEdited() == false and ImGui::IsItemDeactivatedAfterEdit() == false ... ?!?

Screenshots/Video

ImGui_IsItemEdited_IsItemDeactivatedAfterEdit.mp4

Standalone, minimal, complete and verifiable example: (see #2261)

	static ImGuiInputTextFlags flags = 0;
	ImGui::CheckboxFlags("ImGuiComboFlags_PopupAlignLeft", &flags, ImGuiInputTextFlags_EnterReturnsTrue);
	
	static float val_f = 0.0;
	static int val_f_editCount = 0;
	static int val_f_changeCount = 0;
	ImGui::InputFloat("ITEM: InputFloat", &val_f, 0.0, 0.0, "%.3f", flags);
	bool val_f_editEvent = ImGui::IsItemEdited();
	bool val_f_changeEvent = ImGui::IsItemDeactivatedAfterEdit();
	if (val_f_editEvent)
		val_f_editCount++;
	if (val_f_changeEvent)
		val_f_changeCount++;
	ImGui::Text("ITEM: InputFloat edit %d, changed %d times", val_f_editCount, val_f_changeCount);

	static int val_int = 0.0;
	static int val_int_editCount = 0;
	static int val_int_changeCount = 0;
	ImGui::InputInt("ITEM: InputInt", &val_int, 0, 0, flags);
	bool val_int_editEvent = ImGui::IsItemEdited();
	bool val_int_changeEvent = ImGui::IsItemDeactivatedAfterEdit();
	if (val_int_editEvent)
		val_int_editCount++;
	if (val_int_changeEvent)
		val_int_changeCount++;
	ImGui::Text("ITEM: InputInt edit %d, changed %d times", val_int_editCount, val_int_changeCount);

Activity

  1. changed the title [-]ImGui::IsItemEdited() and ImGui::IsItemDeactivatedAfterEdit() unexpected behavior[/-] [+]IsItemEdited() and IsItemDeactivatedAfterEdit() unexpected behavior[/+] on Oct 19, 2022
  2. ocornut commented on Jan 10, 2025

    @ocornut
    Owner

    Initial value == 0
    Input 1 -> ImGui::IsItemEdited() == true ... ok
    Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok
    Input again 1 -> ImGui::IsItemEdited() == false ... ?!?
    Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == false ... ?!?
    Input 9 -> ImGui::IsItemEdited() == true ... ok
    Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok
    Input again 9 -> ImGui::IsItemEdited() == false ... ?!?
    Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == false ... ?!?
    Input 11 -> ImGui::IsItemEdited() == true (2 times)... ok
    Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok
    Input again 11 -> ImGui::IsItemEdited() == true (2 times)... ok
    Enter/Return key -> ImGui::IsItemDeactivatedAfterEdit() == true ... ok

    This seems correct. When the value is "1" and you input "1" the value doesn't change. The value goes 1 -> 1.
    When the value is "11" and you try input "11" your keyboard will likely first send "1" two times. So the value goes 11 -> 1 -> 11.

    For the second one:
    InputScalar() based functions seems to have known issue with ImGuiInputTextFlags_EnterReturnsTrue, it essentially never worked correctly, and that's tracked here: #6284

  3. ozlb commented on Mar 11, 2025

    @ozlb
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址