From af992d1321b2f2c9ea5dbfdeddad8ad68e9b0306 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 2 Jun 2020 16:03:50 +0200 Subject: [PATCH] Tables: Tweak settings functions to more prominently clarify the two levels of function. --- imgui.cpp | 2 +- imgui_internal.h | 11 +++++++---- imgui_tables.cpp | 22 ++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7ad7a547b..bc1ac4b78 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3970,7 +3970,7 @@ void ImGui::Initialize(ImGuiContext* context) #ifdef IMGUI_HAS_TABLE // Add .ini handle for ImGuiTable type - TableInstallSettingsHandler(context); + TableSettingsInstallHandler(context); #endif // #ifdef IMGUI_HAS_TABLE #ifdef IMGUI_HAS_DOCK diff --git a/imgui_internal.h b/imgui_internal.h index 780bc33cb..b9e1d8892 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2275,10 +2275,13 @@ namespace ImGui IMGUI_API void TableSetColumnAutofit(ImGuiTable* table, int column_n); IMGUI_API void PushTableBackground(); IMGUI_API void PopTableBackground(); - IMGUI_API void TableLoadSettings(ImGuiTable* table); - IMGUI_API void TableSaveSettings(ImGuiTable* table); - IMGUI_API ImGuiTableSettings* TableGetBoundSettings(const ImGuiTable* table); - IMGUI_API void TableInstallSettingsHandler(ImGuiContext* context); + IMGUI_API void TableSettingsInstallHandler(ImGuiContext* context); + IMGUI_API ImGuiTableSettings* TableSettingsCreate(ImGuiID id, int columns_count); + IMGUI_API ImGuiTableSettings* TableSettingsFindByID(ImGuiID id); + IMGUI_API void TableSettingsClearByID(ImGuiID id); + IMGUI_API void TableLoadSettings(ImGuiTable* table); + IMGUI_API void TableSaveSettings(ImGuiTable* table); + IMGUI_API ImGuiTableSettings* TableGetBoundSettings(ImGuiTable* table); // Tab Bars IMGUI_API bool BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& bb, ImGuiTabBarFlags flags); diff --git a/imgui_tables.cpp b/imgui_tables.cpp index efeed39fb..48ef06a7d 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -2376,7 +2376,7 @@ static void InitTableSettings(ImGuiTableSettings* settings, ImGuiID id, int colu settings->WantApply = true; } -static ImGuiTableSettings* CreateTableSettings(ImGuiID id, int columns_count) +ImGuiTableSettings* ImGui::TableSettingsCreate(ImGuiID id, int columns_count) { ImGuiContext& g = *GImGui; ImGuiTableSettings* settings = g.SettingsTables.alloc_chunk(sizeof(ImGuiTableSettings) + (size_t)columns_count * sizeof(ImGuiTableColumnSettings)); @@ -2385,7 +2385,7 @@ static ImGuiTableSettings* CreateTableSettings(ImGuiID id, int columns_count) } // Find existing settings -static ImGuiTableSettings* FindTableSettingsByID(ImGuiID id) +ImGuiTableSettings* ImGui::TableSettingsFindByID(ImGuiID id) { // FIXME-OPT: Might want to store a lookup map for this? ImGuiContext& g = *GImGui; @@ -2395,8 +2395,14 @@ static ImGuiTableSettings* FindTableSettingsByID(ImGuiID id) return NULL; } +void ImGui::TableSettingsClearByID(ImGuiID id) +{ + if (ImGuiTableSettings* settings = TableSettingsFindByID(id)) + settings->ID = 0; +} + // Get settings for a given table, NULL if none -ImGuiTableSettings* ImGui::TableGetBoundSettings(const ImGuiTable* table) +ImGuiTableSettings* ImGui::TableGetBoundSettings(ImGuiTable* table) { if (table->SettingsOffset != -1) { @@ -2421,7 +2427,7 @@ void ImGui::TableSaveSettings(ImGuiTable* table) ImGuiTableSettings* settings = TableGetBoundSettings(table); if (settings == NULL) { - settings = CreateTableSettings(table->ID, table->ColumnsCount); + settings = TableSettingsCreate(table->ID, table->ColumnsCount); table->SettingsOffset = g.SettingsTables.offset_from_ptr(settings); } settings->ColumnsCount = (ImS8)table->ColumnsCount; @@ -2473,7 +2479,7 @@ void ImGui::TableLoadSettings(ImGuiTable* table) ImGuiTableSettings* settings; if (table->SettingsOffset == -1) { - settings = FindTableSettingsByID(table->ID); + settings = TableSettingsFindByID(table->ID); if (settings == NULL) return; table->SettingsOffset = g.SettingsTables.offset_from_ptr(settings); @@ -2544,7 +2550,7 @@ static void* TableSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, if (sscanf(name, "0x%08X,%d", &id, &columns_count) < 2) return NULL; - if (ImGuiTableSettings* settings = FindTableSettingsByID(id)) + if (ImGuiTableSettings* settings = ImGui::TableSettingsFindByID(id)) { if (settings->ColumnsCountMax >= columns_count) { @@ -2553,7 +2559,7 @@ static void* TableSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, } settings->ID = 0; // Invalidate storage if we won't fit because of a count change } - return CreateTableSettings(id, columns_count); + return ImGui::TableSettingsCreate(id, columns_count); } static void TableSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) @@ -2620,7 +2626,7 @@ static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandle } } -void ImGui::TableInstallSettingsHandler(ImGuiContext* context) +void ImGui::TableSettingsInstallHandler(ImGuiContext* context) { ImGuiContext& g = *context; ImGuiSettingsHandler ini_handler;