mirror of
https://github.com/Drezil/imgui.git
synced 2025-03-28 15:02:44 +00:00
CalcTextSize*() functions which are often speed bottleneck for large contents are about 25% faster.
Caching character advance contiguously, pulled inline, no int->float conversion.
This commit is contained in:
parent
ca2de0b89b
commit
1da8a52ce7
35
imgui.cpp
35
imgui.cpp
@ -268,6 +268,7 @@
|
|||||||
- columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
|
- columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
|
||||||
- columns: columns header to act as button (~sort op) and allow resize/reorder
|
- columns: columns header to act as button (~sort op) and allow resize/reorder
|
||||||
- columns: user specify columns size
|
- columns: user specify columns size
|
||||||
|
- columns: tree node example actually has a small bug (opening node in right column extends the column different from opening node in left column)
|
||||||
- combo: turn child handling code into pop up helper
|
- combo: turn child handling code into pop up helper
|
||||||
- combo: contents should extends to fit label if combo widget is small
|
- combo: contents should extends to fit label if combo widget is small
|
||||||
- listbox: multiple selection
|
- listbox: multiple selection
|
||||||
@ -282,7 +283,7 @@
|
|||||||
- file selection widget -> build the tool in our codebase to improve model-dialog idioms
|
- file selection widget -> build the tool in our codebase to improve model-dialog idioms
|
||||||
- slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
|
- slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
|
||||||
- slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
|
- slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
|
||||||
- text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather ineficient right now.
|
- text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now.
|
||||||
- text edit: centered text for slider as input text so it matches typical positioning.
|
- text edit: centered text for slider as input text so it matches typical positioning.
|
||||||
- text edit: flag to disable live update of the user buffer.
|
- text edit: flag to disable live update of the user buffer.
|
||||||
- text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
|
- text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
|
||||||
@ -7211,6 +7212,7 @@ void ImFont::Clear()
|
|||||||
DisplayOffset = ImVec2(-0.5f, 0.5f);
|
DisplayOffset = ImVec2(-0.5f, 0.5f);
|
||||||
ContainerAtlas = NULL;
|
ContainerAtlas = NULL;
|
||||||
Glyphs.clear();
|
Glyphs.clear();
|
||||||
|
IndexXAdvance.clear();
|
||||||
IndexLookup.clear();
|
IndexLookup.clear();
|
||||||
FallbackGlyph = NULL;
|
FallbackGlyph = NULL;
|
||||||
}
|
}
|
||||||
@ -7305,12 +7307,21 @@ void ImFont::BuildLookupTable()
|
|||||||
for (size_t i = 0; i != Glyphs.size(); i++)
|
for (size_t i = 0; i != Glyphs.size(); i++)
|
||||||
max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
|
max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
|
||||||
|
|
||||||
|
IndexXAdvance.clear();
|
||||||
|
IndexXAdvance.resize((size_t)max_codepoint + 1);
|
||||||
IndexLookup.clear();
|
IndexLookup.clear();
|
||||||
IndexLookup.resize((size_t)max_codepoint + 1);
|
IndexLookup.resize((size_t)max_codepoint + 1);
|
||||||
for (size_t i = 0; i < IndexLookup.size(); i++)
|
for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
|
||||||
|
{
|
||||||
|
IndexXAdvance[i] = 0.0f;
|
||||||
IndexLookup[i] = -1;
|
IndexLookup[i] = -1;
|
||||||
|
}
|
||||||
for (size_t i = 0; i < Glyphs.size(); i++)
|
for (size_t i = 0; i < Glyphs.size(); i++)
|
||||||
IndexLookup[(int)Glyphs[i].Codepoint] = (int)i;
|
{
|
||||||
|
const size_t codepoint = (int)Glyphs[i].Codepoint;
|
||||||
|
IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
|
||||||
|
IndexLookup[codepoint] = (int)i;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a glyph to handle TAB
|
// Create a glyph to handle TAB
|
||||||
// FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
|
// FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
|
||||||
@ -7321,7 +7332,8 @@ void ImFont::BuildLookupTable()
|
|||||||
tab_glyph = *space_glyph;
|
tab_glyph = *space_glyph;
|
||||||
tab_glyph.Codepoint = '\t';
|
tab_glyph.Codepoint = '\t';
|
||||||
tab_glyph.XAdvance *= 4;
|
tab_glyph.XAdvance *= 4;
|
||||||
IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
|
IndexXAdvance[(size_t)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
|
||||||
|
IndexLookup[(size_t)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7534,10 +7546,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float char_width = 0.0f;
|
const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : 0.0f;
|
||||||
if (const Glyph* glyph = FindGlyph((unsigned short)c))
|
|
||||||
char_width = glyph->XAdvance * scale;
|
|
||||||
|
|
||||||
if (c == ' ' || c == '\t')
|
if (c == ' ' || c == '\t')
|
||||||
{
|
{
|
||||||
if (inside_word)
|
if (inside_word)
|
||||||
@ -7639,10 +7648,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float char_width = 0.0f;
|
const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : 0.0f;
|
||||||
if (const Glyph* glyph = FindGlyph((unsigned short)c))
|
|
||||||
char_width = glyph->XAdvance * scale;
|
|
||||||
|
|
||||||
if (line_width + char_width >= max_width)
|
if (line_width + char_width >= max_width)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -7686,10 +7692,7 @@ ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_be
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float char_width = 0.0f;
|
const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : 0.0f;
|
||||||
if (const Glyph* glyph = FindGlyph((unsigned short)c))
|
|
||||||
char_width = glyph->XAdvance * scale;
|
|
||||||
|
|
||||||
if (line_width + char_width >= max_width)
|
if (line_width + char_width >= max_width)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
1
imgui.h
1
imgui.h
@ -910,6 +910,7 @@ struct ImFont
|
|||||||
};
|
};
|
||||||
ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
||||||
ImVector<Glyph> Glyphs;
|
ImVector<Glyph> Glyphs;
|
||||||
|
ImVector<float> IndexXAdvance; // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
|
||||||
ImVector<int> IndexLookup; // Index glyphs by Unicode code-point
|
ImVector<int> IndexLookup; // Index glyphs by Unicode code-point
|
||||||
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user