Skip to content

Commit 23847ff

Browse files
sense-zzz-timehuangwei1024
authored andcommitted
Fix bug: Not support sprite frame when ignoreContentAdaptWithSize is true (cocos2d#19107)
1 parent 2e3ff46 commit 23847ff

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

cocos/ui/UIRichText.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ void RichText::formatText()
14721472
case RichElement::Type::IMAGE:
14731473
{
14741474
RichElementImage* elmtImage = static_cast<RichElementImage*>(element);
1475-
handleImageRenderer(elmtImage->_filePath, elmtImage->_color, elmtImage->_opacity, elmtImage->_width, elmtImage->_height, elmtImage->_url);
1475+
handleImageRenderer(elmtImage->_filePath, elmtImage->_textureType, elmtImage->_color, elmtImage->_opacity, elmtImage->_width, elmtImage->_height, elmtImage->_url);
14761476
break;
14771477
}
14781478
case RichElement::Type::CUSTOM:
@@ -1740,9 +1740,14 @@ void RichText::handleTextRenderer(const std::string& text, const std::string& fo
17401740
}
17411741
}
17421742

1743-
void RichText::handleImageRenderer(const std::string& filePath, const Color3B &/*color*/, GLubyte /*opacity*/, int width, int height, const std::string& url)
1743+
void RichText::handleImageRenderer(const std::string& filePath, Widget::TextureResType textureType, const Color3B &/*color*/, GLubyte /*opacity*/, int width, int height, const std::string& url)
17441744
{
1745-
Sprite* imageRenderer = Sprite::create(filePath);
1745+
Sprite* imageRenderer;
1746+
if (textureType == Widget::TextureResType::LOCAL)
1747+
imageRenderer = Sprite::create(filePath);
1748+
else
1749+
imageRenderer = Sprite::createWithSpriteFrameName(filePath);
1750+
17461751
if (imageRenderer)
17471752
{
17481753
auto currentSize = imageRenderer->getContentSize();

cocos/ui/UIRichText.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ class CC_GUI_DLL RichText : public Widget
565565
const Color3B& outlineColor = Color3B::WHITE, int outlineSize = -1,
566566
const Color3B& shadowColor = Color3B::BLACK, const Size& shadowOffset = Size(2.0, -2.0), int shadowBlurRadius = 0,
567567
const Color3B& glowColor = Color3B::WHITE);
568-
void handleImageRenderer(const std::string& filePath, const Color3B& color, GLubyte opacity, int width, int height, const std::string& url);
568+
void handleImageRenderer(const std::string& filePath, Widget::TextureResType textureType, const Color3B& color, GLubyte opacity, int width, int height, const std::string& url);
569569
void handleCustomRenderer(Node* renderer);
570570
void formatRenderers();
571571
void addNewLine();

0 commit comments

Comments
 (0)