Browse Source

Fonts: narrowed invalid value for ImFontAtlasRectId to -1 a we will change implementation.

ocornut 5 months ago
parent
commit
85d0507580
3 changed files with 13 additions and 13 deletions
  1. 1 1
      imgui.h
  2. 11 11
      imgui_draw.cpp
  3. 1 1
      imgui_internal.h

+ 1 - 1
imgui.h

@@ -3577,7 +3577,7 @@ struct ImFontAtlas
     // You can request arbitrary rectangles to be packed into the atlas, for your own purpose.
     // You can request your rectangles to be mapped as font glyph (given a font + Unicode point),
     // so you can render e.g. custom colorful icons and use them as regular glyphs.
-    // - Since 1.92.X, packing is done immediately in the function call. Returns >= on success, <0 on error.
+    // - Since 1.92.X, packing is done immediately in the function call. Returns -1 on error.
     // - You can render your pixels into the texture right after calling the AddCustomRectXXX() functions.
     // - If your backend supports ImGuiBackendFlags_RendererHasTextures:
     //   Texture may be resized, so you cannot cache UV coordinates: always use CalcCustomRectUV().

+ 11 - 11
imgui_draw.cpp

@@ -3235,7 +3235,7 @@ int ImFontAtlas::AddCustomRectRegular(int width, int height)
         ImFontAtlasBuildInit(this);
 
     ImFontAtlasRectId r_id = ImFontAtlasPackAddRect(this, width, height);
-    if (r_id < 0)
+    if (r_id == -1)
         return -1;
     ImTextureRect* r = ImFontAtlasPackGetRect(this, r_id);
     if (RendererHasTextures)
@@ -3269,7 +3269,7 @@ int ImFontAtlas::AddCustomRectFontGlyphForSize(ImFont* font, float font_size, Im
     ImFontBaked* baked = font->GetFontBaked(font_size);
 
     ImFontAtlasRectId r_id = ImFontAtlasPackAddRect(this, width, height);
-    if (r_id < 0)
+    if (r_id == -1)
         return -1;
     ImTextureRect* r = ImFontAtlasPackGetRect(this, r_id);
     if (RendererHasTextures)
@@ -3447,7 +3447,7 @@ static void ImFontAtlasBuildUpdateBasicTexData(ImFontAtlas* atlas, bool add_and_
 
     if (add_and_draw)
         builder->PackIdMouseCursors = ImFontAtlasPackAddRect(atlas, pack_size.x, pack_size.y);
-    if (builder->PackIdMouseCursors < 0)
+    if (builder->PackIdMouseCursors == -1)
         return;
     ImTextureRect* r = ImFontAtlasPackGetRect(atlas, builder->PackIdMouseCursors);
 
@@ -3483,7 +3483,7 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
     ImFontAtlasBuilder* builder = atlas->Builder;
     if (add_and_draw)
         builder->PackIdLinesTexData = ImFontAtlasPackAddRect(atlas, pack_size.x, pack_size.y);
-    if (builder->PackIdLinesTexData < 0)
+    if (builder->PackIdLinesTexData == -1)
         return;
     ImTextureRect* r = ImFontAtlasPackGetRect(atlas, builder->PackIdLinesTexData);
 
@@ -3705,7 +3705,7 @@ void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, Im
 
 void ImFontAtlasBuildDiscardFontBakedGlyph(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked, ImFontGlyph* glyph)
 {
-    if (glyph->PackId >= 0)
+    if (glyph->PackId != -1)
     {
         ImFontAtlasPackDiscardRect(atlas, glyph->PackId);
         glyph->PackId = -1;
@@ -3780,7 +3780,7 @@ void ImFontAtlasBuildDiscardFontBaked(ImFontAtlas* atlas, ImFont* font, ImFontBa
     IMGUI_DEBUG_LOG_FONT("[font] Discard baked %.2f for \"%s\"\n", baked->Size, font->GetDebugName());
 
     for (ImFontGlyph& glyph : baked->Glyphs)
-        if (glyph.PackId >= 0)
+        if (glyph.PackId != -1)
             ImFontAtlasPackDiscardRect(atlas, glyph.PackId);
 
     char* loader_data_p = (char*)baked->FontLoaderDatas;
@@ -4235,7 +4235,7 @@ static ImFontAtlasRectId ImFontAtlasPackAllocRectEntry(ImFontAtlas* atlas, int r
 // This is expected to be called in batches and followed by a repack
 void ImFontAtlasPackDiscardRect(ImFontAtlas* atlas, ImFontAtlasRectId id)
 {
-    IM_ASSERT(id >= 0);
+    IM_ASSERT(id != -1);
     ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
     ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[id];
     IM_ASSERT(index_entry->Used && index_entry->TargetIndex >= 0);
@@ -4310,7 +4310,7 @@ ImFontAtlasRectId ImFontAtlasPackAddRect(ImFontAtlas* atlas, int w, int h, ImFon
 // Important: don'return pointer valid until next call to AddRect(), e.g. FindGlyph(), CalcTextSize() can all potentially invalidate previous pointers.
 ImTextureRect* ImFontAtlasPackGetRect(ImFontAtlas* atlas, ImFontAtlasRectId id)
 {
-    IM_ASSERT(id >= 0);
+    IM_ASSERT(id != -1);
     ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
     ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[id];
     IM_ASSERT(index_entry->Used);
@@ -4541,10 +4541,10 @@ static ImFontGlyph* ImGui_ImplStbTrueType_FontBakedLoadGlyph(ImFontAtlas* atlas,
         const int w = (x1 - x0 + oversample_h - 1);
         const int h = (y1 - y0 + oversample_v - 1);
         ImFontAtlasRectId pack_id = ImFontAtlasPackAddRect(atlas, w, h);
-        if (pack_id < 0)
+        if (pack_id == -1)
         {
             // Pathological out of memory case (TexMaxWidth/TexMaxHeight set too small?)
-            IM_ASSERT_USER_ERROR(pack_id >= 0, "Out of texture memory.");
+            IM_ASSERT_USER_ERROR(pack_id != -1, "Out of texture memory.");
             return NULL;
         }
         ImTextureRect* r = ImFontAtlasPackGetRect(atlas, pack_id);
@@ -4993,7 +4993,7 @@ ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked
     IM_ASSERT(baked->Glyphs.Size < 0xFFFE); // IndexLookup[] hold 16-bit values and -1/-2 are reserved.
 
     // Set UV from packed rectangle
-    if (in_glyph->PackId >= 0)
+    if (in_glyph->PackId != -1)
     {
         ImTextureRect* r = ImFontAtlasPackGetRect(atlas, in_glyph->PackId);
         IM_ASSERT(in_glyph->U0 == 0.0f && in_glyph->V0 == 0.0f && in_glyph->U1 == 0.0f && in_glyph->V1 == 0.0f);

+ 1 - 1
imgui_internal.h

@@ -3691,7 +3691,7 @@ IMGUI_API const ImFontLoader* ImFontAtlasGetFontLoaderForStbTruetype();
 // [SECTION] ImFontAtlas internal API
 //-----------------------------------------------------------------------------
 
-typedef int ImFontAtlasRectId;          // <0 when invalid
+typedef int ImFontAtlasRectId; // -1 when invalid
 
 // Packed rectangle lookup entry (we need an indirection to allow removing/reordering rectangles)
 // User are returned ImFontAtlasRectId values which are meant to be persistent.