Cocos3 -- 7. Use the UI's RichText
1. Create
var richText = new ccui.RichText(); richText.ignoreContentAdaptWithSize(false); richText.width = 120; richText.height = 100;
Set contentSize by assigning the width and height values, and set ignoreContentAdaptWithSize to false to layout the text according to contentSize.
2. Create text elements
static RichElementText* create(int tag, const Color3B& color, GLubyte opacity, const std::string& text, const std::string& fontName, float fontSize);static RichElementImage* create(int tag, const Color3B& color, GLubyte opacity, const std::string& filePath);static RichElementCustomNode* create(int tag, const Color3B& color, GLubyte opacity, Node* customNode);
The three elements are text, images, and common nodes (Classes derived from Node can be mounted with common nodes ).
The tag seems to be useless internally and cannot be accessed externally. Other parameters are easy to understand.
Var re1 = new ccui. richElementText (0, cc. color. WHITE, 255, 'White, WHITE, black, 24); var re2 = new ccui. richElementText (0, cc. color. RED, 255, 'this is RED, 'body', 24); var reimg = new ccui. richElementImage (0, cc. color. WHITE, 255, 'res/pic/CloseNormal.png '); var renode = new ccui. richElementCustomNode (0, cc. color. WHITE, 255, new cc. sprite ('res/pic/CloseNormal.png '));
3. add or delete Elements
void insertElement(RichElement* element, int index); void pushBackElement(RichElement* element); void removeElement(int index); void removeElement(RichElement* element);
4. Other Methods
void setVerticalSpace(float space); virtual void setAnchorPoint(const Vec2 &pt); virtual Size getVirtualRendererSize() const override; void formatText(); virtual void ignoreContentAdaptWithSize(bool ignore);
The js getVirtualRendererSize does not seem to be exported.
5. Results