Theoretical part
A container class that displays multiple richelement. We can use it to easily display text with pictures and inherit from widgets.
Code practices
Static RichText * Create ()
Create an empty RichText
void Insertelement (richelement *element, int index)
Inserts a richelement at the specified location.
void Pushbackelement (Richelement *element)
Inserts a richelement at the end of the container.
void removeelement (int index)
Removes the richelement at the specified location.
void Removeelement (Richelement *element)
Remove a richelement.
void Setverticalspace (float space)
Sets the vertical interval for each richelement.
void Formattext ()
Rearrange all the richelement. Often called internally.
Static Richelementtext * Create (int tag,//Tag value.
Const COLOR3B &color,//color value.
Glubyte opacity,//opacity.
Const std::string &text,//text content.
Const std::string &fontname,//text font name.
float fontSize)//text font size.
Create a Richelementtext class from multiple variables.
Static Richelementimage * Create (int tag,//Tag value.
Const COLOR3B &color,//color value.
Glubyte opacity,//opacity.
Const std::string &filepath)//Picture file name.
Create a Richelementimage class from multiple variables.
Static Richelementcustomnode * Create (int tag,//Tag value.
Const COLOR3B &color,//color value.
Glubyte opacity,//opacity.
Node *customnode)//custom nodes pointer.
Create a Richelementcustomnode class from multiple variables.
Instance:
//RichText_richtext =richtext::create (); _richtext->ignorecontentadaptwithsize (false); _richtext->setcontentsize (Size ( -, -)); Richelementtext* Re1 = Richelementtext::create (1, Color3b::white,255, STR1,"SimSun",Ten); Richelementtext* Re2 = Richelementtext::create (2, Color3b::yellow,255,"And this is yellow.","Helvetica",Ten); Richelementtext* Re3 = Richelementtext::create (3, Color3b::gray,255, STR2,"Yu Mincho",Ten); Richelementtext* Re4 = Richelementtext::create (4, Color3b::green,255,"and Green with TTF support.","Fonts/marker Felt.ttf",Ten); Richelementtext* Re5 = Richelementtext::create (5, Color3b::red,255,"Last one is red","Helvetica",Ten); Richelementimage* Reimg = Richelementimage::create (6, Color3b::white,255,"Cocosui/sliderballnormal.png"); Cocostudio::armaturedatamanager::getinstance ()->addarmaturefileinfo ("Cocosui/100/100.exportjson"); Cocostudio::armature*par = Cocostudio::armature::create (" -"); PAr->getanimation ()->play ("Animation1"); Richelementcustomnode* Recustom = Richelementcustomnode::create (1, Color3b::white,255, PAr); Richelementtext* Re6 = Richelementtext::create (7, Color3b::orange,255,"Have fun!!","Helvetica",Ten);
Cocos Code Research (+) widget sub-class Richview learning notes