-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Two childs not overlapping eachother #4493
Comments
The ChildBg rectangle is drawn on the parent to save a draw call. If you look for that code drawing the background you’ll find there’s a rule for it you may be able to workaround. Check the code that calls RenderWindowDecorations(). |
Detecting overlapping childs would be a O(log N) operation I don’t fancy but since our heuristic lastest so long (since 1.71) without another report, I think we could add to checking of previous child as part of the heuristic and it would fix a good portionncases (including yours which technically is the first reported case). |
Thank you for the fast reply! Will do. |
Pushed a fix for this case. Here's some minimal working test: ImGui::Text("Hello from parent");
ImVec2 p = ImGui::GetCursorScreenPos();
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.5f, 0.0f, 0.0f, 1.0f));
ImGui::SetNextWindowPos(ImVec2(p.x+100, p.y+0));
ImGui::BeginChild("Child #1", ImVec2(200, 200), true);
ImGui::Text("Child #1 Text");
ImGui::Button("Child #1 long button");
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.0f, 0.5f, 0.0f, 1.0f));
ImGui::SetNextWindowPos(ImVec2(p.x+150, p.y+0));
ImGui::BeginChild("Child #2", ImVec2(200, 200), true);
ImGui::SetCursorPosY(50);
ImGui::Button("Some button");
ImGui::EndChild();
ImGui::PopStyleColor(); |
This optimization causes z-order issues when a child window overlaps another submitted earlier, before the previous. Minimal code snippet to duplicateif(ImGui::BeginChildFrame(ImGui::GetID("under1"), { -FLT_MIN, 28 })) {
ImGui::Text("aaaaaaaaaaaaaaaaa");
ImGui::EndChildFrame();
}
if(ImGui::BeginChildFrame(ImGui::GetID("under2"), { -FLT_MIN, 28 })) {
ImGui::Text("bbbbbbbbbbbbbbbbb");
ImGui::EndChildFrame();
}
ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 0xcc));
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0xff, 0, 0xff, 0xff));
// overlaps under1 but not under2
ImGui::SetCursorPos({ 10, 32 });
if(ImGui::BeginChild("over1", { 50, 20 })) {
ImGui::Text("over");
ImGui::EndChild();
}
// overlaps both under1 and under2 but not over1
ImGui::SetCursorPos({ 70, 32 });
if(ImGui::BeginChild("over2", { 50, 50 })) {
ImGui::Text("over");
ImGui::EndChild();
}
ImGui::PopStyleColor(2); An example of the problem occurring in a real-world scenario (script by @GoranKovac): user-positioned child windows ( |
This optimization is quite meaningful, so considering we haven't been getting too many requests for that and considering your specific use case, I would suggest to aim for a workaround.
|
If you can think of a way to amend the existing heuristic I'm also open to that. (Btw there was a minor typo in the code |
Thank you!
My Issue/Question:
I've got two childs, one child(1) has a button/text init the second child(2) has a move button that moves the child(2) on top of the other child(1), my problem is that even though the child() is on top of the child(1) the button/text is still visible.
Screenshots/Video
2021-08-27.22-36-14.mp4
The text was updated successfully, but these errors were encountered: