mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-03 22:51:06 +01:00 
			
		
		
		
	Internals: Settings: moved Windows setting to their sub-section.
This commit is contained in:
		
							
								
								
									
										91
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										91
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -12452,15 +12452,16 @@ void ImGui::LogButtons()
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
// - UpdateSettings() [Internal]
 | 
			
		||||
// - MarkIniSettingsDirty() [Internal]
 | 
			
		||||
// - CreateNewWindowSettings() [Internal]
 | 
			
		||||
// - FindWindowSettingsByName() [Internal]
 | 
			
		||||
// - FindWindowSettingsByWindow() [Internal]
 | 
			
		||||
// - FindSettingsHandler() [Internal]
 | 
			
		||||
// - ClearIniSettings() [Internal]
 | 
			
		||||
// - LoadIniSettingsFromDisk()
 | 
			
		||||
// - LoadIniSettingsFromMemory()
 | 
			
		||||
// - SaveIniSettingsToDisk()
 | 
			
		||||
// - SaveIniSettingsToMemory()
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
// - CreateNewWindowSettings() [Internal]
 | 
			
		||||
// - FindWindowSettingsByName() [Internal]
 | 
			
		||||
// - FindWindowSettingsByWindow() [Internal]
 | 
			
		||||
// - WindowSettingsHandler_***() [Internal]
 | 
			
		||||
//-----------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
@@ -12507,48 +12508,6 @@ void ImGui::MarkIniSettingsDirty(ImGuiWindow* window)
 | 
			
		||||
            g.SettingsDirtyTimer = g.IO.IniSavingRate;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
 | 
			
		||||
#if !IMGUI_DEBUG_INI_SETTINGS
 | 
			
		||||
    // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
 | 
			
		||||
    // Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier.
 | 
			
		||||
    if (const char* p = strstr(name, "###"))
 | 
			
		||||
        name = p;
 | 
			
		||||
#endif
 | 
			
		||||
    const size_t name_len = strlen(name);
 | 
			
		||||
 | 
			
		||||
    // Allocate chunk
 | 
			
		||||
    const size_t chunk_size = sizeof(ImGuiWindowSettings) + name_len + 1;
 | 
			
		||||
    ImGuiWindowSettings* settings = g.SettingsWindows.alloc_chunk(chunk_size);
 | 
			
		||||
    IM_PLACEMENT_NEW(settings) ImGuiWindowSettings();
 | 
			
		||||
    settings->ID = ImHashStr(name, name_len);
 | 
			
		||||
    memcpy(settings->GetName(), name, name_len + 1);   // Store with zero terminator
 | 
			
		||||
 | 
			
		||||
    return settings;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is called once per window .ini entry + once per newly instanciated window.
 | 
			
		||||
ImGuiWindowSettings* ImGui::FindWindowSettingsByName(const char* name)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
    ImGuiID id = ImHashStr(name);
 | 
			
		||||
    for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings))
 | 
			
		||||
        if (settings->ID == id)
 | 
			
		||||
            return settings;
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is faster if you are holding on a Window already as we don't need to perform a search.
 | 
			
		||||
ImGuiWindowSettings* ImGui::FindWindowSettingsByWindow(ImGuiWindow* window)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
    if (window->SettingsOffset != -1)
 | 
			
		||||
        return g.SettingsWindows.ptr_from_offset(window->SettingsOffset);
 | 
			
		||||
    return FindWindowSettingsByName(window->Name); // Actual search executed once, so at this point we don't mind the redundant hashing.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui::AddSettingsHandler(const ImGuiSettingsHandler* handler)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
@@ -12698,6 +12657,48 @@ const char* ImGui::SaveIniSettingsToMemory(size_t* out_size)
 | 
			
		||||
    return g.SettingsIniData.c_str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
 | 
			
		||||
#if !IMGUI_DEBUG_INI_SETTINGS
 | 
			
		||||
    // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
 | 
			
		||||
    // Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier.
 | 
			
		||||
    if (const char* p = strstr(name, "###"))
 | 
			
		||||
        name = p;
 | 
			
		||||
#endif
 | 
			
		||||
    const size_t name_len = strlen(name);
 | 
			
		||||
 | 
			
		||||
    // Allocate chunk
 | 
			
		||||
    const size_t chunk_size = sizeof(ImGuiWindowSettings) + name_len + 1;
 | 
			
		||||
    ImGuiWindowSettings* settings = g.SettingsWindows.alloc_chunk(chunk_size);
 | 
			
		||||
    IM_PLACEMENT_NEW(settings) ImGuiWindowSettings();
 | 
			
		||||
    settings->ID = ImHashStr(name, name_len);
 | 
			
		||||
    memcpy(settings->GetName(), name, name_len + 1);   // Store with zero terminator
 | 
			
		||||
 | 
			
		||||
    return settings;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is called once per window .ini entry + once per newly instantiated window.
 | 
			
		||||
ImGuiWindowSettings* ImGui::FindWindowSettingsByName(const char* name)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
    ImGuiID id = ImHashStr(name);
 | 
			
		||||
    for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings))
 | 
			
		||||
        if (settings->ID == id)
 | 
			
		||||
            return settings;
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is faster if you are holding on a Window already as we don't need to perform a search.
 | 
			
		||||
ImGuiWindowSettings* ImGui::FindWindowSettingsByWindow(ImGuiWindow* window)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *GImGui;
 | 
			
		||||
    if (window->SettingsOffset != -1)
 | 
			
		||||
        return g.SettingsWindows.ptr_from_offset(window->SettingsOffset);
 | 
			
		||||
    return FindWindowSettingsByName(window->Name); // Actual search executed once, so at this point we don't mind the redundant hashing.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void WindowSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiContext& g = *ctx;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user