MCPcopy Create free account
hub / github.com/axmolengine/axmol / handleTextRenderer

Method handleTextRenderer

core/ui/UIRichText.cpp:2057–2189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2055} // namespace
2056
2057void RichText::handleTextRenderer(std::string_view text,
2058 std::string_view fontName,
2059 float fontSize,
2060 const Color3B& color,
2061 uint8_t opacity,
2062 uint32_t flags,
2063 std::string_view url,
2064 const Color3B& outlineColor,
2065 int outlineSize,
2066 const Color3B& shadowColor,
2067 const Vec2& shadowOffset,
2068 int shadowBlurRadius,
2069 const Color3B& glowColor,
2070 std::string_view id)
2071{
2072 bool fileExist = FileUtils::getInstance()->isFileExist(fontName);
2073 RichText::WrapMode wrapMode = static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).asInt());
2074
2075 // split text by \n
2076 std::stringstream ss;
2077 ss << text;
2078 std::string currentText;
2079 size_t realLines = 0;
2080 auto isFirstLabel = true;
2081 while (std::getline(ss, currentText, '\n'))
2082 {
2083 if (realLines > 0)
2084 {
2085 addNewLine();
2086 _lineHeights.back() = fontSize;
2087 }
2088 ++realLines;
2089
2090 size_t splitParts = 0;
2091 StringUtils::StringUTF8 utf8Text(currentText);
2092 while (!currentText.empty())
2093 {
2094 if (splitParts > 0)
2095 {
2096 addNewLine();
2097 _lineHeights.back() = fontSize;
2098 }
2099 ++splitParts;
2100
2101 Label* textRenderer = fileExist ? Label::createWithTTF(currentText, fontName, fontSize)
2102 : Label::createWithSystemFont(currentText, fontName, fontSize);
2103
2104 if (flags & RichElementText::ITALICS_FLAG)
2105 textRenderer->enableItalics();
2106 if (flags & RichElementText::BOLD_FLAG)
2107 textRenderer->enableBold();
2108 if (flags & RichElementText::UNDERLINE_FLAG)
2109 textRenderer->enableUnderline();
2110 if (flags & RichElementText::STRIKETHROUGH_FLAG)
2111 textRenderer->enableStrikethrough();
2112 if (flags & RichElementText::URL_FLAG)
2113 textRenderer->addComponent(UrlTouchListenerComponent::create(
2114 textRenderer, url, [this](std::string_view url) { openUrl(url); }));

Callers

nothing calls this directly

Calls 15

getInstanceFunction · 0.85
createFunction · 0.85
Color4BFunction · 0.85
findSplitPositionForWordFunction · 0.85
findSplitPositionForCharFunction · 0.85
asIntMethod · 0.80
enableItalicsMethod · 0.80
enableBoldMethod · 0.80
enableUnderlineMethod · 0.80
enableStrikethroughMethod · 0.80
addComponentMethod · 0.80
getAsCharSequenceMethod · 0.80

Tested by

no test coverage detected