Updated ImGui.

This commit is contained in:
Бранимир Караџић
2025-05-10 19:59:27 -07:00
parent 56dd9f4ae1
commit 636a860b0e
5 changed files with 48 additions and 11 deletions

View File

@@ -15493,6 +15493,18 @@ static void MetricsHelpMarker(const char* desc)
// [DEBUG] List fonts in a font atlas and display its texture
void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
{
ImGuiContext& g = *GImGui;
Text("Read ");
SameLine(0, 0);
TextLinkOpenURL("https://www.dearimgui.com/faq/");
SameLine(0, 0);
Text(" for details on font loading.");
ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
Checkbox("Show font preview", &cfg->ShowFontPreview);
// Font list
for (ImFont* font : atlas->Fonts)
{
PushID(font);
@@ -15501,7 +15513,6 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
}
if (TreeNode("Font Atlas", "Font Atlas (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
{
ImGuiContext& g = *GImGui;
PushStyleVar(ImGuiStyleVar_ImageBorderSize, ImMax(1.0f, g.Style.ImageBorderSize));
ImageWithBg(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
PopStyleVar();
@@ -16292,6 +16303,8 @@ void ImGui::DebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list, co
// [DEBUG] Display details for a single font, called by ShowStyleEditor().
void ImGui::DebugNodeFont(ImFont* font)
{
ImGuiContext& g = *GImGui;
ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
bool opened = TreeNode(font, "Font: \"%s\": %.2f px, %d glyphs, %d sources(s)",
font->Sources ? font->Sources[0].Name : "", font->FontSize, font->Glyphs.Size, font->SourcesCount);
@@ -16299,9 +16312,12 @@ void ImGui::DebugNodeFont(ImFont* font)
if (!opened)
Indent();
Indent();
PushFont(font);
Text("The quick brown fox jumps over the lazy dog");
PopFont();
if (cfg->ShowFontPreview)
{
PushFont(font);
Text("The quick brown fox jumps over the lazy dog");
PopFont();
}
if (!opened)
{
Unindent();

View File

@@ -3540,7 +3540,7 @@ struct ImFont
IMGUI_API void ClearOutputData();
IMGUI_API void GrowIndex(int new_size);
IMGUI_API void AddGlyph(const ImFontConfig* src_cfg, ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x);
IMGUI_API void AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built.
IMGUI_API void AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst);// , bool overwrite_dst = true); // Makes 'from_codepoint' character points to 'to_codepoint' character. Currently needs to be called AFTER fonts have been built.
IMGUI_API bool IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last);
};

View File

@@ -82,6 +82,7 @@ Index of this file:
// [SECTION] DemoWindowWidgetsDisableBlocks()
// [SECTION] DemoWindowWidgetsDragAndDrop()
// [SECTION] DemoWindowWidgetsDragsAndSliders()
// [SECTION] DemoWindowWidgetsFonts()
// [SECTION] DemoWindowWidgetsImages()
// [SECTION] DemoWindowWidgetsListBoxes()
// [SECTION] DemoWindowWidgetsMultiComponents()
@@ -1719,6 +1720,24 @@ static void DemoWindowWidgetsDragsAndSliders()
}
}
//-----------------------------------------------------------------------------
// [SECTION] DemoWindowWidgetsFonts()
//-----------------------------------------------------------------------------
// Forward declare ShowFontAtlas() which isn't worth putting in public API yet
namespace ImGui { IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); }
static void DemoWindowWidgetsFonts()
{
IMGUI_DEMO_MARKER("Widgets/Fonts");
if (ImGui::TreeNode("Fonts"))
{
ImFontAtlas* atlas = ImGui::GetIO().Fonts;
ImGui::ShowFontAtlas(atlas);
ImGui::TreePop();
}
}
//-----------------------------------------------------------------------------
// [SECTION] DemoWindowWidgetsImages()
//-----------------------------------------------------------------------------
@@ -4182,6 +4201,7 @@ static void DemoWindowWidgets(ImGuiDemoWindowData* demo_data)
DemoWindowWidgetsDragAndDrop();
DemoWindowWidgetsDragsAndSliders();
DemoWindowWidgetsFonts();
DemoWindowWidgetsImages();
DemoWindowWidgetsListBoxes();
DemoWindowWidgetsMultiComponents();

View File

@@ -3885,19 +3885,19 @@ void ImFont::AddGlyph(const ImFontConfig* src, ImWchar codepoint, float x0, floa
MetricsTotalSurface += (int)((glyph.U1 - glyph.U0) * ContainerAtlas->TexWidth + pad) * (int)((glyph.V1 - glyph.V0) * ContainerAtlas->TexHeight + pad);
}
void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)
void ImFont::AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst)
{
IM_ASSERT(IndexLookup.Size > 0); // Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function.
unsigned int index_size = (unsigned int)IndexLookup.Size;
if (dst < index_size && IndexLookup.Data[dst] == (ImU16)-1 && !overwrite_dst) // 'dst' already exists
if (from_codepoint < index_size && IndexLookup.Data[from_codepoint] == (ImU16)-1 && !overwrite_dst) // 'from_codepoint' already exists
return;
if (src >= index_size && dst >= index_size) // both 'dst' and 'src' don't exist -> no-op
if (to_codepoint >= index_size && from_codepoint >= index_size) // both 'from_codepoint' and 'to_codepoint' don't exist -> no-op
return;
GrowIndex(dst + 1);
IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : (ImU16)-1;
IndexAdvanceX[dst] = (src < index_size) ? IndexAdvanceX.Data[src] : 1.0f;
GrowIndex(from_codepoint + 1);
IndexLookup[from_codepoint] = (to_codepoint < index_size) ? IndexLookup.Data[to_codepoint] : (ImU16)-1;
IndexAdvanceX[from_codepoint] = (to_codepoint < index_size) ? IndexAdvanceX.Data[to_codepoint] : 1.0f;
}
// Find glyph, return fallback if missing

View File

@@ -2020,6 +2020,7 @@ struct ImGuiMetricsConfig
int ShowTablesRectsType = -1;
int HighlightMonitorIdx = -1;
ImGuiID HighlightViewportID = 0;
bool ShowFontPreview = true;
};
struct ImGuiStackLevelInfo