Fonts: proof of concept support for user textures.

# Conflicts:
#	imgui.h
#	imgui_internal.h
This commit is contained in:
ocornut
2025-05-12 10:22:15 +02:00
committed by ocornut
parent 91ed6e67b4
commit 39f6c793b3
3 changed files with 22 additions and 1 deletions

View File

@@ -5231,6 +5231,8 @@ static void ImGui::UpdateTexturesEndFrame()
tex->RefCount = (unsigned short)atlas->RefCount;
g.PlatformIO.Textures.push_back(tex);
}
for (ImTextureData* tex : g.UserTextures)
g.PlatformIO.Textures.push_back(tex);
}
// Called once a frame. Followed by SetCurrentFont() which sets up the remaining data.
@@ -8613,6 +8615,19 @@ void ImGui::UpdateFontsEndFrame()
PopFont();
}
void ImGui::RegisterUserTexture(ImTextureData* tex)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(tex->RefCount > 0);
g.UserTextures.push_back(tex);
}
void ImGui::UnregisterUserTexture(ImTextureData* tex)
{
ImGuiContext& g = *GImGui;
g.UserTextures.find_erase(tex);
}
void ImGui::RegisterFontAtlas(ImFontAtlas* atlas)
{
ImGuiContext& g = *GImGui;

View File

@@ -3905,7 +3905,7 @@ struct ImGuiPlatformIO
// Textures list (the list is updated by calling ImGui::EndFrame or ImGui::Render)
// The ImGui_ImplXXXX_RenderDrawData() function of each backend generally access this via ImDrawData::Textures which points to this. The array is available here mostly because backends will want to destroy textures on shutdown.
ImVector<ImTextureData*> Textures; // List of textures used by Dear ImGui (most often 1).
ImVector<ImTextureData*> Textures; // List of textures used by Dear ImGui (most often 1) + contents of external texture list is automatically appended into this.
};
// (Optional) Support for IME (Input Method Editor) via the platform_io.Platform_SetImeDataFn() function. Handler is called during EndFrame().

View File

@@ -2426,6 +2426,10 @@ struct ImGuiContext
ImGuiPlatformImeData PlatformImeData; // Data updated by current frame. Will be applied at end of the frame. For some backends, this is required to have WantVisible=true in order to receive text message.
ImGuiPlatformImeData PlatformImeDataPrev; // Previous frame data. When changed we call the platform_io.Platform_SetImeDataFn() handler.
// Extensions
// FIXME: We could provide an API to register one slot in an array held in ImGuiContext?
ImVector<ImTextureData*> UserTextures; // List of textures created/managed by user or third-party extension. Automatically appended into platform_io.Textures[].
// Settings
bool SettingsLoaded;
float SettingsDirtyTimer; // Save .ini Settings to memory when time reaches zero
@@ -3108,6 +3112,8 @@ namespace ImGui
IMGUI_API void SetNextWindowRefreshPolicy(ImGuiWindowRefreshFlags flags);
// Fonts, drawing
IMGUI_API void RegisterUserTexture(ImTextureData* tex); // Register external texture
IMGUI_API void UnregisterUserTexture(ImTextureData* tex);
IMGUI_API void RegisterFontAtlas(ImFontAtlas* atlas);
IMGUI_API void UnregisterFontAtlas(ImFontAtlas* atlas);
IMGUI_API void SetCurrentFont(ImFont* font, float font_size);