| 41 | // UIEditBoxTest |
| 42 | |
| 43 | bool UIEditBoxTest::init() |
| 44 | { |
| 45 | if (UIScene::init()) |
| 46 | { |
| 47 | auto renderView = Director::getInstance()->getRenderView(); |
| 48 | auto visibleOrigin = renderView->getVisibleOrigin(); |
| 49 | auto visibleSize = renderView->getVisibleSize(); |
| 50 | |
| 51 | auto pBg = Sprite::create("Images/HelloWorld.png"); |
| 52 | pBg->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 2)); |
| 53 | addChild(pBg); |
| 54 | |
| 55 | _TTFShowEditReturn = Label::createWithSystemFont("No edit control return!", "Arial", 30); |
| 56 | _TTFShowEditReturn->setPosition( |
| 57 | Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height - 50)); |
| 58 | addChild(_TTFShowEditReturn); |
| 59 | |
| 60 | auto editBoxSize = Size(visibleSize.width - 100, visibleSize.height * 0.1); |
| 61 | |
| 62 | // top |
| 63 | std::string pNormalSprite = "extensions/green_edit.png"; |
| 64 | _editName = ui::EditBox::create(editBoxSize + Size(0, 40), ui::Scale9Sprite::create(pNormalSprite)); |
| 65 | _editName->setPosition( |
| 66 | Vec2(visibleOrigin.x + visibleSize.width / 2 - 50, visibleOrigin.y + visibleSize.height * 3 / 4)); |
| 67 | _editName->setFontColor(Color3B::RED); |
| 68 | _editName->setPlaceHolder("Name:"); |
| 69 | _editName->setPlaceholderFontColor(Color3B::WHITE); |
| 70 | _editName->setMaxLength(8); |
| 71 | _editName->setFontSize((int)editBoxSize.height / 2); |
| 72 | _editName->setText("v👐👊💝"); |
| 73 | _editName->setReturnType(ui::EditBox::KeyboardReturnType::DONE); |
| 74 | _editName->setDelegate(this); |
| 75 | _editName->setVisible(true); |
| 76 | addChild(_editName); |
| 77 | |
| 78 | Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); |
| 79 | auto buttonSize = button->getContentSize(); |
| 80 | button->setTitleText("Single Line"); |
| 81 | button->setPosition(_editName->getPosition() + Vec2(editBoxSize.width / 2 + buttonSize.width / 2, 0.0f)); |
| 82 | button->addClickEventListener([this](Object* /*sender*/) { _editName->setInputMode(ui::EditBox::InputMode::SINGLE_LINE); }); |
| 83 | addChild(button); |
| 84 | |
| 85 | // middle |
| 86 | _editPassword = |
| 87 | ui::EditBox::create(Size(editBoxSize.width, editBoxSize.height + 20), "extensions/orange_edit.png"); |
| 88 | _editPassword->setPosition( |
| 89 | Vec2(visibleOrigin.x + visibleSize.width / 2 - 50, visibleOrigin.y + visibleSize.height / 2)); |
| 90 | _editPassword->setFontColor(Color3B::GREEN); |
| 91 | _editPassword->setPlaceHolder("Password:"); |
| 92 | _editPassword->setMaxLength(6); |
| 93 | _editPassword->setInputFlag(ui::EditBox::InputFlag::PASSWORD); |
| 94 | _editPassword->setInputMode(ui::EditBox::InputMode::SINGLE_LINE); |
| 95 | _editPassword->setFontSize((int)editBoxSize.height / 2); |
| 96 | _editPassword->setDelegate(this); |
| 97 | _editPassword->setVisible(true); |
| 98 | addChild(_editPassword); |
| 99 | |
| 100 | auto buttonPassword = (ui::Button*)button->clone(); |
nothing calls this directly
no test coverage detected