@@ -5068,6 +5068,8 @@ static void InitViewportDrawData(ImGuiViewportP* viewport)
5068
5068
// - If the code here changes, may need to update code of functions like NextColumn() and PushColumnClipRect():
5069
5069
// some frequently called functions which to modify both channels and clipping simultaneously tend to use the
5070
5070
// more specialized SetWindowClipRectBeforeSetChannel() to avoid extraneous updates of underlying ImDrawCmds.
5071
+ // - This is analoguous to PushFont()/PopFont() in the sense that are a mixing a global stack and a window stack,
5072
+ // which in the case of ClipRect is not so problematic but tends to be more restrictive for fonts.
5071
5073
void ImGui::PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect)
5072
5074
{
5073
5075
ImGuiWindow* window = GetCurrentWindow();
@@ -7574,22 +7576,31 @@ void ImGui::SetCurrentFont(ImFont* font)
7574
7576
g.DrawListSharedData.FontScale = g.FontScale;
7575
7577
}
7576
7578
7579
+ // Use ImDrawList::_SetTextureID(), making our shared g.FontStack[] authorative against window-local ImDrawList.
7580
+ // - Whereas ImDrawList::PushTextureID()/PopTextureID() is not to be used across Begin() calls.
7581
+ // - Note that we don't propagate current texture id when e.g. Begin()-ing into a new window, we never really did...
7582
+ // - Some code paths never really fully worked with multiple atlas textures.
7583
+ // - The right-ish solution may be to remove _SetTextureID() and make AddText/RenderText lazily call PushTextureID()/PopTextureID()
7584
+ // the same way AddImage() does, but then all other primitives would also need to? I don't think we should tackle this problem
7585
+ // because we have a concrete need and a test bed for multiple atlas textures.
7577
7586
void ImGui::PushFont(ImFont* font)
7578
7587
{
7579
7588
ImGuiContext& g = *GImGui;
7580
- if (! font)
7589
+ if (font == NULL )
7581
7590
font = GetDefaultFont();
7582
- SetCurrentFont(font);
7583
7591
g.FontStack.push_back(font);
7584
- g.CurrentWindow->DrawList->PushTextureID(font->ContainerAtlas->TexID);
7592
+ SetCurrentFont(font);
7593
+ g.CurrentWindow->DrawList->_SetTextureID(font->ContainerAtlas->TexID);
7585
7594
}
7586
7595
7587
7596
void ImGui::PopFont()
7588
7597
{
7589
7598
ImGuiContext& g = *GImGui;
7590
- g.CurrentWindow->DrawList->PopTextureID( );
7599
+ IM_ASSERT(g.FontStack.Size > 0 );
7591
7600
g.FontStack.pop_back();
7592
- SetCurrentFont(g.FontStack.empty() ? GetDefaultFont() : g.FontStack.back());
7601
+ ImFont* font = g.FontStack.Size == 0 ? GetDefaultFont() : g.FontStack.back();
7602
+ SetCurrentFont(font);
7603
+ g.CurrentWindow->DrawList->_SetTextureID(font->ContainerAtlas->TexID);
7593
7604
}
7594
7605
7595
7606
void ImGui::PushItemFlag(ImGuiItemFlags option, bool enabled)
0 commit comments