Skip to content

Commit 8c3bedf

Browse files
committed
jngl::Text: Don't query pWindow->getFontImpl() if not needed
1 parent 1af5c5a commit 8c3bedf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/jngl/text.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@ class Text::Line {
5555
double height = std::numeric_limits<double>::quiet_NaN();
5656
};
5757

58-
Text::Text(const std::string& text) : font(pWindow->getFontImpl()) {
59-
setText(text);
58+
Text::Text(const std::string& text) : font(text.empty() ? nullptr : pWindow->getFontImpl()) {
59+
if (!text.empty()) {
60+
setText(text);
61+
}
6062
}
6163

6264
void Text::setText(const std::string& text, double maxWidth) {
65+
if (!font) {
66+
font = pWindow->getFontImpl();
67+
}
6368
lines.clear();
6469
for (const auto& lineText : splitlines(text)) {
6570
addLine(lineText, maxWidth);

0 commit comments

Comments
 (0)