imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Fixed work with focus in popups

Open DimaKoltun opened this issue 3 years ago • 1 comments

I need to have opportunity to create Popup with flag: ImGuiWindowFlags_NoFocusOnAppearing, to create popup which won't block mouse & keyboard focus for last focused item. Real Example: We have game viewport with popup, after opening popup we want to click ImGui button which also located in viewport by first mouse click - this behavior does not occur due popup steel focus if we use BeginPopupContextItem(...)/BeginPopupContextWindow(...)/BeginPopupContextVoid(...) because ImGuiWindowFlags_NoFocusOnAppearing isn't using there(i think it should be default behavior). Even if we add this flag, the second time the popup is opened it will not be in front of other windows: image

Minimal code, that reproduce problem:

if (ImGui::Button("Popup without focus"))
{
	ImGui::OpenPopup("Popup1");
}

if (ImGui::BeginPopup("Popup1", ImGuiWindowFlags_NoFocusOnAppearing))
{
	ImGui::Selectable("Option A");
	ImGui::Selectable("Option B");

	ImGui::EndPopup();
}

if (ImGui::Button("Popup with focus"))
{
	ImGui::OpenPopup("Popup2");
}

if (ImGui::BeginPopup("Popup2"))
{
	ImGui::Selectable("Option C");
	ImGui::Selectable("Option D");

	ImGui::EndPopup();
}

if (ImGui::BeginPopupContextWindow("Popup3"))
{
	ImGui::Selectable("Option F");
	ImGui::Selectable("Option Q");

	ImGui::EndPopup();
}

DimaKoltun avatar Jan 25 '22 16:01 DimaKoltun

Found problem: In popup with this ImGuiWindowFlags_NoFocusOnAppearing doesn't work navigation by keyboard if NavEnableKeyboard is on, so adding ImGuiWindowFlags_NoFocusOnAppearing by default for popup is not good idea.

DimaKoltun avatar Feb 08 '22 13:02 DimaKoltun