mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 05:01:05 +01:00 
			
		
		
		
	Viewport: Reorder flags. Set owned viewport common decoration flags in Begin(). Moved code in UpdateViewportsEndFrame() before we introduce family/class based overrides.
This commit is contained in:
		
							
								
								
									
										76
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										76
									
								
								imgui.cpp
									
									
									
									
									
								
							| @@ -1010,7 +1010,8 @@ static void             UpdateManualResize(ImGuiWindow* window, const ImVec2& si | ||||
| // Viewports | ||||
| const ImGuiID           IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111; // Using an arbitrary constant instead of e.g. ImHash("ViewportDefault", 0); so it's easier to spot in the debugger. The exact value doesn't matter. | ||||
| static ImGuiViewportP*  AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& platform_pos, const ImVec2& size, ImGuiViewportFlags flags); | ||||
| static void             UpdateViewports(); | ||||
| static void             UpdateViewportsNewFrame(); | ||||
| static void             UpdateViewportsEndFrame(); | ||||
| static void             UpdateSelectWindowViewport(ImGuiWindow* window); | ||||
| static bool             UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* host_viewport); | ||||
| static void             SetCurrentViewport(ImGuiWindow* window, ImGuiViewportP* viewport); | ||||
| @@ -3352,7 +3353,7 @@ void ImGui::NewFrame() | ||||
|     g.WindowsActiveCount = 0; | ||||
|     g.ConfigFlagsForFrame = g.IO.ConfigFlags; | ||||
|  | ||||
|     UpdateViewports(); | ||||
|     UpdateViewportsNewFrame(); | ||||
|  | ||||
|     // Setup current font, and draw list shared data | ||||
|     // FIXME-VIEWPORT: the concept of a single ClipRectFullscreen is not ideal! | ||||
| @@ -3846,24 +3847,8 @@ void ImGui::EndFrame() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Update user-facing viewport list | ||||
|     g.PlatformIO.MainViewport = g.Viewports[0]; | ||||
|     g.PlatformIO.Viewports.resize(0); | ||||
|     for (int i = 0; i < g.Viewports.Size; i++) | ||||
|     { | ||||
|         ImGuiViewportP* viewport = g.Viewports[i]; | ||||
|         viewport->LastPos = viewport->Pos; | ||||
|         if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0.0f || viewport->Size.y <= 0.0f) | ||||
|             continue; | ||||
|         if (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)) // Will be destroyed in UpdatePlatformWindows() | ||||
|             continue; | ||||
|         if (i > 0) | ||||
|             IM_ASSERT(viewport->Window != NULL); | ||||
|  | ||||
|         // Add to user-facing list | ||||
|         g.PlatformIO.Viewports.push_back(viewport); | ||||
|     } | ||||
|     g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called | ||||
|     // Update user-facing viewport list (g.Viewports -> g.PlatformIO.Viewports after filtering out some) | ||||
|     UpdateViewportsEndFrame(); | ||||
|  | ||||
|     // Sort the window list so that all child windows are after their parent | ||||
|     // We cannot do that on FocusWindow() because childs may not exist yet | ||||
| @@ -5178,16 +5163,26 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) | ||||
|                 SetCurrentWindow(window); | ||||
|             } | ||||
|  | ||||
|         // Synchronize viewport --> window in case the platform window has been moved or resized from the OS/WM | ||||
|         if (window->ViewportOwned) | ||||
|         { | ||||
|             // Synchronize viewport -> window in case the platform window has been moved or resized from the OS/WM | ||||
|             if (window->Viewport->PlatformRequestMove) | ||||
|                 window->Pos = window->Viewport->Pos; | ||||
|             if (window->Viewport->PlatformRequestResize) | ||||
|                 window->Size = window->SizeFull = window->Viewport->Size; | ||||
|  | ||||
|             // Update common viewport flags | ||||
|             ImGuiViewportFlags viewport_flags = (window->Viewport->Flags) & ~(ImGuiViewportFlags_TopMost | ImGuiViewportFlags_NoTaskBarIcon | ImGuiViewportFlags_NoDecoration); | ||||
|             if (flags & ImGuiWindowFlags_Tooltip) | ||||
|                 viewport_flags |= ImGuiViewportFlags_TopMost; | ||||
|             if ((g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsNoTaskBarIcon) != 0 || (flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0) | ||||
|                 viewport_flags |= ImGuiViewportFlags_NoTaskBarIcon; | ||||
|             if ((g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsDecoration) == 0 || (flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0) | ||||
|                 viewport_flags |= ImGuiViewportFlags_NoDecoration; | ||||
|  | ||||
|             // We also tell the back-end that clearing the platform window won't be necessary, as our window is filling the viewport and we have disabled BgAlpha | ||||
|             window->Viewport->Flags |= ImGuiViewportFlags_NoRendererClear; | ||||
|             viewport_flags |= ImGuiViewportFlags_NoRendererClear; | ||||
|             window->Viewport->Flags = viewport_flags; | ||||
|         } | ||||
|  | ||||
|         // Clamp position so window stays visible within its viewport or monitor | ||||
| @@ -7387,8 +7382,7 @@ static ImGuiViewportP* FindViewportHoveredFromPlatformWindowStack(const ImVec2 m | ||||
|     return best_candidate; | ||||
| } | ||||
|  | ||||
| // Called in NewFrame() | ||||
| static void ImGui::UpdateViewports() | ||||
| static void ImGui::UpdateViewportsNewFrame() | ||||
| { | ||||
|     ImGuiContext& g = *GImGui; | ||||
|     IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size); | ||||
| @@ -7540,6 +7534,27 @@ static void ImGui::UpdateViewports() | ||||
|     IM_ASSERT(g.MouseViewport != NULL); | ||||
| } | ||||
|  | ||||
| // Update user-facing viewport list (g.Viewports -> g.PlatformIO.Viewports after filtering out some) | ||||
| static void ImGui::UpdateViewportsEndFrame() | ||||
| { | ||||
|     ImGuiContext& g = *GImGui; | ||||
|     g.PlatformIO.MainViewport = g.Viewports[0]; | ||||
|     g.PlatformIO.Viewports.resize(0); | ||||
|     for (int i = 0; i < g.Viewports.Size; i++) | ||||
|     { | ||||
|         ImGuiViewportP* viewport = g.Viewports[i]; | ||||
|         viewport->LastPos = viewport->Pos; | ||||
|         if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0.0f || viewport->Size.y <= 0.0f) | ||||
|             continue; | ||||
|         if (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)) | ||||
|             continue; | ||||
|         if (i > 0) | ||||
|             IM_ASSERT(viewport->Window != NULL); | ||||
|         g.PlatformIO.Viewports.push_back(viewport); | ||||
|     } | ||||
|     g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called | ||||
| } | ||||
|  | ||||
| // FIXME: We should ideally refactor the system to call this every frame (we currently don't) | ||||
| ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& pos, const ImVec2& size, ImGuiViewportFlags flags) | ||||
| { | ||||
| @@ -7734,19 +7749,6 @@ void ImGui::UpdatePlatformWindows() | ||||
|         if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0 || viewport->Size.y <= 0) | ||||
|             continue; | ||||
|  | ||||
|         // Update common viewport flags for owned viewports | ||||
|         if (ImGuiWindow* window = viewport->Window) | ||||
|         { | ||||
|             ImGuiViewportFlags flags = viewport->Flags & ~(ImGuiViewportFlags_TopMost | ImGuiViewportFlags_NoTaskBarIcon | ImGuiViewportFlags_NoDecoration); | ||||
|             if (window->Flags & ImGuiWindowFlags_Tooltip) | ||||
|                 flags |= ImGuiViewportFlags_TopMost; | ||||
|             if ((g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsNoTaskBarIcon) != 0 || (window->Flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0) | ||||
|                 flags |= ImGuiViewportFlags_NoTaskBarIcon; | ||||
|             if ((g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsDecoration) == 0 || (window->Flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0) | ||||
|                 flags |= ImGuiViewportFlags_NoDecoration; | ||||
|             viewport->Flags = flags; | ||||
|         } | ||||
|  | ||||
|         // Create window | ||||
|         bool is_new_platform_window = (viewport->PlatformWindowCreated == false); | ||||
|         if (is_new_platform_window) | ||||
|   | ||||
							
								
								
									
										14
									
								
								imgui.h
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								imgui.h
									
									
									
									
									
								
							| @@ -989,8 +989,8 @@ enum ImGuiConfigFlags_ | ||||
|     // When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable. | ||||
|     ImGuiConfigFlags_ViewportsEnable        = 1 << 10,  // Viewport enable flags (require both ImGuiConfigFlags_PlatformHasViewports + ImGuiConfigFlags_RendererHasViewports set by the respective back-ends) | ||||
|     ImGuiConfigFlags_ViewportsNoTaskBarIcon = 1 << 11,  // Disable task bars icons for all secondary viewports (will set ImGuiViewportFlags_NoTaskBarIcon on them) | ||||
|     ImGuiConfigFlags_ViewportsNoMerge       = 1 << 12,  // All floating windows will always create their own viewport and platform window. | ||||
|     ImGuiConfigFlags_ViewportsDecoration    = 1 << 13,  // FIXME [Broken] Enable platform decoration for all secondary viewports (will not set ImGuiViewportFlags_NoDecoration on them). This currently doesn't behave well in Windows because 1) By default the new window animation get in the way of our transitions, 2) It enable a minimum window size which tends to breaks resizing. You can workaround the later by setting style.WindowMinSize to a bigger value. | ||||
|     ImGuiConfigFlags_ViewportsDecoration    = 1 << 12,  // FIXME [Broken] Enable platform decoration for all secondary viewports (will not set ImGuiViewportFlags_NoDecoration on them). This currently doesn't behave well in Windows because 1) By default the new window animation get in the way of our transitions, 2) It enable a minimum window size which tends to breaks resizing. You can workaround the later by setting style.WindowMinSize to a bigger value. | ||||
|     ImGuiConfigFlags_ViewportsNoMerge       = 1 << 13,  // All floating windows will always create their own viewport and platform window. | ||||
|     ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14,  // FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application. | ||||
|     ImGuiConfigFlags_DpiEnableScaleFonts    = 1 << 15,  // FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress. | ||||
|  | ||||
| @@ -2217,11 +2217,11 @@ struct ImGuiPlatformIO | ||||
| enum ImGuiViewportFlags_ | ||||
| { | ||||
|     ImGuiViewportFlags_None                     = 0, | ||||
|     ImGuiViewportFlags_NoDecoration             = 1 << 0,   // Platform Window: Disable platform decorations: title bar, borders, etc. | ||||
|     ImGuiViewportFlags_NoFocusOnAppearing       = 1 << 1,   // Platform Window: Don't take focus when created. | ||||
|     ImGuiViewportFlags_NoInputs                 = 1 << 2,   // Platform Window: Make mouse pass through so we can drag this window while peaking behind it. | ||||
|     ImGuiViewportFlags_NoTaskBarIcon            = 1 << 3,   // Platform Window: Disable platform task bar icon (for popups, menus, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcons if set) | ||||
|     ImGuiViewportFlags_NoRendererClear          = 1 << 4,   // Platform Window: Renderer doesn't need to clear the framebuffer ahead. | ||||
|     ImGuiViewportFlags_NoDecoration             = 1 << 0,   // Platform Window: Disable platform decorations: title bar, borders, etc. (generally set all windows, but if ImGuiConfigFlags_ViewportsDecoration is set we only set this on popups/tooltips) | ||||
|     ImGuiViewportFlags_NoTaskBarIcon            = 1 << 1,   // Platform Window: Disable platform task bar icon (generally set on popups/tooltips, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcon is set) | ||||
|     ImGuiViewportFlags_NoFocusOnAppearing       = 1 << 2,   // Platform Window: Don't take focus when created. | ||||
|     ImGuiViewportFlags_NoInputs                 = 1 << 3,   // Platform Window: Make mouse pass through so we can drag this window while peaking behind it. | ||||
|     ImGuiViewportFlags_NoRendererClear          = 1 << 4,   // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely). | ||||
|     ImGuiViewportFlags_TopMost                  = 1 << 5    // Platform Window: Display on top (for tooltips only) | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -665,7 +665,7 @@ struct ImGuiViewportP : public ImGuiViewport | ||||
|     short               PlatformMonitor; | ||||
|     bool                PlatformWindowCreated; | ||||
|     bool                PlatformWindowMinimized; | ||||
|     ImGuiWindow*        Window;                   // Set when the viewport is owned by a window | ||||
|     ImGuiWindow*        Window;                   // Set when the viewport is owned by a window (and ImGuiViewportFlags_CanHostOtherWindows is NOT set) | ||||
|     ImDrawList*         OverlayDrawList;          // For convenience, a draw list we can render to that's always rendered last (we use it to draw software mouse cursor when io.MouseDrawCursor is set) | ||||
|     ImDrawData          DrawDataP; | ||||
|     ImDrawDataBuilder   DrawDataBuilder; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user