Cocos2d-x3.3final (TextField) common member functions (c + +)

Source: Internet
Author: User

TextField * TextField = textfield::create ("Input words here", "Arial", 30);

Textfield->setposition (VEC2 (widgetsize.width/2.0f, widgetsize.height/2.0f));

Textfield->addeventlistener (Cc_callback_2 (HelloWorld::textfieldevent, this));


void HelloWorld::textfieldevent(REF * psender, Textfield::eventtype type)

{

Switch (type)

{

Case Textfield::eventtype::attach_with_ime:

{

TextField * TextField = dynamic_cast<textfield*> (Psender);

Size screensize = ccdirector::getinstance ()->getwinsize ();

Textfield->runaction (Ccmoveto::create (0.225f, VEC2 (screensize.width/2.0f, screensize.height/2.0f +textField- >getcontentsize (). height/2.0f));

_displayvaluelabel->setstring (String::createwithformat ("Attach with IME")->getcstring ());

textfield->setmaxlengthenabled (true); Set allowed maximum number limit

Textfield->setmaxlength (3); //Set maximum allowable number to 3

Textfield->setpasswordenabled (TRUE); //settings can be set to password mode

Textfield->setpasswordstyletext ("*"); //Set the occlusion character of the password to *

textfield->setplaceholder ("Input text Here"); Set Placeholder
Textfield->setplaceholdercolor (Color4b::green); //Set placeholder color

Textfield->settextcolor (color4b::red);


If you want to set up line wrapping

Textfield->ignorecontentadaptwithsize (FALSE); //(code required) here is false, if true, the control uses only Getvirtualrenderersize () the size returned by this function, regardless of setcontentsize size

( (label*) (Textfield->getvirtualrenderer ()))->setlinebreakwithoutspace (true); (The most critical code that has to go)

Textfield->setcontentsize (Size (240, 170)); //(code required)

Textfield->settexthorizontalalignment (Texthalignment::left); //Set the alignment of text in horizontal direction
Textfield->settextverticalalignment (Textvalignment::top); //Set the alignment of text in the vertical direction

Alignment Settexthorizontalalignment So we can understand that left is the entire line of text on the right side of the alignment, the whole line of text is aligned by the side,

Alignment Settextverticalalignment We can understand that top is your entire text by the top of the alignment, whereas bottom is the entire text by the bottom of the alignment

Textfield->getvirtualrenderersize (); Can get the actual size of it

((label*) (Textfield->getvirtualrenderer ()))->setlinebreakwithoutspace (true); //Is true, content is more than width and will be wrapped automatically .

}

Break

Case Textfield::eventtype::D etach_with_ime:

{

TextField * TextField = dynamic_cast<textfield*> (Psender);

Size screensize = ccdirector::getinstance ()->getwinsize ();

Textfield->runaction (Ccmoveto::create (0.225f, VEC2 (screensize.width/2.0f, screensize.height/2.0f));

}

Break

Case Textfield::eventtype::insert_text:

Break

Case Textfield::eventtype::D elete_backward:

Break

}

Cocos2d-x3.3final (TextField) common member functions (c + +)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.