MCPcopy Create free account
hub / github.com/devkitPro/3ds-hbmenu / textCalcWidth

Function textCalcWidth

source/text.c:74–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74float textCalcWidth(const char* text)
75{
76 float width = 0.0f;
77 float maxWidth = 0.0f;
78 ssize_t units;
79 uint32_t code;
80 const uint8_t* p = (const uint8_t*)text;
81 do
82 {
83 if (!*p) break;
84 units = decode_utf8(&code, p);
85 if (units == -1)
86 break;
87 p += units;
88
89 if (code == '\n')
90 {
91 maxWidth = maxf(width, maxWidth);
92 width = 0.0f;
93 continue;
94 }
95
96 if (code > 0)
97 {
98 int glyphIdx = fontGlyphIndexFromCodePoint(NULL, code);
99 charWidthInfo_s* cwi = fontGetCharWidthInfo(NULL, glyphIdx);
100 width += cwi->charWidth;
101 }
102 } while (code > 0);
103 return s_textScale*maxf(width, maxWidth);
104}
105
106void textDraw(float x, float y, float scaleX, float scaleY, bool baseline, const char* text)
107{

Callers 1

textDrawInBoxFunction · 0.85

Calls 1

maxfFunction · 0.85

Tested by

no test coverage detected