Backends: SDL3: added support for viewport->ParentViewportId field to support parenting windows at OS level. (#7973)
This commit is contained in:
parent
68aa9a86ec
commit
484764860d
@ -13,7 +13,6 @@
|
||||
// [x] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable' -> the OS animation effect when window gets created/destroyed is problematic. SDL2 backend doesn't have issue.
|
||||
// Issues:
|
||||
// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
|
||||
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
@ -26,6 +25,7 @@
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 2024-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||
// 2024-09-11: (Docking) Added support for viewport->ParentViewportId field to support parenting at OS level. (#7973)
|
||||
// 2024-09-03: Update for SDL3 api changes: SDL_GetGamepads() memory ownership revert. (#7918, #7898, #7807)
|
||||
// 2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
|
||||
// - io.GetClipboardTextFn -> platform_io.Platform_GetClipboardTextFn
|
||||
@ -905,20 +905,34 @@ void ImGui_ImplSDL3_NewFrame()
|
||||
struct ImGui_ImplSDL3_ViewportData
|
||||
{
|
||||
SDL_Window* Window;
|
||||
SDL_Window* ParentWindow;
|
||||
Uint32 WindowID;
|
||||
bool WindowOwned;
|
||||
SDL_GLContext GLContext;
|
||||
|
||||
ImGui_ImplSDL3_ViewportData() { Window = nullptr; WindowID = 0; WindowOwned = false; GLContext = nullptr; }
|
||||
ImGui_ImplSDL3_ViewportData() { Window = ParentWindow = nullptr; WindowID = 0; WindowOwned = false; GLContext = nullptr; }
|
||||
~ImGui_ImplSDL3_ViewportData() { IM_ASSERT(Window == nullptr && GLContext == nullptr); }
|
||||
};
|
||||
|
||||
static SDL_Window* ImGui_ImplSDL3_GetSDLWindowFromViewportID(ImGuiID viewport_id)
|
||||
{
|
||||
if (viewport_id != 0)
|
||||
if (ImGuiViewport* viewport = ImGui::FindViewportByID(viewport_id))
|
||||
{
|
||||
SDL_WindowID window_id = (SDL_WindowID)(intptr_t)viewport->PlatformHandle;
|
||||
return SDL_GetWindowFromID(window_id);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_CreateWindow(ImGuiViewport* viewport)
|
||||
{
|
||||
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
|
||||
ImGui_ImplSDL3_ViewportData* vd = IM_NEW(ImGui_ImplSDL3_ViewportData)();
|
||||
viewport->PlatformUserData = vd;
|
||||
|
||||
vd->ParentWindow = ImGui_ImplSDL3_GetSDLWindowFromViewportID(viewport->ParentViewportId);
|
||||
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
ImGui_ImplSDL3_ViewportData* main_viewport_data = (ImGui_ImplSDL3_ViewportData*)main_viewport->PlatformUserData;
|
||||
|
||||
@ -943,6 +957,7 @@ static void ImGui_ImplSDL3_CreateWindow(ImGuiViewport* viewport)
|
||||
#endif
|
||||
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0;
|
||||
vd->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags);
|
||||
SDL_SetWindowParent(vd->Window, vd->ParentWindow);
|
||||
SDL_SetWindowPosition(vd->Window, (int)viewport->Pos.x, (int)viewport->Pos.y);
|
||||
vd->WindowOwned = true;
|
||||
if (use_opengl)
|
||||
@ -992,6 +1007,20 @@ static void ImGui_ImplSDL3_ShowWindow(ImGuiViewport* viewport)
|
||||
SDL_ShowWindow(vd->Window);
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL3_UpdateWindow(ImGuiViewport* viewport)
|
||||
{
|
||||
ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData;
|
||||
|
||||
// Update SDL3 parent if it changed _after_ creation.
|
||||
// This is for advanced apps that are manipulating ParentViewportID manually.
|
||||
SDL_Window* new_parent = ImGui_ImplSDL3_GetSDLWindowFromViewportID(viewport->ParentViewportId);
|
||||
if (new_parent != vd->ParentWindow)
|
||||
{
|
||||
vd->ParentWindow = new_parent;
|
||||
SDL_SetWindowParent(vd->Window, vd->ParentWindow);
|
||||
}
|
||||
}
|
||||
|
||||
static ImVec2 ImGui_ImplSDL3_GetWindowPos(ImGuiViewport* viewport)
|
||||
{
|
||||
ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData;
|
||||
@ -1085,6 +1114,7 @@ static void ImGui_ImplSDL3_InitPlatformInterface(SDL_Window* window, void* sdl_g
|
||||
platform_io.Platform_CreateWindow = ImGui_ImplSDL3_CreateWindow;
|
||||
platform_io.Platform_DestroyWindow = ImGui_ImplSDL3_DestroyWindow;
|
||||
platform_io.Platform_ShowWindow = ImGui_ImplSDL3_ShowWindow;
|
||||
platform_io.Platform_UpdateWindow = ImGui_ImplSDL3_UpdateWindow;
|
||||
platform_io.Platform_SetWindowPos = ImGui_ImplSDL3_SetWindowPos;
|
||||
platform_io.Platform_GetWindowPos = ImGui_ImplSDL3_GetWindowPos;
|
||||
platform_io.Platform_SetWindowSize = ImGui_ImplSDL3_SetWindowSize;
|
||||
|
@ -13,7 +13,6 @@
|
||||
// [x] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable' -> the OS animation effect when window gets created/destroyed is problematic. SDL2 backend doesn't have issue.
|
||||
// Issues:
|
||||
// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
|
||||
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
||||
// [x] Platform: Basic IME support. Position somehow broken in SDL3 + app needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
|
@ -67,6 +67,11 @@ Other changes:
|
||||
- TextLinkOpenURL(): modified tooltip to display a verb "Open 'xxxx'". (#7885, #7660)
|
||||
- Backends: SDL2: use SDL_Vulkan_GetDrawableSize() when available. (#7967, #3190) [@scribam]
|
||||
|
||||
Docking+Viewports Branch:
|
||||
|
||||
- Backends: SDL3: added support for viewport->ParentViewportId field to support parenting
|
||||
windows at OS level. (#7973) [@RT2code]
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
VERSION 1.91.1 (Released 2024-09-04)
|
||||
-----------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user