From 2785a4313fcae0b27857fa2d6d9f4cd67f7a6a13 Mon Sep 17 00:00:00 2001 From: dimon4eg Date: Wed, 30 Sep 2015 12:31:33 +0300 Subject: [PATCH 1/2] Set focus for widgets --- cocos/ui/UITextField.cpp | 1 + cocos/ui/UIWidget.cpp | 8 +++++++- cocos/ui/UIWidget.h | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 89388b2c95..63d578d1e1 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -536,6 +536,7 @@ bool TextField::onTouchBegan(Touch *touch, Event *unusedEvent) bool pass = Widget::onTouchBegan(touch, unusedEvent); if (_hitted) { + requestFocus(); _textFieldRenderer->attachWithIME(); } else diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index ac4c173e46..0c494db808 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -888,6 +888,12 @@ void Widget::moveEvent() void Widget::releaseUpEvent() { this->retain(); + + if (isFocusEnabled()) + { + requestFocus(); + } + if (_touchEventCallback) { _touchEventCallback(this, TouchEventType::ENDED); @@ -1449,7 +1455,7 @@ void Widget::onFocusChange(Widget* widgetLostFocus, Widget* widgetGetFocus) } } -Widget* Widget::getCurrentFocusedWidget()const +Widget* Widget::getCurrentFocusedWidget() { return _focusedWidget; } diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index d0de0b155c..f625931eed 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -775,7 +775,7 @@ public: * Return a current focused widget in your UI scene. * No matter what widget object you call this method on , it will return you the exact one focused widget. */ - Widget* getCurrentFocusedWidget()const; + static Widget* getCurrentFocusedWidget(); /* * Call this method with parameter true to enable the Android Dpad focus navigation feature From fe8c1a12b558789f0a86f93e707eac897220802f Mon Sep 17 00:00:00 2001 From: dimon4eg Date: Wed, 30 Sep 2015 12:39:44 +0300 Subject: [PATCH 2/2] Fix for text field --- cocos/ui/UITextField.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 63d578d1e1..dc13ee6b07 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -536,7 +536,11 @@ bool TextField::onTouchBegan(Touch *touch, Event *unusedEvent) bool pass = Widget::onTouchBegan(touch, unusedEvent); if (_hitted) { - requestFocus(); + if (isFocusEnabled()) + { + requestFocus(); + } + _textFieldRenderer->attachWithIME(); } else