ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
60.37k stars 10.21k forks source link

Controlling the z-index of windows #983

Open djones4487169 opened 7 years ago

djones4487169 commented 7 years ago

Is there a way to control the z-index of windows so some are always on top?

ocornut commented 7 years ago

There isn't an a way to control it at the moment.

Depending on your exact intent, you may use the SetNextWindowFocus() window to bring a window to the top, or the ImGuiWindowFlags_NoBringToFrontOnFocus and ImGuiWindowFlags_NoFocusOnAppearing window flags.

djones4487169 commented 7 years ago

OK. I have the following piece of code taken from the Custom Rendering example. I want to leave a simple overlay at the end of each line measuring the size of the line. However, every time I start a new line the old overlay disappears? What I want is regardless of number of lines each one have a unique displayed ending overlay.

draw->PushClipRect(ImVec4(canvas_pos.x, canvas_pos.y, canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y));
for (int i = 0; i < points.Size - 1; i += 2) { draw->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i + 1].x, canvas_pos.y + points[i + 1].y), ImColor(255, 0, 0), 1.0f); float len = MathHelper::Length(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i + 1].x, canvas_pos.y + points[i + 1].y)); char str[32]; sprintf(str, "%.2f mm", len); bool tmp = true; char num[16]; sprintf(num, "%d", i); ImGui::SetNextWindowPos(ImVec2(canvas_pos.x + points[i + 1].x + 10, canvas_pos.y + points[i + 1].y)); ImGui::Begin(num, &tmp, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove); ImGui::Text(str); ImGui::End(); } draw->PopClipRect(); if (adding_preview) points.pop_back();

ocornut commented 7 years ago

Don't use a million windows for that anyway, especially if you are only drawing simple non-interactive labels, is a waste of resource when you can do in the same window you already are in. Just use the drawlist api to draw rectangle+text, or set the cursor position within the window, add the Text() statement and then restore cursor position.

djones4487169 commented 7 years ago

OK. Is there a way to make the rectangle act like the autosize property of the popups otherwise I will need different size calculations for each rectangle depending on length result?

ocornut commented 7 years ago

Yes you need to calculate the text size yourself.