Skip to content

Commit

Permalink
Internals: add AddSettingsHandler(), RemoveSettingsHandler().
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut authored and sergeyn committed Mar 19, 2022
1 parent d6fa106 commit 8f8defa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
18 changes: 16 additions & 2 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4479,11 +4479,11 @@ void ImGui::Initialize(ImGuiContext* context)
ini_handler.ReadLineFn = WindowSettingsHandler_ReadLine;
ini_handler.ApplyAllFn = WindowSettingsHandler_ApplyAll;
ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll;
g.SettingsHandlers.push_back(ini_handler);
AddSettingsHandler(&ini_handler);
}

// Add .ini handle for ImGuiTable type
TableSettingsInstallHandler(context);
TableSettingsAddSettingsHandler();

// Create default viewport
ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)();
Expand Down Expand Up @@ -11618,6 +11618,20 @@ ImGuiWindowSettings* ImGui::FindOrCreateWindowSettings(const char* name)
return CreateNewWindowSettings(name);
}

void ImGui::AddSettingsHandler(const ImGuiSettingsHandler* handler)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(FindSettingsHandler(handler->TypeName) == NULL);
g.SettingsHandlers.push_back(*handler);
}

void ImGui::RemoveSettingsHandler(const char* type_name)
{
ImGuiContext& g = *GImGui;
if (ImGuiSettingsHandler* handler = FindSettingsHandler(type_name))
g.SettingsHandlers.erase(handler);
}

ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
{
ImGuiContext& g = *GImGui;
Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Index of this file:
// Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
#define IMGUI_VERSION "1.88 WIP"
#define IMGUI_VERSION_NUM 18709
#define IMGUI_VERSION_NUM 18710
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE

Expand Down
4 changes: 3 additions & 1 deletion imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,8 @@ namespace ImGui
IMGUI_API ImGuiWindowSettings* CreateNewWindowSettings(const char* name);
IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id);
IMGUI_API ImGuiWindowSettings* FindOrCreateWindowSettings(const char* name);
IMGUI_API void AddSettingsHandler(const ImGuiSettingsHandler* handler);
IMGUI_API void RemoveSettingsHandler(const char* type_name);
IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name);

// Scrolling
Expand Down Expand Up @@ -2744,7 +2746,7 @@ namespace ImGui
IMGUI_API void TableSaveSettings(ImGuiTable* table);
IMGUI_API void TableResetSettings(ImGuiTable* table);
IMGUI_API ImGuiTableSettings* TableGetBoundSettings(ImGuiTable* table);
IMGUI_API void TableSettingsInstallHandler(ImGuiContext* context);
IMGUI_API void TableSettingsAddSettingsHandler();
IMGUI_API ImGuiTableSettings* TableSettingsCreate(ImGuiID id, int columns_count);
IMGUI_API ImGuiTableSettings* TableSettingsFindByID(ImGuiID id);

Expand Down
5 changes: 2 additions & 3 deletions imgui_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3433,9 +3433,8 @@ static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandle
}
}

void ImGui::TableSettingsInstallHandler(ImGuiContext* context)
void ImGui::TableSettingsAddSettingsHandler()
{
ImGuiContext& g = *context;
ImGuiSettingsHandler ini_handler;
ini_handler.TypeName = "Table";
ini_handler.TypeHash = ImHashStr("Table");
Expand All @@ -3444,7 +3443,7 @@ void ImGui::TableSettingsInstallHandler(ImGuiContext* context)
ini_handler.ReadLineFn = TableSettingsHandler_ReadLine;
ini_handler.ApplyAllFn = TableSettingsHandler_ApplyAll;
ini_handler.WriteAllFn = TableSettingsHandler_WriteAll;
g.SettingsHandlers.push_back(ini_handler);
AddSettingsHandler(&ini_handler);
}

//-------------------------------------------------------------------------
Expand Down

0 comments on commit 8f8defa

Please sign in to comment.