mirror of
https://github.com/ocornut/imgui.git
synced 2025-09-07 03:48:25 +00:00
(Breaking) Fonts: rename GetCustomRectByIndex() to GetCustomRect(). Made return struct const.
This commit is contained in:
@@ -357,7 +357,7 @@ You can ask questions in [#8466](https://github.com/ocornut/imgui/issues/8466).
|
|||||||
As an alternative to rendering colorful glyphs using imgui_freetype with `ImGuiFreeTypeBuilderFlags_LoadColor`, you may allocate your own space in the texture atlas and write yourself into it. **(This is a BETA api, use if you are familiar with dear imgui and with your rendering backend)**
|
As an alternative to rendering colorful glyphs using imgui_freetype with `ImGuiFreeTypeBuilderFlags_LoadColor`, you may allocate your own space in the texture atlas and write yourself into it. **(This is a BETA api, use if you are familiar with dear imgui and with your rendering backend)**
|
||||||
|
|
||||||
- You can use the `ImFontAtlas::AddCustomRect()` and `ImFontAtlas::AddCustomRectFontGlyph()` api to register rectangles that will be packed into the font atlas texture. Register them before building the atlas, then call Build()`.
|
- You can use the `ImFontAtlas::AddCustomRect()` and `ImFontAtlas::AddCustomRectFontGlyph()` api to register rectangles that will be packed into the font atlas texture. Register them before building the atlas, then call Build()`.
|
||||||
- You can then use `ImFontAtlas::GetCustomRectByIndex(int)` to query the position/size of your rectangle within the texture, and blit/copy any graphics data of your choice into those rectangles.
|
- You can then use `ImFontAtlas::GetCustomRect(int)` to query the position/size of your rectangle within the texture, and blit/copy any graphics data of your choice into those rectangles.
|
||||||
- This API is beta because it is likely to change in order to support multi-dpi (multiple viewports on multiple monitors with varying DPI scale).
|
- This API is beta because it is likely to change in order to support multi-dpi (multiple viewports on multiple monitors with varying DPI scale).
|
||||||
|
|
||||||
#### Pseudo-code:
|
#### Pseudo-code:
|
||||||
@@ -377,9 +377,7 @@ int tex_width, tex_height;
|
|||||||
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height);
|
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height);
|
||||||
|
|
||||||
for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++)
|
for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++)
|
||||||
{
|
if (const ImTextureRect* rect = io.Fonts->GetCustomRect(rect_ids[rect_n]))
|
||||||
int rect_id = rect_ids[rect_n];
|
|
||||||
if (const ImFontAtlasCustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id))
|
|
||||||
{
|
{
|
||||||
// Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!)
|
// Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!)
|
||||||
for (int y = 0; y < rect->Height; y++)
|
for (int y = 0; y < rect->Height; y++)
|
||||||
@@ -389,7 +387,6 @@ for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++)
|
|||||||
*p++ = IM_COL32(255, 0, 0, 255);
|
*p++ = IM_COL32(255, 0, 0, 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
##### [Return to Index](#index)
|
##### [Return to Index](#index)
|
||||||
|
28
imgui.h
28
imgui.h
@@ -3574,24 +3574,24 @@ struct ImFontAtlas
|
|||||||
// [ALPHA] Custom Rectangles/Glyphs API
|
// [ALPHA] Custom Rectangles/Glyphs API
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
|
|
||||||
// You can request arbitrary rectangles to be packed into the atlas, for your own purpose.
|
// Register and retrieve custom rectangles
|
||||||
// You can request your rectangles to be mapped as font glyph (given a font + Unicode point),
|
// - You can request arbitrary rectangles to be packed into the atlas, for your own purpose.
|
||||||
// so you can render e.g. custom colorful icons and use them as regular glyphs.
|
// - You can request your rectangles to be mapped as font glyph (given a font + Unicode point),
|
||||||
// - Since 1.92.X, packing is done immediately in the function call. Returns -1 on error.
|
// 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.
|
||||||
// - You can render your pixels into the texture right after calling the AddCustomRectXXX() functions.
|
// - 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()!
|
||||||
// Texture may be resized, so you cannot cache UV coordinates: always use CalcCustomRectUV().
|
// - If you render colored output into your AddCustomRectRegular() rectangle: set 'atlas->TexPixelsUseColors = true' as this may help some backends decide of preferred texture format.
|
||||||
// - If you render colored output into your AddCustomRectRegular() rectangle: set 'atlas->TexPixelsUseColors = true'
|
|
||||||
// as this may help some backends decide of preferred texture format.
|
|
||||||
// - Read docs/FONTS.md for more details about using colorful icons.
|
// - Read docs/FONTS.md for more details about using colorful icons.
|
||||||
// - Note: this API may be redesigned later in order to support multi-monitor varying DPI settings.
|
// - Note: this API may be reworked further in order to facilitate supporting e.g. multi-monitor, varying DPI settings.
|
||||||
IMGUI_API int AddCustomRectRegular(int width, int height);
|
IMGUI_API int AddCustomRectRegular(int width, int height); // Register a rectangle. Return -1 on error.
|
||||||
|
IMGUI_API const ImTextureRect* GetCustomRect(int id); // Get rectangle coordinate in current texture.
|
||||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0, 0));
|
IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0, 0));
|
||||||
IMGUI_API int AddCustomRectFontGlyphForSize(ImFont* font, float font_size, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0, 0));
|
IMGUI_API int AddCustomRectFontGlyphForSize(ImFont* font, float font_size, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0, 0));
|
||||||
|
inline const ImTextureRect* GetCustomRectByIndex(int id) { return GetCustomRect(id); }
|
||||||
#endif
|
#endif
|
||||||
IMGUI_API ImTextureRect* GetCustomRectByIndex(int index);
|
IMGUI_API void CalcCustomRectUV(const ImTextureRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const;
|
||||||
IMGUI_API void CalcCustomRectUV(const ImTextureRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const;
|
|
||||||
|
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
// Members
|
// Members
|
||||||
|
@@ -2500,7 +2500,7 @@ void ImTextureData::DestroyPixels()
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// - ImFontAtlas::AddCustomRectRegular()
|
// - ImFontAtlas::AddCustomRectRegular()
|
||||||
// - ImFontAtlas::AddCustomRectFontGlyph()
|
// - ImFontAtlas::AddCustomRectFontGlyph()
|
||||||
// - ImFontAtlas::GetCustomRectByIndex()
|
// - ImFontAtlas::GetCustomRect()
|
||||||
// - ImFontAtlas::CalcCustomRectUV()
|
// - ImFontAtlas::CalcCustomRectUV()
|
||||||
// - ImFontAtlasGetMouseCursorTexData()
|
// - ImFontAtlasGetMouseCursorTexData()
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -3293,9 +3293,9 @@ int ImFontAtlas::AddCustomRectFontGlyphForSize(ImFont* font, float font_size, Im
|
|||||||
}
|
}
|
||||||
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|
||||||
ImTextureRect* ImFontAtlas::GetCustomRectByIndex(int idx)
|
const ImTextureRect* ImFontAtlas::GetCustomRect(int id)
|
||||||
{
|
{
|
||||||
return ImFontAtlasPackGetRect(this, idx);
|
return ImFontAtlasPackGetRect(this, (ImFontAtlasRectId)id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImFontAtlas::CalcCustomRectUV(const ImTextureRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const
|
void ImFontAtlas::CalcCustomRectUV(const ImTextureRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const
|
||||||
|
@@ -3691,7 +3691,9 @@ IMGUI_API const ImFontLoader* ImFontAtlasGetFontLoaderForStbTruetype();
|
|||||||
// [SECTION] ImFontAtlas internal API
|
// [SECTION] ImFontAtlas internal API
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef int ImFontAtlasRectId; // -1 when invalid
|
// An identifier to a rectangle in the atlas. -1 when invalid.
|
||||||
|
// The rectangle may move, use GetCustomRect() to retrieve it.
|
||||||
|
typedef int ImFontAtlasRectId;
|
||||||
|
|
||||||
// Packed rectangle lookup entry (we need an indirection to allow removing/reordering rectangles)
|
// Packed rectangle lookup entry (we need an indirection to allow removing/reordering rectangles)
|
||||||
// User are returned ImFontAtlasRectId values which are meant to be persistent.
|
// User are returned ImFontAtlasRectId values which are meant to be persistent.
|
||||||
|
Reference in New Issue
Block a user