Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors with io.KeysDown[] after update #8317

Closed
MajdevInc opened this issue Jan 13, 2025 · 1 comment
Closed

Errors with io.KeysDown[] after update #8317

MajdevInc opened this issue Jan 13, 2025 · 1 comment

Comments

@MajdevInc
Copy link

MajdevInc commented Jan 13, 2025

Hello,
I am in the process of updating my project from ImGui version 1.91.1 to 1.91.6. However, I have encountered a few errors. I have reviewed the documentation, but I am unsure how to resolve these issues. I would like to share the parts of the code that are causing errors and kindly ask if you could review them and provide assistance.
The following sections of the code are generating errors:

if (hovered && io.MouseClicked[0]) {
	if (g.ActiveId != id) {
		memset(io.MouseDown, 0, sizeof(io.MouseDown));
		memset(io.KeysDown, 0, sizeof(io.KeysDown)); //class "ImGuiIO" has no member "KeysDown"
		*key = 0;
	}
	ImGui::SetActiveID(id, window);
	ImGui::FocusWindow(window);
}

if (!value_changed) {
	for (auto i = 0x08; i <= 0xA5; i++) {
		if (io.KeysDown[i]) { //class "ImGuiIO" has no member "KeysDown"
			k = i;
			value_changed = true;
			ImGui::ClearActiveID();
		}
	}
}

if ((flags & ImGuiSelectableFlags_AllowOverlap) || (g.LastItemData.InFlags & ImGuiItemFlags_AllowOverlap)) { button_flags |= ImGuiButtonFlags_AllowOverlap; } //class "ImGuiLastItemData" has no member "InFlags"

if (pressed || (hovered && (flags & ImGuiSelectableFlags_SetNavIdOnHover))) {
	if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent) { //class "ImGuiContext" has no member "NavDisableMouseHover"
		ImGui::SetNavID(id, window->DC.NavLayerCurrent, g.CurrentFocusScopeId, ImGui::WindowRectAbsToRel(window, bb));
		g.NavDisableHighlight = true;//class "ImGuiContext" has no member "NavDisableHighlight"
	}
}

bool hovered = ImGui::ItemHoverable(frame_bb, id, g.LastItemData.InFlags), held, pressed = ImGui::ButtonBehavior(frame_bb, id, &hovered, &held, NULL); //class "ImGuiLastItemData" has no member "InFlags"

I would greatly appreciate any insights or suggestions you may have regarding these issues.
Thank you for your time and support.

@ocornut ocornut changed the title ImGui Güncellemesi Sonrası hatalar Errors with io.KeysDown[] after update Jan 13, 2025
@ocornut
Copy link
Owner

ocornut commented Jan 13, 2025

Hello,

If you search for KeysDown in the codebase you'll find various references to #4921 but I agree there are not enough direct/explicit mention that you should use ImGui::IsKeyDown() to poll keys. I've added a few new comments.
io.KeysDown[] has been made obsolete in February 2022.

if (hovered && io.MouseClicked[0]) {
	if (g.ActiveId != id) {
		memset(io.MouseDown, 0, sizeof(io.MouseDown));
		memset(io.KeysDown, 0, sizeof(io.KeysDown)); //class "ImGuiIO" has no member "KeysDown"
		*key = 0;
	}
	ImGui::SetActiveID(id, window);
	ImGui::FocusWindow(window);
}

if (!value_changed) {
	for (auto i = 0x08; i <= 0xA5; i++) {
		if (io.KeysDown[i]) { //class "ImGuiIO" has no member "KeysDown"
			k = i;
			value_changed = true;
			ImGui::ClearActiveID();
		}
	}
}

I would really want to question what the first block is for (it's trying to clear all key information). io.ClearInputKeys() seems similar, but I cannot guide to toward the correct solution if I don't exactly know what the code is trying to achieve and the context for it (you can open a new issue for it after you researched it enough).

The for (auto i = 0x08; i <= 0xA5; i++) { values would refer to legacy, backend-dependent keycodes.
You have not filled the request issue template so I don't know what backend they refer to, but #4921 explains the transition that started happening 3 years ago. You should use ImGuiKey_ enums for this.

if ((flags & ImGuiSelectableFlags_AllowOverlap) || (g.LastItemData.InFlags & ImGuiItemFlags_AllowOverlap)) { button_flags |= ImGuiButtonFlags_AllowOverlap; }
//class "ImGuiLastItemData" has no member "InFlags"

If you look inside ImGuiLastItemData you'll find what this was renamed into (e6b5caf).
This is using imgui_internal.h which provides no guarantee of backward/forward compatibility, if you use it you are expected to be able to browse a C++ codebase to find answers.

If you search for NavDisableMouseHover and NavDisableHighlight in the codebase you'll also find references to what they changed into (23b655f, 0bae2db). Please make more use of your IDE search function and follow symbols to find information :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants