Merge branch 'master' into docking

# Conflicts:
#	backends/imgui_impl_opengl2.cpp
#	backends/imgui_impl_opengl3.cpp
#	imgui.cpp
This commit is contained in:
ocornut
2025-07-22 18:38:50 +09:00
26 changed files with 344 additions and 230 deletions

116
imgui.cpp
View File

@@ -1,4 +1,4 @@
// dear imgui, v1.92.1
// dear imgui, v1.92.2 WIP
// (main code and documentation)
// Help:
@@ -78,7 +78,7 @@ CODE
// [SECTION] RENDER HELPERS
// [SECTION] INITIALIZATION, SHUTDOWN
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
// [SECTION] FONTS
// [SECTION] FONTS, TEXTURES
// [SECTION] ID STACK
// [SECTION] INPUTS
// [SECTION] ERROR CHECKING, STATE RECOVERY
@@ -2644,11 +2644,11 @@ static inline int ImTextCharToUtf8_inline(char* buf, int buf_size, unsigned int
return 0;
}
const char* ImTextCharToUtf8(char out_buf[5], unsigned int c)
int ImTextCharToUtf8(char out_buf[5], unsigned int c)
{
int count = ImTextCharToUtf8_inline(out_buf, 5, c);
out_buf[count] = 0;
return out_buf;
return count;
}
// Not optimal but we very rarely use this function.
@@ -5442,46 +5442,6 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags(const ImVec2& mouse_pos)
io.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false;
}
static void ImGui::UpdateTexturesNewFrame()
{
// Cannot update every atlases based on atlas's FrameCount < g.FrameCount, because an atlas may be shared by multiple contexts with different frame count.
ImGuiContext& g = *GImGui;
const bool has_textures = (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasTextures) != 0;
for (ImFontAtlas* atlas : g.FontAtlases)
{
if (atlas->OwnerContext == &g)
{
ImFontAtlasUpdateNewFrame(atlas, g.FrameCount, has_textures);
}
else
{
// (1) If you manage font atlases yourself, e.g. create a ImFontAtlas yourself you need to call ImFontAtlasUpdateNewFrame() on it.
// Otherwise, calling ImGui::CreateContext() without parameter will create an atlas owned by the context.
// (2) If you have multiple font atlases, make sure the 'atlas->RendererHasTextures' as specified in the ImFontAtlasUpdateNewFrame() call matches for that.
// (3) If you have multiple imgui contexts, they also need to have a matching value for ImGuiBackendFlags_RendererHasTextures.
IM_ASSERT(atlas->Builder != NULL && atlas->Builder->FrameCount != -1);
IM_ASSERT(atlas->RendererHasTextures == has_textures);
}
}
}
// Build a single texture list
static void ImGui::UpdateTexturesEndFrame()
{
ImGuiContext& g = *GImGui;
g.PlatformIO.Textures.resize(0);
for (ImFontAtlas* atlas : g.FontAtlases)
for (ImTextureData* tex : atlas->TexList)
{
// We provide this information so backends can decide whether to destroy textures.
// This means in practice that if N imgui contexts are created with a shared atlas, we assume all of them have a backend initialized.
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.
// FIXME-VIEWPORT: the concept of a single ClipRectFullscreen is not ideal!
static void SetupDrawListSharedData()
@@ -8100,7 +8060,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
#endif
// Decide if we are going to handle borders and resize grips
const bool handle_borders_and_resize_grips = (window->DockNodeAsHost || !window->DockIsActive);
// 'window->SkipItems' is not updated yet so for child windows we rely on ParentWindow to avoid submitting decorations. (#8815)
// Whenever we add support for full decorated child windows we will likely make this logic more general.
bool handle_borders_and_resize_grips = (window->DockNodeAsHost || !window->DockIsActive);
if ((flags & ImGuiWindowFlags_ChildWindow) && window->ParentWindow->SkipItems)
handle_borders_and_resize_grips = false;
// Handle manual resize: Resize Grips, Borders, Gamepad
int border_hovered = -1, border_held = -1;
@@ -9282,11 +9246,13 @@ bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max)
}
//-----------------------------------------------------------------------------
// [SECTION] FONTS
// [SECTION] FONTS, TEXTURES
//-----------------------------------------------------------------------------
// Most of the relevant font logic is in imgui_draw.cpp.
// Those are high-level support functions.
//-----------------------------------------------------------------------------
// - UpdateTexturesNewFrame() [Internal]
// - UpdateTexturesEndFrame() [Internal]
// - UpdateFontsNewFrame() [Internal]
// - UpdateFontsEndFrame() [Internal]
// - GetDefaultFont() [Internal]
@@ -9301,6 +9267,46 @@ bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max)
// - PopFont()
//-----------------------------------------------------------------------------
static void ImGui::UpdateTexturesNewFrame()
{
// Cannot update every atlases based on atlas's FrameCount < g.FrameCount, because an atlas may be shared by multiple contexts with different frame count.
ImGuiContext& g = *GImGui;
const bool has_textures = (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasTextures) != 0;
for (ImFontAtlas* atlas : g.FontAtlases)
{
if (atlas->OwnerContext == &g)
{
ImFontAtlasUpdateNewFrame(atlas, g.FrameCount, has_textures);
}
else
{
// (1) If you manage font atlases yourself, e.g. create a ImFontAtlas yourself you need to call ImFontAtlasUpdateNewFrame() on it.
// Otherwise, calling ImGui::CreateContext() without parameter will create an atlas owned by the context.
// (2) If you have multiple font atlases, make sure the 'atlas->RendererHasTextures' as specified in the ImFontAtlasUpdateNewFrame() call matches for that.
// (3) If you have multiple imgui contexts, they also need to have a matching value for ImGuiBackendFlags_RendererHasTextures.
IM_ASSERT(atlas->Builder != NULL && atlas->Builder->FrameCount != -1);
IM_ASSERT(atlas->RendererHasTextures == has_textures);
}
}
}
// Build a single texture list
static void ImGui::UpdateTexturesEndFrame()
{
ImGuiContext& g = *GImGui;
g.PlatformIO.Textures.resize(0);
for (ImFontAtlas* atlas : g.FontAtlases)
for (ImTextureData* tex : atlas->TexList)
{
// We provide this information so backends can decide whether to destroy textures.
// This means in practice that if N imgui contexts are created with a shared atlas, we assume all of them have a backend initialized.
tex->RefCount = (unsigned short)atlas->RefCount;
g.PlatformIO.Textures.push_back(tex);
}
for (ImTextureData* tex : g.UserTextures)
g.PlatformIO.Textures.push_back(tex);
}
void ImGui::UpdateFontsNewFrame()
{
ImGuiContext& g = *GImGui;
@@ -9343,16 +9349,19 @@ ImFont* ImGui::GetDefaultFont()
return g.IO.FontDefault ? g.IO.FontDefault : atlas->Fonts[0];
}
// EXPERIMENTAL: DO NOT USE YET.
void ImGui::RegisterUserTexture(ImTextureData* tex)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(tex->RefCount > 0);
tex->RefCount++;
g.UserTextures.push_back(tex);
}
void ImGui::UnregisterUserTexture(ImTextureData* tex)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(tex->RefCount > 0);
tex->RefCount--;
g.UserTextures.find_erase(tex);
}
@@ -13184,7 +13193,7 @@ bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags)
IM_ASSERT(cur_window); // Not inside a Begin()/End()
const bool popup_hierarchy = (flags & ImGuiFocusedFlags_NoPopupHierarchy) == 0;
const bool dock_hierarchy = (flags & ImGuiFocusedFlags_DockHierarchy) != 0;
if (flags & ImGuiHoveredFlags_RootWindow)
if (flags & ImGuiFocusedFlags_RootWindow)
cur_window = GetCombinedRootWindow(cur_window, popup_hierarchy, dock_hierarchy);
if (flags & ImGuiHoveredFlags_ChildWindows)
@@ -22759,8 +22768,10 @@ void ImGui::DebugNodeFont(ImFont* font)
#endif
char c_str[5];
Text("Fallback character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->FallbackChar), font->FallbackChar);
Text("Ellipsis character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->EllipsisChar), font->EllipsisChar);
ImTextCharToUtf8(c_str, font->FallbackChar);
Text("Fallback character: '%s' (U+%04X)", c_str, font->FallbackChar);
ImTextCharToUtf8(c_str, font->EllipsisChar);
Text("Ellipsis character: '%s' (U+%04X)", c_str, font->EllipsisChar);
for (int src_n = 0; src_n < font->Sources.Size; src_n++)
{
@@ -22802,7 +22813,10 @@ void ImGui::DebugNodeFont(ImFont* font)
{
char utf8_buf[5];
for (unsigned int n = c; n < c_end; n++)
BulletText("Codepoint U+%04X (%s)", n, ImTextCharToUtf8(utf8_buf, n));
{
ImTextCharToUtf8(utf8_buf, n);
BulletText("Codepoint U+%04X (%s)", n, utf8_buf);
}
TreePop();
}
TableNextColumn();