Parcourir la source

(Breaking) Fonts: removing obsolete ImFont::Scale.

ocornut il y a 2 mois
Parent
commit
e3860aa6ac
4 fichiers modifiés avec 16 ajouts et 5 suppressions
  1. 10 3
      imgui.cpp
  2. 3 1
      imgui.h
  3. 2 0
      imgui_draw.cpp
  4. 1 1
      imgui_internal.h

+ 10 - 3
imgui.cpp

@@ -8683,7 +8683,9 @@ void ImGui::SetCurrentFont(ImFont* font, float font_size)
     if (font != NULL)
     if (font != NULL)
     {
     {
         IM_ASSERT(font && font->IsLoaded());    // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
         IM_ASSERT(font && font->IsLoaded());    // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
         IM_ASSERT(font->Scale > 0.0f);
         IM_ASSERT(font->Scale > 0.0f);
+#endif
         g.DrawListSharedData.Font = g.Font;
         g.DrawListSharedData.Font = g.Font;
         ImFontAtlasUpdateDrawListsSharedData(g.Font->ContainerAtlas);
         ImFontAtlasUpdateDrawListsSharedData(g.Font->ContainerAtlas);
         if (g.CurrentWindow != NULL)
         if (g.CurrentWindow != NULL)
@@ -8699,7 +8701,10 @@ void ImGui::UpdateCurrentFontSize()
         return;
         return;
 
 
     float final_size = g.FontSizeBeforeScaling * g.IO.FontGlobalScale;
     float final_size = g.FontSizeBeforeScaling * g.IO.FontGlobalScale;
-    final_size *= g.Font->Scale;
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
+    if (g.Font != NULL)
+        final_size *= g.Font->Scale;
+#endif
     if (window != NULL)
     if (window != NULL)
         final_size *= window->FontWindowScale;
         final_size *= window->FontWindowScale;
 
 
@@ -16753,14 +16758,16 @@ void ImGui::DebugNodeFont(ImFont* font)
         ImFontAtlasFontDiscardBakes(atlas, font, 2);
         ImFontAtlasFontDiscardBakes(atlas, font, 2);
 
 
     // Display details
     // Display details
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
     SetNextItemWidth(GetFontSize() * 8);
     SetNextItemWidth(GetFontSize() * 8);
     DragFloat("Font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f");
     DragFloat("Font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f");
-    SameLine(); MetricsHelpMarker(
+    /*SameLine(); MetricsHelpMarker(
         "Note that the default embedded font is NOT meant to be scaled.\n\n"
         "Note that the default embedded font is NOT meant to be scaled.\n\n"
         "Font are currently rendered into bitmaps at a given size at the time of building the atlas. "
         "Font are currently rendered into bitmaps at a given size at the time of building the atlas. "
         "You may oversample them to get some flexibility with scaling. "
         "You may oversample them to get some flexibility with scaling. "
         "You can also render at multiple sizes and select which one to use at runtime.\n\n"
         "You can also render at multiple sizes and select which one to use at runtime.\n\n"
-        "(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)");
+        "(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)");*/
+#endif
 
 
     char c_str[5];
     char c_str[5];
     Text("Fallback character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->FallbackChar), font->FallbackChar);
     Text("Fallback character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->FallbackChar), font->FallbackChar);

+ 3 - 1
imgui.h

@@ -3762,10 +3762,12 @@ struct ImFont
     ImVector<ImFontConfig*>     Sources;            // 16    // in  // List of sources. Pointers within ContainerAtlas->Sources[]
     ImVector<ImFontConfig*>     Sources;            // 16    // in  // List of sources. Pointers within ContainerAtlas->Sources[]
     ImWchar                     EllipsisChar;       // 2-4   // out // Character used for ellipsis rendering ('...').
     ImWchar                     EllipsisChar;       // 2-4   // out // Character used for ellipsis rendering ('...').
     ImWchar                     FallbackChar;       // 2-4   // out // Character used if a glyph isn't found (U+FFFD, '?')
     ImWchar                     FallbackChar;       // 2-4   // out // Character used if a glyph isn't found (U+FFFD, '?')
-    float                       Scale;              // 4     // in  // Base font scale (~1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
     ImU8                        Used8kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/8192/8]; // 1 bytes if ImWchar=ImWchar16, 16 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations across all used codepoints.
     ImU8                        Used8kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/8192/8]; // 1 bytes if ImWchar=ImWchar16, 16 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations across all used codepoints.
     bool                        EllipsisAutoBake;   // 1     //     // Mark when the "..." glyph needs to be generated.
     bool                        EllipsisAutoBake;   // 1     //     // Mark when the "..." glyph needs to be generated.
     ImGuiStorage                RemapPairs;         // 16    //     // Remapping pairs when using AddRemapChar(), otherwise empty.
     ImGuiStorage                RemapPairs;         // 16    //     // Remapping pairs when using AddRemapChar(), otherwise empty.
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
+    float                       Scale;              // 4     // in  // Legacy base font scale (~1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
+#endif
 
 
     // Methods
     // Methods
     IMGUI_API ImFont();
     IMGUI_API ImFont();

+ 2 - 0
imgui_draw.cpp

@@ -5018,7 +5018,9 @@ void ImFontBaked::ClearOutputData()
 ImFont::ImFont()
 ImFont::ImFont()
 {
 {
     memset(this, 0, sizeof(*this));
     memset(this, 0, sizeof(*this));
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
     Scale = 1.0f;
     Scale = 1.0f;
+#endif
 }
 }
 
 
 ImFont::~ImFont()
 ImFont::~ImFont()

+ 1 - 1
imgui_internal.h

@@ -2139,7 +2139,7 @@ struct ImGuiContext
     ImFont*                 Font;                               // Currently bound font. (== FontStack.back().Font)
     ImFont*                 Font;                               // Currently bound font. (== FontStack.back().Font)
     ImFontBaked*            FontBaked;                          // Currently bound font at currently bound size. (== Font->GetFontBaked(FontSize))
     ImFontBaked*            FontBaked;                          // Currently bound font at currently bound size. (== Font->GetFontBaked(FontSize))
     float                   FontSize;                           // Currently bound font size == line height (== FontSizeBeforeScaling * io.FontGlobalScale * font->Scale * g.CurrentWindow->FontWindowScale).
     float                   FontSize;                           // Currently bound font size == line height (== FontSizeBeforeScaling * io.FontGlobalScale * font->Scale * g.CurrentWindow->FontWindowScale).
-    float                   FontSizeBeforeScaling;              // == value passed to PushFontSize()
+    float                   FontSizeBeforeScaling;              // == value passed to PushFont() / PushFontSize() when specified.
     float                   FontScale;                          // == FontBaked->Size / Font->FontSize. Scale factor over baked size.
     float                   FontScale;                          // == FontBaked->Size / Font->FontSize. Scale factor over baked size.
     float                   FontRasterizerDensity;              // Current font density. Used by all calls to GetFontBaked().
     float                   FontRasterizerDensity;              // Current font density. Used by all calls to GetFontBaked().
     float                   CurrentDpiScale;                    // Current window/viewport DpiScale == CurrentViewport->DpiScale
     float                   CurrentDpiScale;                    // Current window/viewport DpiScale == CurrentViewport->DpiScale