Translate Dear ImGui windows when a Host Viewport has been moved (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!)
| 16741 | // Translate Dear ImGui windows when a Host Viewport has been moved |
| 16742 | // (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!) |
| 16743 | void ImGui::TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos, const ImVec2& old_size, const ImVec2& new_size) |
| 16744 | { |
| 16745 | ImGuiContext& g = *GImGui; |
| 16746 | //IMGUI_DEBUG_LOG_VIEWPORT("[viewport] TranslateWindowsInViewport 0x%08X\n", viewport->ID); |
| 16747 | IM_ASSERT(viewport->Window == NULL && (viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows)); |
| 16748 | |
| 16749 | // 1) We test if ImGuiConfigFlags_ViewportsEnable was just toggled, which allows us to conveniently |
| 16750 | // translate imgui windows from OS-window-local to absolute coordinates or vice-versa. |
| 16751 | // 2) If it's not going to fit into the new size, keep it at same absolute position. |
| 16752 | // One problem with this is that most Win32 applications doesn't update their render while dragging, |
| 16753 | // and so the window will appear to teleport when releasing the mouse. |
| 16754 | const bool translate_all_windows = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable); |
| 16755 | ImRect test_still_fit_rect(old_pos, old_pos + old_size); |
| 16756 | ImVec2 delta_pos = new_pos - old_pos; |
| 16757 | for (ImGuiWindow* window : g.Windows) // FIXME-OPT |
| 16758 | if (translate_all_windows || (window->Viewport == viewport && (old_size == new_size || test_still_fit_rect.Contains(window->Rect())))) |
| 16759 | TranslateWindow(window, delta_pos); |
| 16760 | } |
| 16761 | |
| 16762 | // Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!) |
| 16763 | void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale) |
nothing calls this directly
no test coverage detected