Cocos2d-x, C++, How to Resize EditBox

  • Likes 0

    Problem Description

    I have implemented EditBox. The next thing I want is that the height of the EditBox be changed every time a line break occurs like in Message App. I did that with "editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text)". But I have problems when using a Japanese keyboard. Characters before conversion cannot be obtained with getText(). Therefore, the height does not change even if the line breaks are repeated until Japanese is converted. Any good ideas? Help me.

     

    The current code.

    // default editbox

    editBox = cocos2d::ui::EditBox::create(Size(600, 40), cocos2d::ui::Scale9Sprite::create(("abc.png")));

    // Height change editbox

    void HelloWorld::editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text)

    {
         std::string s = editBox->getText();

         if (s.length() > 18)

         {

             editBox->setContentSize(Size(600, 80));

          }

    }

    Thanks.

     

     
  • Sonar Systems admin
    Likes 0

    Does it work fine for english characters?

  • Likes 0

    Yes. I want to realize the movement of EditBox in iMessage app. The movement is that the height of the EditBox changes at the same time when the characters are broken. However, when inputting using a Japanese keyboard, the character before conversion cannot be obtained with getText(), so that is not possible and I am in trouble. It would be helpful to have a clone that works the same as iMessage, which uses cocos2dx to enter and display characters.

  • Sonar Systems admin
    Likes 0

    Try making the box bigger in general

  • Likes 0

    The box was enlarged from the beginning and displayed. But this was not what I wanted to implement. I would like to imitate the mechanism in which the height of the box changes flexibly according to line breaks like the gif image attached to an email.

  • Likes 0

    I changed your advice a little and tried it.
    Maybe I can solve it. I appreciate your advice. Thank you.

Login to reply