| 360 | } |
| 361 | |
| 362 | void TextFieldEx::enableIME(Node* control) |
| 363 | { |
| 364 | if (_touchListener != nullptr) |
| 365 | { |
| 366 | return; |
| 367 | } |
| 368 | _touchListener = EventListenerTouchOneByOne::create(); |
| 369 | |
| 370 | // this->getContentSize() == Vec2::ZERO, so we need to use the size of _renderLabel; |
| 371 | if(control == nullptr) |
| 372 | control = this->_renderLabel; |
| 373 | |
| 374 | _touchListener->onTouchBegan = [control,this](Touch* touch, Event*) { |
| 375 | bool focus = (_checkVisibility(this) && _editable && this->_enabled && |
| 376 | _containsTouchPoint(control, touch)); |
| 377 | |
| 378 | if (this->_continuousTouchDelayTimerID != nullptr) |
| 379 | { |
| 380 | stimer::kill(this->_continuousTouchDelayTimerID); |
| 381 | this->_continuousTouchDelayTimerID = nullptr; |
| 382 | } |
| 383 | |
| 384 | if (focus && _cursorVisible) |
| 385 | { |
| 386 | auto worldPoint = touch->getLocation(); |
| 387 | if (this->_continuousTouchCallback) |
| 388 | { |
| 389 | this->_continuousTouchDelayTimerID = stimer::delay( |
| 390 | this->_continuousTouchDelayTime, [=, this]() { this->_continuousTouchCallback(worldPoint); }); |
| 391 | } |
| 392 | } |
| 393 | return true; |
| 394 | }; |
| 395 | _touchListener->onTouchEnded = [control, this](Touch* touch, Event* e) { |
| 396 | if (this->_continuousTouchDelayTimerID != nullptr) |
| 397 | { |
| 398 | stimer::kill(this->_continuousTouchDelayTimerID); |
| 399 | this->_continuousTouchDelayTimerID = nullptr; |
| 400 | } |
| 401 | |
| 402 | bool focus = (_checkVisibility(this) && _editable && this->_enabled && |
| 403 | _containsTouchPoint(control, touch)); |
| 404 | |
| 405 | if (focus) |
| 406 | { |
| 407 | if (!s_keyboardVisible || !_cursorVisible) |
| 408 | openIME(); |
| 409 | if (_touchCursorControlEnabled) |
| 410 | { |
| 411 | auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); |
| 412 | __moveCursorTo(renderLabelPoint.x); |
| 413 | } |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | closeIME(); |
| 418 | } |
| 419 | }; |
no test coverage detected