MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / stringWidth

Method stringWidth

source/rendering/StarTextPainter.cpp:94–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94int TextPainter::stringWidth(StringView s, unsigned charLimit) {
95 if (s.empty())
96 return 0;
97
98 String font = m_renderSettings.font, setFont = font;
99 m_fontTextureGroup.switchFont(font);
100
101 Text::CommandsCallback commandsCallback = [&](StringView commands) {
102 commands.forEachSplitView(",", [&](StringView command, size_t, size_t) {
103 if (command == "reset") {
104 m_fontTextureGroup.switchFont(font = setFont);
105 } else if (command == "set") {
106 setFont = font;
107 } else if (command.beginsWith("font=")) {
108 m_fontTextureGroup.switchFont(font = command.substr(5));
109 }
110 });
111 return true;
112 };
113
114 int width = 0;
115 Text::TextCallback textCallback = [&](StringView text) {
116 for (String::Char c : text) {
117 width += glyphWidth(c);
118 if (charLimit && --charLimit == 0)
119 return false;
120 }
121 return true;
122 };
123
124 Text::processText(s, textCallback, commandsCallback);
125
126 return width;
127}
128
129bool TextPainter::processWrapText(StringView text, unsigned* wrapWidth, WrapTextCallback textFunc) {
130 String font = m_renderSettings.font, setFont = font;

Callers

nothing calls this directly

Calls 6

processTextFunction · 0.85
switchFontMethod · 0.80
forEachSplitViewMethod · 0.80
emptyMethod · 0.45
beginsWithMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected