MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / RenderText

Method RenderText

external/imgui/imgui_draw.cpp:5803–6011  ·  view source on GitHub ↗

Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound. DO NOT CALL DIRECTLY THIS WILL CHANGE WILDLY IN 2026. Use ImDrawList::AddText().

Source from the content-addressed store, hash-verified

5801// Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.
5802// DO NOT CALL DIRECTLY THIS WILL CHANGE WILDLY IN 2026. Use ImDrawList::AddText().
5803void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, ImDrawTextFlags flags)
5804{
5805begin:
5806 // Align to be pixel perfect
5807 float x = pos.x;
5808 float y = pos.y;
5809 if (y > clip_rect.w)
5810 return;
5811 if ((draw_list->Flags & ImDrawListFlags_TextNoPixelSnap) == 0)
5812 {
5813 x = IM_TRUNC(x);
5814 y = IM_TRUNC(y);
5815 }
5816
5817 if (!text_end)
5818 text_end = text_begin + ImStrlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.
5819
5820 const float line_height = size;
5821 ImFontBaked* baked = GetFontBaked(size);
5822
5823 const float scale = size / baked->Size;
5824 const float origin_x = x;
5825 const bool word_wrap_enabled = (wrap_width > 0.0f);
5826
5827 // Fast-forward to first visible line
5828 const char* s = text_begin;
5829 if (y + line_height < clip_rect.y)
5830 while (y + line_height < clip_rect.y && s < text_end)
5831 {
5832 const char* line_end = (const char*)ImMemchr(s, '\n', text_end - s);
5833 if (word_wrap_enabled)
5834 {
5835 // FIXME-OPT: This is not optimal as do first do a search for \n before calling CalcWordWrapPosition().
5836 // If the specs for CalcWordWrapPosition() were reworked to optionally return on \n we could combine both.
5837 // However it is still better than nothing performing the fast-forward!
5838 s = ImFontCalcWordWrapPositionEx(this, size, s, line_end ? line_end : text_end, wrap_width, flags);
5839 s = ImTextCalcWordWrapNextLineStart(s, text_end, flags);
5840 }
5841 else
5842 {
5843 s = line_end ? line_end + 1 : text_end;
5844 }
5845 y += line_height;
5846 }
5847
5848 // For large text, scan for the last visible line in order to avoid over-reserving in the call to PrimReserve()
5849 // Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer without a newline will likely crash atm)
5850 if (text_end - s > 10000 && !word_wrap_enabled)
5851 {
5852 const char* s_end = s;
5853 float y_end = y;
5854 while (y_end < clip_rect.w && s_end < text_end)
5855 {
5856 s_end = (const char*)ImMemchr(s_end, '\n', text_end - s_end);
5857 s_end = s_end ? s_end + 1 : text_end;
5858 y_end += line_height;
5859 }
5860 text_end = s_end;

Callers 1

AddTextMethod · 0.45

Calls 8

ImTextCharFromUtf8Function · 0.85
PrimReserveMethod · 0.80
FindGlyphMethod · 0.80
PrimUnreserveMethod · 0.80
AddDrawCmdMethod · 0.80
pop_backMethod · 0.45

Tested by

no test coverage detected