mirror of
https://github.com/ocornut/imgui.git
synced 2026-02-03 03:50:06 +00:00
Merge branch 'master' into docking
This commit is contained in:
commit
7cd567202e
7 changed files with 100 additions and 21 deletions
|
|
@ -62,7 +62,7 @@ Breaking changes:
|
|||
- Fonts: **IMPORTANT**: if your app was solving the OSX/iOS Retina screen specific
|
||||
logical vs display scale problem by setting io.DisplayFramebufferScale (e.g. to 2.0f)
|
||||
+ setting io.FontGlobalScale (e.g. to 1.0f/2.0f) + loading fonts at scaled sizes (e.g. size X * 2.0f):
|
||||
This WILL NOT map correctly to the new system! Because font will rasterize as requested size.
|
||||
- This WILL NOT map correctly to the new system! Because font will rasterize as requested size.
|
||||
- With a legacy backend (< 1.92):
|
||||
- Instead of setting io.FontGlobalScale = 1.0f/N -> set ImFontCfg::RasterizerDensity = N.
|
||||
- This already worked before, but is now pretty much required.
|
||||
|
|
@ -83,7 +83,28 @@ Breaking changes:
|
|||
(not desirable as it requires e.g. all third-party code to be aware of it).
|
||||
- ImFont::FontSize was removed and does not make sense anymore.
|
||||
ImFont::LegacySize is the size passed to AddFont().
|
||||
- Removed support for PushFont(NULL) which was a shortcut for "default font".
|
||||
- Renamed/moved 'io.FontGlobalScale' to 'style.FontScaleMain'.
|
||||
- Fonts: **IMPORTANT** on Font Merging:
|
||||
- When searching for a glyph in multiple merged fonts: font inputs are now scanned in order
|
||||
for the first font input which the desired glyph. This is technically a different behavior
|
||||
than before!
|
||||
- e.g. If you are merging fonts you may have glyphs that you expected to load from
|
||||
Font Source 2 which exists in Font Source 1. After the update and when using a new backend,
|
||||
those glyphs may now loaded from Font Source 1!
|
||||
- You can use `ImFontConfig::GlyphExcludeRanges[]` to specify ranges to ignore in given Input:
|
||||
// Add Font Source 1 but ignore ICON_MIN_FA..ICON_MAX_FA range
|
||||
static ImWchar exclude_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
|
||||
ImFontConfig cfg1;
|
||||
cfg1.GlyphExcludeRanges = exclude_ranges;
|
||||
io.Fonts->AddFontFromFileTTF("segoeui.ttf", 0.0f, &cfg1);
|
||||
// Add Font Source 2, which expects to use the range above
|
||||
ImFontConfig cfg2;
|
||||
cfg2.MergeMode = true;
|
||||
io.Fonts->AddFontFromFileTTF("FontAwesome4.ttf", 0.0f, &cfg2);
|
||||
- You can use `Metrics/Debugger->Fonts->Font->Input Glyphs Overlap Detection Tool` to
|
||||
see list of glyphs available in multiple font sources. This can facilitate understanding
|
||||
which font input is providing which glyph.
|
||||
|
||||
- Textures:
|
||||
- All API functions taking a 'ImTextureID' parameter are now taking a 'ImTextureRef':
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ In the [misc/fonts/](https://github.com/ocornut/imgui/tree/master/misc/fonts) fo
|
|||
- [Loading Font Data from Memory](#loading-font-data-from-memory)
|
||||
- [Loading Font Data Embedded In Source Code](#loading-font-data-embedded-in-source-code)
|
||||
- [Using Icon Fonts](#using-icon-fonts)
|
||||
- [Excluding Overlapping Ranges](#excluding-overlapping-ranges)
|
||||
- [Using FreeType Rasterizer (imgui_freetype)](#using-freetype-rasterizer-imgui_freetype)
|
||||
- [Using Colorful Glyphs/Emojis](#using-colorful-glyphsemojis)
|
||||
- [Using Custom Glyph Ranges](#using-custom-glyph-ranges)
|
||||
|
|
@ -313,6 +314,44 @@ Here's an application using icons ("Avoyd", https://www.avoyd.com):
|
|||
|
||||
---------------------------------------
|
||||
|
||||
### Excluding Overlapping Ranges
|
||||
|
||||
🆕 **Since 1.92, with an up to date backend: glyphs ranges are ignored**: when loading a glyph, input fonts in the merge list are queried in order. The first font which has the glyph loads it.
|
||||
<BR>‼️ **If you are merging several fonts, you may have undesirable overlapping ranges.** You can use `ImFontConfig::GlyphExcludeRanges[] `to specify ranges to ignore in a given Input.
|
||||
|
||||
```cpp
|
||||
// Add Font Source 1 but ignore ICON_MIN_FA..ICON_MAX_FA range
|
||||
static ImWchar exclude_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
|
||||
ImFontConfig cfg1;
|
||||
cfg1.GlyphExcludeRanges = exclude_ranges;
|
||||
io.Fonts->AddFontFromFileTTF("segoeui.ttf", 0.0f, &cfg1);
|
||||
|
||||
// Add Font Source 2, which expects to use the range above
|
||||
ImFontConfig cfg2;
|
||||
cfg2.MergeMode = true;
|
||||
io.Fonts->AddFontFromFileTTF("FontAwesome4.ttf", 0.0f, &cfg2);
|
||||
```
|
||||
Another (silly) example:
|
||||
```cpp
|
||||
// Remove 'A'-'Z' from first font
|
||||
static ImWchar exclude_ranges[] = { 'A', 'Z', 0 };
|
||||
ImFontConfig cfg1;
|
||||
cfg1.GlyphExcludeRanges = exclude_ranges;
|
||||
io.Fonts->AddFontFromFileTTF("segoeui.ttf", 0.0f, &cfg1);
|
||||
|
||||
// Load another font to fill the gaps
|
||||
ImFontConfig cfg2;
|
||||
cfg2.MergeMode = true;
|
||||
io.Fonts->AddFontFromFileTTF("Roboto-Medium.ttf", 0.0f, &cfg2);
|
||||
```
|
||||

|
||||
|
||||
You can use `Metrics/Debugger->Fonts->Font->Input Glyphs Overlap Detection Tool` to see list of glyphs available in multiple font sources. This can facilitate understanding which font input is providing which glyph.
|
||||
|
||||
##### [Return to Index](#index)
|
||||
|
||||
---------------------------------------
|
||||
|
||||
## Using FreeType Rasterizer (imgui_freetype)
|
||||
|
||||
- Dear ImGui uses [stb_truetype.h](https://github.com/nothings/stb/) to rasterize fonts (with optional oversampling). This technique and its implementation are not ideal for fonts rendered at small sizes, which may appear a little blurry or hard to read.
|
||||
|
|
|
|||
26
imgui.cpp
26
imgui.cpp
|
|
@ -484,7 +484,22 @@ CODE
|
|||
- Before 1.92: ImGui::PushFont() always used font "default" size specified in AddFont() call.
|
||||
- Since 1.92: ImGui::PushFont() preserve the current font size which is a shared value.
|
||||
- To use old behavior: (A) use 'ImGui::PushFont(font, font->LegacySize)' at call site (preferred). (B) Set 'ImFontConfig::Flags |= ImFontFlags_DefaultToLegacySize' in AddFont() call (not desirable as it requires e.g. third-party code to be aware of it).
|
||||
- Fonts: **IMPORTANT** on Font Merging:
|
||||
- When searching for a glyph in multiple merged fonts: font inputs are now scanned in orderfor the first font input which the desired glyph. This is technically a different behavior than before!
|
||||
- e.g. If you are merging fonts you may have glyphs that you expected to load from Font Source 2 which exists in Font Source 1. After the update and when using a new backend, those glyphs may now loaded from Font Source 1!
|
||||
- You can use `ImFontConfig::GlyphExcludeRanges[]` to specify ranges to ignore in given Input:
|
||||
// Add Font Source 1 but ignore ICON_MIN_FA..ICON_MAX_FA range
|
||||
static ImWchar exclude_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
|
||||
ImFontConfig cfg1;
|
||||
cfg1.GlyphExcludeRanges = exclude_ranges;
|
||||
io.Fonts->AddFontFromFileTTF("segoeui.ttf", 0.0f, &cfg1);
|
||||
// Add Font Source 2, which expects to use the range above
|
||||
ImFontConfig cfg2;
|
||||
cfg2.MergeMode = true;
|
||||
io.Fonts->AddFontFromFileTTF("FontAwesome4.ttf", 0.0f, &cfg2);
|
||||
- You can use `Metrics/Debugger->Fonts->Font->Input Glyphs Overlap Detection Tool` to see list of glyphs available in multiple font sources. This can facilitate unde
|
||||
- Fonts: ImFont::FontSize was removed and does not make sense anymore. ImFont::LegacySize is the size passed to AddFont().
|
||||
- Fonts: Removed support for PushFont(NULL) which was a shortcut for "default font".
|
||||
- Fonts: Renamed/moved 'io.FontGlobalScale' to 'style.FontScaleMain'.
|
||||
- Textures: all API functions taking a 'ImTextureID' parameter are now taking a 'ImTextureRef'. Affected functions are: ImGui::Image(), ImGui::ImageWithBg(), ImGui::ImageButton(), ImDrawList::AddImage(), ImDrawList::AddImageQuad(), ImDrawList::AddImageRounded().
|
||||
- Fonts: obsoleted ImFontAtlas::GetTexDataAsRGBA32(), GetTexDataAsAlpha8(), Build(), SetTexID(), IsBuilt() functions. The new protocol for backends to handle textures doesn't need them. Kept redirection functions (will obsolete).
|
||||
|
|
@ -4002,7 +4017,7 @@ void ImGui::RenderMouseCursor(ImVec2 base_pos, float base_scale, ImGuiMouseCurso
|
|||
ImGuiContext& g = *GImGui;
|
||||
if (mouse_cursor <= ImGuiMouseCursor_None || mouse_cursor >= ImGuiMouseCursor_COUNT) // We intentionally accept out of bound values.
|
||||
mouse_cursor = ImGuiMouseCursor_Arrow;
|
||||
ImFontAtlas* font_atlas = g.DrawListSharedData.FontAtlas;
|
||||
ImFontAtlas* font_atlas = g.DrawListSharedData.FontAtlas;
|
||||
for (ImGuiViewportP* viewport : g.Viewports)
|
||||
{
|
||||
// We scale cursor with current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor.
|
||||
|
|
@ -9503,9 +9518,11 @@ void ImGui::SetFontRasterizerDensity(float rasterizer_density)
|
|||
void ImGui::PushFont(ImFont* font, float font_size_base)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
//if (font == NULL) // Before 1.92 (June 2025), PushFont(NULL) == PushFont(GetDefaultFont())
|
||||
// font = g.Font;
|
||||
IM_ASSERT(font != NULL);
|
||||
|
||||
g.FontStack.push_back({ g.Font, g.FontSizeBase, g.FontSize });
|
||||
if (font == NULL)
|
||||
font = GetDefaultFont();
|
||||
if (font_size_base <= 0.0f)
|
||||
{
|
||||
if (font->Flags & ImFontFlags_DefaultToLegacySize)
|
||||
|
|
@ -22800,7 +22817,8 @@ void ImGui::DebugNodeFont(ImFont* font)
|
|||
}
|
||||
if (font->Sources.Size > 1 && TreeNode("Input Glyphs Overlap Detection Tool"))
|
||||
{
|
||||
TextWrapped("- First Input that contains the glyph is used.\n- Use ImFontConfig::GlyphExcludeRanges[] to specify ranges to ignore glyph in given Input.\n- This tool doesn't cache results and is slow, don't keep it open!");
|
||||
TextWrapped("- First Input that contains the glyph is used.\n"
|
||||
"- Use ImFontConfig::GlyphExcludeRanges[] to specify ranges to ignore glyph in given Input.\n- Prefer using a small number of ranges as the list is scanned every time a new glyph is loaded,\n - e.g. GlyphExcludeRanges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };\n- This tool doesn't cache results and is slow, don't keep it open!");
|
||||
if (BeginTable("table", 2))
|
||||
{
|
||||
for (unsigned int c = 0; c < 0x10000; c++)
|
||||
|
|
|
|||
17
imgui.h
17
imgui.h
|
|
@ -507,14 +507,16 @@ namespace ImGui
|
|||
// - To use old behavior (single size font, size specified in AddFontXXX() call:
|
||||
// - Use 'PushFont(font, font->LegacySize)' at call site
|
||||
// - Or set 'ImFontConfig::Flags |= ImFontFlags_DefaultToLegacySize' before calling AddFont(), and then 'PushFont(font)' will use this size.
|
||||
// - External scale factors are applied over the provided value.
|
||||
// *IMPORTANT* If you want to scale an existing font size:
|
||||
// - OK: PushFontSize(style.FontSizeBase * factor) (= value before external scale factors applied).
|
||||
// - KO: PushFontSize(GetFontSize() * factor) (= value after external scale factors applied. external scale factors are style.FontScaleMain + per-viewport scales.).
|
||||
// *IMPORTANT* External scale factors are applied over the provided value. If you want to scale an existing font size:
|
||||
// - OK: PushFontSize(style.FontSizeBase * 2.0f) (= value before external scale factors applied).
|
||||
// - NOT OK: PushFontSize(GetFontSize() * 2.0f) (= value after external scale factors applied. External scale factors are: 'style.FontScaleMain * style.FontScaleDpi * maybe more').
|
||||
IMGUI_API void PushFont(ImFont* font, float font_size_base = -1); // use NULL as a shortcut to push default font. Use <0.0f to keep current font size.
|
||||
IMGUI_API void PopFont();
|
||||
IMGUI_API void PushFontSize(float font_size_base);
|
||||
IMGUI_API void PushFontSize(float font_size_base); // keep current font, change its size. Final 'font size = font_size_base * external scale factors'.
|
||||
IMGUI_API void PopFontSize();
|
||||
IMGUI_API ImFont* GetFont(); // get current font
|
||||
IMGUI_API float GetFontSize(); // get current font size (= height in pixels) AFTER external scale factors applied. *IMPORTANT* DO NOT PASS THIS VALUE TO PushFont()/PushFontSize()! Use ImGui::GetStyle().FontSizeBase to get value before external scale factors.
|
||||
IMGUI_API ImFontBaked* GetFontBaked(); // get current font bound at current size // == GetFont()->GetFontBaked(GetFontSize())
|
||||
|
||||
// Parameters stacks (shared)
|
||||
IMGUI_API void PushStyleColor(ImGuiCol idx, ImU32 col); // modify a style color. always use this if you modify the style after NewFrame().
|
||||
|
|
@ -538,10 +540,7 @@ namespace ImGui
|
|||
|
||||
// Style read access
|
||||
// - Use the ShowStyleEditor() function to interactively see/edit the colors.
|
||||
IMGUI_API ImFont* GetFont(); // get current font
|
||||
IMGUI_API float GetFontSize(); // get current font size (= height in pixels) of current font with external scale factors applied. Use ImGui::GetStyle().FontSizeBase to get value before external scale factors.
|
||||
IMGUI_API ImVec2 GetFontTexUvWhitePixel(); // get UV coordinate for a white pixel, useful to draw custom shapes via the ImDrawList API
|
||||
IMGUI_API ImFontBaked* GetFontBaked(); // get current font bound at current size // == GetFont()->GetFontBaked(GetFontSize())
|
||||
IMGUI_API ImU32 GetColorU32(ImGuiCol idx, float alpha_mul = 1.0f); // retrieve given style color with style alpha applied and optional extra alpha multiplier, packed as a 32-bit value suitable for ImDrawList
|
||||
IMGUI_API ImU32 GetColorU32(const ImVec4& col); // retrieve given color with style alpha applied, packed as a 32-bit value suitable for ImDrawList
|
||||
IMGUI_API ImU32 GetColorU32(ImU32 col, float alpha_mul = 1.0f); // retrieve given color with style alpha applied, packed as a 32-bit value suitable for ImDrawList
|
||||
|
|
@ -3594,7 +3593,7 @@ struct ImFontConfig
|
|||
ImS8 OversampleV; // 0 (1) // Rasterize at higher quality for sub-pixel positioning. 0 == auto == 1. This is not really useful as we don't use sub-pixel positions on the Y axis.
|
||||
float SizePixels; // // Size in pixels for rasterizer (more or less maps to the resulting font height).
|
||||
const ImWchar* GlyphRanges; // NULL // *LEGACY* THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE. Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list).
|
||||
const ImWchar* GlyphExcludeRanges; // NULL // Pointer to a VERY SHORT user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). This is very close to GlyphRanges[] but designed to exclude ranges from a font source, when merging fonts with overlapping glyphs. Use "Input Glyphs Overlap Detection Tool" to find about your overlapping ranges.
|
||||
const ImWchar* GlyphExcludeRanges; // NULL // Pointer to a small user-provided list of Unicode ranges (2 value per range, values are inclusive, zero-terminated list). This is very close to GlyphRanges[] but designed to exclude ranges from a font source, when merging fonts with overlapping glyphs. Use "Input Glyphs Overlap Detection Tool" to find about your overlapping ranges.
|
||||
//ImVec2 GlyphExtraSpacing; // 0, 0 // (REMOVED AT IT SEEMS LARGELY OBSOLETE. PLEASE REPORT IF YOU WERE USING THIS). Extra spacing (in pixels) between glyphs when rendered: essentially add to glyph->AdvanceX. Only X axis is supported for now.
|
||||
ImVec2 GlyphOffset; // 0, 0 // Offset (in pixels) all glyphs from this font input. Absolute value for default size, other sizes will scale this value.
|
||||
float GlyphMinAdvanceX; // 0 // Minimum AdvanceX for glyphs, set Min to align font icons, set both Min/Max to enforce mono-space font. Absolute value for default size, other sizes will scale this value.
|
||||
|
|
|
|||
|
|
@ -4525,11 +4525,11 @@ static void DemoWindowLayout()
|
|||
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(-Min(GetContentRegionAvail().x * 0.40f, GetFontSize() * 12))");
|
||||
ImGui::PushItemWidth(-IM_MIN(ImGui::GetFontSize() * 12, ImGui::GetContentRegionAvail().x * 0.40f));
|
||||
ImGui::DragFloat("float##4a", &f);
|
||||
ImGui::DragFloat("float##5a", &f);
|
||||
if (show_indented_items)
|
||||
{
|
||||
ImGui::Indent();
|
||||
ImGui::DragFloat("float (indented)##4b", &f);
|
||||
ImGui::DragFloat("float (indented)##5b", &f);
|
||||
ImGui::Unindent();
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
|
@ -4539,11 +4539,11 @@ static void DemoWindowLayout()
|
|||
ImGui::Text("SetNextItemWidth/PushItemWidth(-FLT_MIN)");
|
||||
ImGui::SameLine(); HelpMarker("Align to right edge");
|
||||
ImGui::PushItemWidth(-FLT_MIN);
|
||||
ImGui::DragFloat("##float5a", &f);
|
||||
ImGui::DragFloat("##float6a", &f);
|
||||
if (show_indented_items)
|
||||
{
|
||||
ImGui::Indent();
|
||||
ImGui::DragFloat("float (indented)##5b", &f);
|
||||
ImGui::DragFloat("float (indented)##6b", &f);
|
||||
ImGui::Unindent();
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
|
|
|||
|
|
@ -3108,7 +3108,7 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
|
|||
if (font_cfg.Name[0] == '\0')
|
||||
ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "ProggyClean.ttf");
|
||||
font_cfg.EllipsisChar = (ImWchar)0x0085;
|
||||
font_cfg.GlyphOffset.y = 1.0f * IM_TRUNC(font_cfg.SizePixels / 13.0f); // Add +1 offset per 13 units
|
||||
font_cfg.GlyphOffset.y += 1.0f * IM_TRUNC(font_cfg.SizePixels / 13.0f); // Add +1 offset per 13 units
|
||||
|
||||
int ttf_compressed_size = 0;
|
||||
const char* ttf_compressed = GetDefaultCompressedFontDataTTF(&ttf_compressed_size);
|
||||
|
|
@ -5587,7 +5587,6 @@ begin:
|
|||
return;
|
||||
|
||||
// Reserve vertices for remaining worse case (over-reserving is useful and easily amortized)
|
||||
const int cmd_count = draw_list->CmdBuffer.Size;
|
||||
const int vtx_count_max = (int)(text_end - s) * 4;
|
||||
const int idx_count_max = (int)(text_end - s) * 6;
|
||||
const int idx_expected_size = draw_list->IdxBuffer.Size + idx_count_max;
|
||||
|
|
@ -5595,6 +5594,7 @@ begin:
|
|||
ImDrawVert* vtx_write = draw_list->_VtxWritePtr;
|
||||
ImDrawIdx* idx_write = draw_list->_IdxWritePtr;
|
||||
unsigned int vtx_index = draw_list->_VtxCurrentIdx;
|
||||
const int cmd_count = draw_list->CmdBuffer.Size;
|
||||
|
||||
const ImU32 col_untinted = col | ~IM_COL32_A_MASK;
|
||||
const char* word_wrap_eol = NULL;
|
||||
|
|
@ -5717,6 +5717,8 @@ begin:
|
|||
draw_list->CmdBuffer.pop_back();
|
||||
draw_list->PrimUnreserve(idx_count_max, vtx_count_max);
|
||||
draw_list->AddDrawCmd();
|
||||
//IMGUI_DEBUG_LOG("RenderText: cancel and retry to missing glyphs.\n"); // [DEBUG]
|
||||
//draw_list->AddRectFilled(pos, pos + ImVec2(10, 10), IM_COL32(255, 0, 0, 255)); // [DEBUG]
|
||||
goto begin;
|
||||
//RenderText(draw_list, size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip); // FIXME-OPT: Would a 'goto begin' be better for code-gen?
|
||||
//return;
|
||||
|
|
|
|||
|
|
@ -4295,7 +4295,7 @@ void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, cons
|
|||
// Grow internal buffer if needed
|
||||
const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0;
|
||||
const int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)ImStrlen(new_text);
|
||||
if (new_text_len + BufTextLen + 1 > obj->TextA.Size)
|
||||
if (new_text_len + BufTextLen + 1 > obj->TextA.Size && (Flags & ImGuiInputTextFlags_ReadOnly) == 0)
|
||||
{
|
||||
if (!is_resizable)
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue