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

InputText input stealing #1600

Closed
LemonHaze420 opened this issue Feb 7, 2018 · 10 comments
Closed

InputText input stealing #1600

LemonHaze420 opened this issue Feb 7, 2018 · 10 comments

Comments

@LemonHaze420
Copy link

Currently having issues when toggling a chat box we've made using ImGui. It works fine on it's first run, but after this, every time the chatbox is toggled with 'T', a lowercase 'T' can be seen at the beginning of the chatbox.

	if (this->chatToggled)
	{
		ImGuiStyle& style = ImGui::GetStyle();
		ImGui::SetNextWindowFocus();
		ImGui::SetNextWindowPos(ImVec2(30, (float)gRender->MeasureText("Y").cy * 10 + 20));
		ImGui::SetNextWindowBgAlpha(-1.0f);
		style.WindowBorderSize = 0.0f;
		ImGui::Begin("A", &this->chatToggled, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
		ImGui::PushItemWidth(350.0f);
		ImGui::SetKeyboardFocusHere(); 
		if (ImGui::InputText("", this->chatInputBuffer, 256, ImGuiInputTextFlags_EnterReturnsTrue, NULL, this->chatInputBuffer))
		{
			char* input_end = this->chatInputBuffer + strlen(this->chatInputBuffer);
			while (input_end > this->chatInputBuffer && input_end[-1] == ' ') { input_end--; } *input_end = 0;
			if (this->chatInputBuffer[0])
			{
				ProcessChatInput();
				strcpy(this->chatInputBuffer, "");
			}
			this->chatToggled = false;
		}

		ImGui::PopItemWidth();
		ImGui::End();
		style.WindowBorderSize = 1.0f;
	}
@ocornut
Copy link
Owner

ocornut commented Feb 7, 2018

Hello,

You are missing a proper repro (or MCVE, see: https://stackoverflow.com/help/mcve) and there isn't enough information in your post to infer anything. Please provide one.

every time the chatbox is toggled with 'T', a lowercase 'T' can be seen at the beginning of the chatbox.

It seems normal that if you press T on the keyboard the InputText() would receive it, isn't that the desirable behavior of InputText() ? If anything, it could be a bug that the first time the character isn't received by the InputText(), presumably because the widget is clipped during the initial window sizing.

InputText() gets its data from the io.InputCharacters[] buffer which is filled via io.AddInputCharacter() in your back-end code, typically on character inputs events like WM_CHAR.

@LemonHaze420
Copy link
Author

Sorry, I thought the code I posted was more than enough?

I've tried using ImGui::GetIO().ClearInputCharacters() once the chat has been toggled and still nothing.

@ocornut
Copy link
Owner

ocornut commented Feb 7, 2018

Sorry, I thought the code I posted was more than enough?

It's not if I cannot reproduce your issue on my end.
An ideal MCVE repro would a bit of code I can paste or patch into one of the examples and I can witness the bug. Mind you, one of the purpose of the repro (apart from respecting my time) is that the majority of times by constructing one and narrowing down your issue to its core, you will find the answer to your question.

Experienced users have more leeway and possibilities to explain their bug without a repro, but if you are not able to, then the repro is the best thing you can do.

I've tried using ImGui::GetIO().ClearInputCharacters() once the chat has been toggled and still nothing.

It seems like the correct solution to me, so if it doesn't work you are maybe doing something wrong.?

@LemonHaze420
Copy link
Author

I guess we'll have to discontinue using ImGui, then. Because I've tried almost everything and it simply does not work, or must just be counter-intuitive.

@ocornut
Copy link
Owner

ocornut commented Feb 7, 2018

As you wish. I literally gave you the fastest path to finding a solution and your answer is "we'll have to discontinue using ImGui". You can't say you have tried almost everything when you haven't tried the thing that I suggested you do.

@LemonHaze420
Copy link
Author

I've tried using ClearInputCharacters(), clearing the buffer used by ImGui, toggling the InputText and then setting focus to it, blocking input via WndProc and several other methods. It just simply does not work.

How exactly am I supposed to provide a further MCVE when the code I posted can easily be modified to fit within the ImGui demo examples?

@ocornut
Copy link
Owner

ocornut commented Feb 7, 2018

How exactly am I supposed to provide a further MCVE when the code I posted can easily be modified to fit within the ImGui demo examples?

It's your job to make that modification and prove that you get the bug inside the demo example, then I'll be able to see the bug. If it's easy what you don't do that? Most likely the bug lies in the code that you HAVEN'T provided above. This is why I'm asking you verify the bug inside the demo application, that's the best way to ensure you are providing everything. You may fork imgui/ make the minimum modification to exhibit the bug and share that commit/branch.

If you trace the code you can see that InputText() is reading from that buffer you cleared with io.ClearInputCharacters(), so while your intention is correct, you are doing something wrong with that clearing.

@LemonHaze420
Copy link
Author

Isn't it your job to make sure this works?

@ocornut
Copy link
Owner

ocornut commented Feb 7, 2018

No, it's your job to prove your claim first, and then if there is a bug (and in this case I think there isn't) I get to decide whether I want to fix it because this is a free software and I owe you nothing.

It's insane that you would be so entitled even when I take the time to help you fix your own bugs.

You are blocked now, good luck.

@ocornut ocornut closed this as completed Feb 7, 2018
@zaafar
Copy link

zaafar commented Feb 7, 2018

Works fine for me, looks like he did his job well.

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

3 participants