mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Viewport: Exposing SetNextWindowViewport(). Used in demo and old/obsolete SetNextWindowPosCenter() (which is an interesting case). Fixed back-end likely crash calling GetFocus() after viewport destruction. Fixed metrics crash.
This commit is contained in:
parent
cd51f37fc0
commit
c47d34cf70
12
imgui.cpp
12
imgui.cpp
@ -3594,6 +3594,7 @@ void ImGui::UpdatePlatformWindows()
|
|||||||
g.PlatformIO.Renderer_DestroyWindow(viewport);
|
g.PlatformIO.Renderer_DestroyWindow(viewport);
|
||||||
if (g.PlatformIO.Platform_DestroyWindow)
|
if (g.PlatformIO.Platform_DestroyWindow)
|
||||||
g.PlatformIO.Platform_DestroyWindow(viewport);
|
g.PlatformIO.Platform_DestroyWindow(viewport);
|
||||||
|
viewport->CreatedPlatformWindow = false;
|
||||||
IM_ASSERT(viewport->RendererUserData == NULL);
|
IM_ASSERT(viewport->RendererUserData == NULL);
|
||||||
IM_ASSERT(viewport->PlatformUserData == NULL && viewport->PlatformHandle == NULL);
|
IM_ASSERT(viewport->PlatformUserData == NULL && viewport->PlatformHandle == NULL);
|
||||||
}
|
}
|
||||||
@ -7916,6 +7917,15 @@ void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiCond cond, const ImVec2& pi
|
|||||||
g.NextWindowData.PosCond = cond ? cond : ImGuiCond_Always;
|
g.NextWindowData.PosCond = cond ? cond : ImGuiCond_Always;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
void ImGui::SetNextWindowPosCenter(ImGuiCond cond)
|
||||||
|
{
|
||||||
|
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||||
|
SetNextWindowPos(viewport->Pos + viewport->Size * 0.5f, cond, ImVec2(0.5f, 0.5f));
|
||||||
|
SetNextWindowViewport(viewport->ID);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond)
|
void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
@ -14260,7 +14270,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
else
|
else
|
||||||
ImGui::BulletText("NavRectRel[0]: <None>");
|
ImGui::BulletText("NavRectRel[0]: <None>");
|
||||||
ImGui::BulletText("Viewport: %d, ViewportId: 0x%08X, ViewportPos: (%.1f,%.1f)", window->Viewport ? window->Viewport->Idx : -1, window->ViewportId, window->ViewportPos.x, window->ViewportPos.y);
|
ImGui::BulletText("Viewport: %d, ViewportId: 0x%08X, ViewportPos: (%.1f,%.1f)", window->Viewport ? window->Viewport->Idx : -1, window->ViewportId, window->ViewportPos.x, window->ViewportPos.y);
|
||||||
ImGui::BulletText("ViewportMonitor: %d", window->Viewport->PlatformMonitor);
|
ImGui::BulletText("ViewportMonitor: %d", window->Viewport ? window->Viewport->PlatformMonitor : -1);
|
||||||
if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow");
|
if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow");
|
||||||
if (window->ParentWindow != NULL) NodeWindow(window->ParentWindow, "ParentWindow");
|
if (window->ParentWindow != NULL) NodeWindow(window->ParentWindow, "ParentWindow");
|
||||||
if (window->DC.ChildWindows.Size > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows");
|
if (window->DC.ChildWindows.Size > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows");
|
||||||
|
3
imgui.h
3
imgui.h
@ -206,6 +206,7 @@ namespace ImGui
|
|||||||
IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin()
|
IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin()
|
||||||
IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin()
|
IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin()
|
||||||
IMGUI_API void SetNextWindowBgAlpha(float alpha); // set next window background color alpha. helper to easily modify ImGuiCol_WindowBg/ChildBg/PopupBg.
|
IMGUI_API void SetNextWindowBgAlpha(float alpha); // set next window background color alpha. helper to easily modify ImGuiCol_WindowBg/ChildBg/PopupBg.
|
||||||
|
IMGUI_API void SetNextWindowViewport(ImGuiID viewport_id); // set next window viewport
|
||||||
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects.
|
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects.
|
||||||
IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiCond cond = 0); // (not recommended) set current window size - call within Begin()/End(). set to ImVec2(0,0) to force an auto-fit. prefer using SetNextWindowSize(), as this may incur tearing and minor side-effects.
|
IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiCond cond = 0); // (not recommended) set current window size - call within Begin()/End(). set to ImVec2(0,0) to force an auto-fit. prefer using SetNextWindowSize(), as this may incur tearing and minor side-effects.
|
||||||
IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // (not recommended) set current window collapsed state. prefer using SetNextWindowCollapsed().
|
IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // (not recommended) set current window collapsed state. prefer using SetNextWindowCollapsed().
|
||||||
@ -1148,7 +1149,7 @@ namespace ImGui
|
|||||||
bool Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override = -1.0f, ImGuiWindowFlags flags = 0); // Use SetNextWindowSize(size, ImGuiCond_FirstUseEver) + SetNextWindowBgAlpha() instead.
|
bool Begin(const char* name, bool* p_open, const ImVec2& size_on_first_use, float bg_alpha_override = -1.0f, ImGuiWindowFlags flags = 0); // Use SetNextWindowSize(size, ImGuiCond_FirstUseEver) + SetNextWindowBgAlpha() instead.
|
||||||
static inline bool IsRootWindowOrAnyChildHovered() { return IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); }
|
static inline bool IsRootWindowOrAnyChildHovered() { return IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); }
|
||||||
static inline void AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); }
|
static inline void AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); }
|
||||||
static inline void SetNextWindowPosCenter(ImGuiCond c=0) { ImGuiIO& io = GetIO(); SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), c, ImVec2(0.5f, 0.5f)); } // FIXME-VIEWPORT-ABS: Select viewport based on mouse position
|
void SetNextWindowPosCenter(ImGuiCond cond);
|
||||||
// OBSOLETED in 1.51 (between Jun 2017 and Aug 2017)
|
// OBSOLETED in 1.51 (between Jun 2017 and Aug 2017)
|
||||||
static inline bool IsItemHoveredRect() { return IsItemHovered(ImGuiHoveredFlags_RectOnly); }
|
static inline bool IsItemHoveredRect() { return IsItemHovered(ImGuiHoveredFlags_RectOnly); }
|
||||||
static inline bool IsPosHoveringAnyWindow(const ImVec2&) { IM_ASSERT(0); return false; } // This was misleading and partly broken. You probably want to use the ImGui::GetIO().WantCaptureMouse flag instead.
|
static inline bool IsPosHoveringAnyWindow(const ImVec2&) { IM_ASSERT(0); return false; } // This was misleading and partly broken. You probably want to use the ImGui::GetIO().WantCaptureMouse flag instead.
|
||||||
|
@ -2477,11 +2477,14 @@ static void ShowExampleAppFixedOverlay(bool* p_open)
|
|||||||
// FIXME-VIEWPORT-ABS: Select a default viewport
|
// FIXME-VIEWPORT-ABS: Select a default viewport
|
||||||
const float DISTANCE = 10.0f;
|
const float DISTANCE = 10.0f;
|
||||||
static int corner = 0;
|
static int corner = 0;
|
||||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
|
||||||
ImVec2 window_pos = ImVec2((corner & 1) ? (viewport->Pos.x + viewport->Size.x - DISTANCE) : (viewport->Pos.x + DISTANCE), (corner & 2) ? (viewport->Pos.y + viewport->Size.y - DISTANCE) : (viewport->Pos.y + DISTANCE));
|
|
||||||
ImVec2 window_pos_pivot = ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f);
|
|
||||||
if (corner != -1)
|
if (corner != -1)
|
||||||
|
{
|
||||||
|
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||||
|
ImVec2 window_pos = ImVec2((corner & 1) ? (viewport->Pos.x + viewport->Size.x - DISTANCE) : (viewport->Pos.x + DISTANCE), (corner & 2) ? (viewport->Pos.y + viewport->Size.y - DISTANCE) : (viewport->Pos.y + DISTANCE));
|
||||||
|
ImVec2 window_pos_pivot = ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f);
|
||||||
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
|
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
|
||||||
|
ImGui::SetNextWindowViewport(viewport->ID);
|
||||||
|
}
|
||||||
ImGui::SetNextWindowBgAlpha(0.3f); // Transparent background
|
ImGui::SetNextWindowBgAlpha(0.3f); // Transparent background
|
||||||
if (ImGui::Begin("Example: Fixed Overlay", p_open, (corner != -1 ? ImGuiWindowFlags_NoMove : 0) | ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_NoFocusOnAppearing|ImGuiWindowFlags_NoNav))
|
if (ImGui::Begin("Example: Fixed Overlay", p_open, (corner != -1 ? ImGuiWindowFlags_NoMove : 0) | ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_NoFocusOnAppearing|ImGuiWindowFlags_NoNav))
|
||||||
{
|
{
|
||||||
|
@ -1080,7 +1080,6 @@ namespace ImGui
|
|||||||
|
|
||||||
// Viewports
|
// Viewports
|
||||||
IMGUI_API ImGuiViewportP* FindViewportByID(ImGuiID id);
|
IMGUI_API ImGuiViewportP* FindViewportByID(ImGuiID id);
|
||||||
IMGUI_API void SetNextWindowViewport(ImGuiID id);
|
|
||||||
IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale);
|
IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale);
|
||||||
IMGUI_API void ShowViewportThumbnails();
|
IMGUI_API void ShowViewportThumbnails();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user