mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 05:01:05 +01:00 
			
		
		
		
	Settings: Internals: Simplifying code a bit. Creating Settings structure during first save. Windows where ImGuiWindowFlags_NoSavedSettings was late toggled will save settings correctly. (#1000)
This commit is contained in:
		
							
								
								
									
										17
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								imgui.cpp
									
									
									
									
									
								
							| @@ -2497,8 +2497,8 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext& g, ImGuiTextBuffer* buf | |||||||
|         if (window->Flags & ImGuiWindowFlags_NoSavedSettings) |         if (window->Flags & ImGuiWindowFlags_NoSavedSettings) | ||||||
|             continue; |             continue; | ||||||
|         ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); |         ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); | ||||||
|         if (!settings)  // This will only return NULL in the rare instance where the window was first created with ImGuiWindowFlags_NoSavedSettings then had the flag disabled later on. We don't bind settings in this case (bug #1000). |         if (!settings) | ||||||
|             continue; |             settings = AddWindowSettings(window->Name); | ||||||
|         settings->Pos = window->Pos; |         settings->Pos = window->Pos; | ||||||
|         settings->Size = window->SizeFull; |         settings->Size = window->SizeFull; | ||||||
|         settings->Collapsed = window->Collapsed; |         settings->Collapsed = window->Collapsed; | ||||||
| @@ -2624,7 +2624,6 @@ static ImGuiWindowSettings* AddWindowSettings(const char* name) | |||||||
|     ImGuiWindowSettings* settings = &g.SettingsWindows.back(); |     ImGuiWindowSettings* settings = &g.SettingsWindows.back(); | ||||||
|     settings->Name = ImStrdup(name); |     settings->Name = ImStrdup(name); | ||||||
|     settings->Id = ImHash(name, 0); |     settings->Id = ImHash(name, 0); | ||||||
|     settings->Pos = ImVec2(FLT_MAX,FLT_MAX); |  | ||||||
|     return settings; |     return settings; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -4077,21 +4076,15 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl | |||||||
|         window->PosFloat = ImVec2(60, 60); |         window->PosFloat = ImVec2(60, 60); | ||||||
|         window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); |         window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); | ||||||
|  |  | ||||||
|         ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); |         if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID)) | ||||||
|         if (!settings) |  | ||||||
|             settings = AddWindowSettings(name); |  | ||||||
|         else |  | ||||||
|             SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); |  | ||||||
|  |  | ||||||
|         if (settings->Pos.x != FLT_MAX) |  | ||||||
|         { |         { | ||||||
|  |             SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); | ||||||
|             window->PosFloat = settings->Pos; |             window->PosFloat = settings->Pos; | ||||||
|             window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); |             window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); | ||||||
|             window->Collapsed = settings->Collapsed; |             window->Collapsed = settings->Collapsed; | ||||||
|         } |  | ||||||
|  |  | ||||||
|             if (ImLengthSqr(settings->Size) > 0.00001f) |             if (ImLengthSqr(settings->Size) > 0.00001f) | ||||||
|                 size = settings->Size; |                 size = settings->Size; | ||||||
|  |         } | ||||||
|         window->Size = window->SizeFull = size; |         window->Size = window->SizeFull = size; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user