2013-09-16 20:54:13 +08:00
|
|
|
#include "UITextFieldTest.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UITextFieldTests::UITextFieldTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(UITextFieldTest);
|
|
|
|
ADD_TEST_CASE(UITextFieldTest_MaxLength);
|
|
|
|
ADD_TEST_CASE(UITextFieldTest_Password);
|
|
|
|
ADD_TEST_CASE(UITextFieldTest_LineWrap);
|
|
|
|
ADD_TEST_CASE(UITextFieldTest_TrueTypeFont);
|
|
|
|
ADD_TEST_CASE(UITextFieldTest_PlaceHolderColor);
|
|
|
|
}
|
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// UITextFieldTest
|
|
|
|
UITextFieldTest::UITextFieldTest()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UITextFieldTest::~UITextFieldTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UITextFieldTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add a label in which the textfield events will be displayed
|
2014-04-03 15:52:42 +08:00
|
|
|
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:52:42 +08:00
|
|
|
Text* alert = Text::create("TextField","fonts/Marker Felt.ttf",30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the textfield
|
2014-07-29 09:56:33 +08:00
|
|
|
TextField* textField = TextField::create("input words here","Arial",30);
|
2014-04-02 18:35:08 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2014-05-12 11:29:22 +08:00
|
|
|
textField->addEventListener(CC_CALLBACK_2(UITextFieldTest::textFieldEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(textField);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
void UITextFieldTest::textFieldEvent(Ref *pSender, TextField::EventType type)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-09-17 20:13:23 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::ATTACH_WITH_IME:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.225f,
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("attach with IME"));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DETACH_WITH_IME:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
|
|
|
_displayValueLabel->setString(StringUtils::format("detach with IME"));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::INSERT_TEXT:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("insert words"));
|
2013-09-17 20:13:23 +08:00
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DELETE_BACKWARD:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("delete word"));
|
2013-09-17 20:13:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UITextFieldTest_MaxLength
|
|
|
|
UITextFieldTest_MaxLength::UITextFieldTest_MaxLength()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UITextFieldTest_MaxLength::~UITextFieldTest_MaxLength()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UITextFieldTest_MaxLength::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add a label in which the textfield events will be displayed
|
2014-04-03 15:52:42 +08:00
|
|
|
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:52:42 +08:00
|
|
|
Text *alert = Text::create("TextField max length","fonts/Marker Felt.ttf",30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the textfield
|
2014-07-29 09:56:33 +08:00
|
|
|
TextField* textField = TextField::create("input words here","Arial",30);
|
2013-11-06 16:04:06 +08:00
|
|
|
textField->setMaxLengthEnabled(true);
|
2013-09-16 20:54:13 +08:00
|
|
|
textField->setMaxLength(3);
|
2014-05-15 01:07:09 +08:00
|
|
|
textField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f));
|
2014-05-12 11:29:22 +08:00
|
|
|
textField->addEventListener(CC_CALLBACK_2(UITextFieldTest_MaxLength::textFieldEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(textField);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
void UITextFieldTest_MaxLength::textFieldEvent(Ref *pSender, TextField::EventType type)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-09-17 20:13:23 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::ATTACH_WITH_IME:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.225f,
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("attach with IME max length %d", textField->getMaxLength()));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DETACH_WITH_IME:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
|
|
|
_displayValueLabel->setString(StringUtils::format("detach with IME max length %d", textField->getMaxLength()));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::INSERT_TEXT:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("insert words max length %d", textField->getMaxLength()));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DELETE_BACKWARD:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("delete word max length %d", textField->getMaxLength()));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UITextFieldTest_Password
|
|
|
|
UITextFieldTest_Password::UITextFieldTest_Password()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UITextFieldTest_Password::~UITextFieldTest_Password()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UITextFieldTest_Password::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add a label in which the textfield events will be displayed
|
2014-04-03 15:52:42 +08:00
|
|
|
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:52:42 +08:00
|
|
|
Text *alert = Text::create("TextField password","fonts/Marker Felt.ttf",30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the textfield
|
2014-07-29 09:56:33 +08:00
|
|
|
TextField* textField = TextField::create("input password here","Arial",30);
|
2013-11-06 16:04:06 +08:00
|
|
|
textField->setPasswordEnabled(true);
|
2013-09-16 20:54:13 +08:00
|
|
|
textField->setPasswordStyleText("*");
|
2014-05-15 01:07:09 +08:00
|
|
|
textField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f));
|
2014-05-12 11:29:22 +08:00
|
|
|
textField->addEventListener(CC_CALLBACK_2(UITextFieldTest_Password::textFieldEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(textField);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
void UITextFieldTest_Password::textFieldEvent(Ref *pSender, TextField::EventType type)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-09-17 20:13:23 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::ATTACH_WITH_IME:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.225f,
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("attach with IME password"));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DETACH_WITH_IME:
|
2013-09-17 20:13:23 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
|
|
|
_displayValueLabel->setString(StringUtils::format("detach with IME password"));
|
2013-09-17 20:13:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::INSERT_TEXT:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("insert words password"));
|
2013-09-17 20:13:23 +08:00
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DELETE_BACKWARD:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("delete word password"));
|
2013-09-17 20:13:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
// UITextFieldTest_LineWrap
|
|
|
|
UITextFieldTest_LineWrap::UITextFieldTest_LineWrap()
|
2014-04-09 22:53:59 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UITextFieldTest_LineWrap::~UITextFieldTest_LineWrap()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UITextFieldTest_LineWrap::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
// Add a label in which the textfield events will be displayed
|
2014-04-03 15:52:42 +08:00
|
|
|
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",30);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
2014-06-20 11:18:53 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5));
|
2014-03-04 16:51:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:52:42 +08:00
|
|
|
Text *alert = Text::create("TextField line wrap","fonts/Marker Felt.ttf",30);
|
2014-03-04 16:51:35 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075));
|
2014-03-04 16:51:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the textfield
|
2014-04-03 15:52:42 +08:00
|
|
|
TextField* textField = TextField::create("input words here","fonts/Marker Felt.ttf",30);
|
2014-03-06 21:58:45 +08:00
|
|
|
textField->ignoreContentAdaptWithSize(false);
|
2014-07-17 16:23:38 +08:00
|
|
|
((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true);
|
2014-07-29 09:56:33 +08:00
|
|
|
textField->setContentSize(Size(240, 170));
|
2014-09-15 11:13:56 +08:00
|
|
|
textField->setString("input words here");
|
2014-03-04 16:51:35 +08:00
|
|
|
textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
|
|
|
|
textField->setTextVerticalAlignment(TextVAlignment::CENTER);
|
2014-05-15 01:07:09 +08:00
|
|
|
textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2014-05-12 11:29:22 +08:00
|
|
|
textField->addEventListener(CC_CALLBACK_2(UITextFieldTest_LineWrap::textFieldEvent, this));
|
2014-03-04 16:51:35 +08:00
|
|
|
_uiLayer->addChild(textField);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
void UITextFieldTest_LineWrap::textFieldEvent(Ref *pSender, TextField::EventType type)
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::ATTACH_WITH_IME:
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2015-07-15 12:04:48 +08:00
|
|
|
textField->runAction(MoveTo::create(0.225f,
|
2014-07-29 09:56:33 +08:00
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 30)));
|
2014-03-04 16:51:35 +08:00
|
|
|
textField->setTextHorizontalAlignment(TextHAlignment::LEFT);
|
|
|
|
textField->setTextVerticalAlignment(TextVAlignment::TOP);
|
|
|
|
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("attach with IME"));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DETACH_WITH_IME:
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2016-12-13 13:38:49 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
|
2014-03-04 16:51:35 +08:00
|
|
|
textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
|
|
|
|
textField->setTextVerticalAlignment(TextVAlignment::CENTER);
|
|
|
|
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("detach with IME"));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::INSERT_TEXT:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("insert words"));
|
2014-03-04 16:51:35 +08:00
|
|
|
break;
|
|
|
|
|
2014-05-12 11:29:22 +08:00
|
|
|
case TextField::EventType::DELETE_BACKWARD:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("delete word"));
|
2014-03-04 16:51:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 14:29:28 +08:00
|
|
|
|
|
|
|
// UITextFieldTest_TrueTypeFont
|
|
|
|
UITextFieldTest_TrueTypeFont::UITextFieldTest_TrueTypeFont()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UITextFieldTest_TrueTypeFont::~UITextFieldTest_TrueTypeFont()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UITextFieldTest_TrueTypeFont::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the textfield events will be displayed
|
|
|
|
_displayValueLabel = Text::create("True Type Font Test - No Event","fonts/Marker Felt.ttf",32);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("TextField","fonts/Marker Felt.ttf",30);
|
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the textfield
|
|
|
|
TextField* textField = TextField::create("input words here","fonts/A Damn Mess.ttf",30);
|
|
|
|
|
|
|
|
textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
|
|
textField->addEventListener(CC_CALLBACK_2(UITextFieldTest_TrueTypeFont::textFieldEvent, this));
|
|
|
|
_uiLayer->addChild(textField);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UITextFieldTest_TrueTypeFont::textFieldEvent(Ref *pSender, TextField::EventType type)
|
2014-08-13 11:28:37 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TextField::EventType::ATTACH_WITH_IME:
|
|
|
|
{
|
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.225f,
|
2014-08-13 11:28:37 +08:00
|
|
|
Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("attach with IME"));
|
2014-08-13 11:28:37 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TextField::EventType::DETACH_WITH_IME:
|
|
|
|
{
|
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
|
|
|
_displayValueLabel->setString(StringUtils::format("detach with IME"));
|
2014-08-13 11:28:37 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TextField::EventType::INSERT_TEXT:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("insert words"));
|
2014-08-13 11:28:37 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TextField::EventType::DELETE_BACKWARD:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("delete word"));
|
2014-08-13 11:28:37 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UITextFieldTest_PlaceHolderColor
|
|
|
|
UITextFieldTest_PlaceHolderColor::UITextFieldTest_PlaceHolderColor()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UITextFieldTest_PlaceHolderColor::~UITextFieldTest_PlaceHolderColor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UITextFieldTest_PlaceHolderColor::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the textfield events will be displayed
|
2015-01-26 18:26:59 +08:00
|
|
|
_displayValueLabel = Text::create("You should see 16.50000, 34.0000 in the output window the first time you type","fonts/Marker Felt.ttf",12);
|
2014-08-13 11:28:37 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("TextField","fonts/Marker Felt.ttf",30);
|
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the textfield
|
|
|
|
TextField* textField = TextField::create("input words here","Arial",30);
|
|
|
|
textField->setPlaceHolder("input text here");
|
|
|
|
textField->setPlaceHolderColor(Color4B::GREEN);
|
|
|
|
textField->setTextColor(Color4B::RED);
|
|
|
|
textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
|
|
textField->addEventListener(CC_CALLBACK_2(UITextFieldTest_PlaceHolderColor::textFieldEvent, this));
|
|
|
|
_uiLayer->addChild(textField);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UITextFieldTest_PlaceHolderColor::textFieldEvent(Ref *pSender, TextField::EventType type)
|
2014-07-14 14:29:28 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TextField::EventType::ATTACH_WITH_IME:
|
|
|
|
{
|
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.225f,
|
2014-07-14 14:29:28 +08:00
|
|
|
Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f)));
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("attach with IME"));
|
2014-07-14 14:29:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TextField::EventType::DETACH_WITH_IME:
|
|
|
|
{
|
|
|
|
TextField* textField = dynamic_cast<TextField*>(pSender);
|
2015-07-15 12:04:48 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
|
|
|
textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)));
|
|
|
|
_displayValueLabel->setString(StringUtils::format("detach with IME"));
|
2014-07-14 14:29:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TextField::EventType::INSERT_TEXT:
|
2015-01-26 18:26:59 +08:00
|
|
|
{
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("insert words"));
|
2015-01-28 15:34:28 +08:00
|
|
|
CCLOG("%f, %f", dynamic_cast<TextField*>(pSender)->getContentSize().width, dynamic_cast<TextField*>(pSender)->getContentSize().height);
|
2015-01-26 18:26:59 +08:00
|
|
|
}
|
2014-07-14 14:29:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TextField::EventType::DELETE_BACKWARD:
|
2015-07-15 12:04:48 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("delete word"));
|
2014-07-14 14:29:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|