From e5b0bbad74caffdc28b532658ec6dde4d00e542f Mon Sep 17 00:00:00 2001 From: CaiWenzhi Date: Mon, 30 Dec 2013 14:40:49 +0800 Subject: [PATCH] Fixed bugs --- cocos/gui/UITextField.cpp | 19 ++++++++++++++---- .../UIListViewTest/UIListViewTest.cpp | 20 ++++++++----------- .../UIListViewTest/UIListViewTest.h | 4 ++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/cocos/gui/UITextField.cpp b/cocos/gui/UITextField.cpp index a9cc8571f8..fa7c89dbe7 100644 --- a/cocos/gui/UITextField.cpp +++ b/cocos/gui/UITextField.cpp @@ -326,10 +326,21 @@ void TextField::setTouchSize(const Size &size) void TextField::setText(const std::string& text) { - if (text.size()==0) - return; - - _textFieldRenderer->setString(text); + std::string strText(text); + if (isMaxLengthEnabled()) + { + strText = strText.substr(0, getMaxLength()); + } + const char* content = strText.c_str(); + if (isPasswordEnabled()) + { + _textFieldRenderer->setPasswordText(content); + _textFieldRenderer->insertText(content, strlen(content)); + } + else + { + _textFieldRenderer->setString(content); + } textfieldRendererScaleChangedWithSize(); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 9ac47f8d73..32b32c70cb 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -70,7 +70,7 @@ bool UIListViewTest_Vertical::init() (backgroundSize.width - listView->getSize().width) / 2.0f, (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - listView->getSize().height) / 2.0f)); - listView->addEventListenerScrollView(this, scrollvieweventselector(UIListViewTest_Vertical::selectedItemEvent)); + listView->addEventListenerListView(this, listvieweventselector(UIListViewTest_Vertical::selectedItemEvent)); _uiLayer->addChild(listView); @@ -167,22 +167,20 @@ bool UIListViewTest_Vertical::init() return false; } -void UIListViewTest_Vertical::selectedItemEvent(Object *pSender, ScrollviewEventType type) +void UIListViewTest_Vertical::selectedItemEvent(Object *pSender, ListViewEventType type) { - /* switch (type) { - case SCROLLVIEW_EVENT_SELECT_CHILD: + case LISTVIEW_ONSELECTEDITEM: { ListView* listView = static_cast(pSender); - CCLOG("select child index = %d", listView->getSelectedChildIndex()); + CCLOG("select child index = %ld", listView->getCurSelectedIndex()); } break; default: break; } - */ } // UIListViewTest_Horizontal @@ -245,7 +243,7 @@ bool UIListViewTest_Horizontal::init() (backgroundSize.width - listView->getSize().width) / 2.0f, (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - listView->getSize().height) / 2.0f)); - listView->addEventListenerScrollView(this, scrollvieweventselector(UIListViewTest_Horizontal::selectedItemEvent)); + listView->addEventListenerListView(this, listvieweventselector(UIListViewTest_Horizontal::selectedItemEvent)); _uiLayer->addChild(listView); @@ -342,20 +340,18 @@ bool UIListViewTest_Horizontal::init() return false; } -void UIListViewTest_Horizontal::selectedItemEvent(Object *pSender, ScrollviewEventType type) +void UIListViewTest_Horizontal::selectedItemEvent(Object *pSender, ListViewEventType type) { - /* switch (type) { - case SCROLLVIEW_EVENT_SELECT_CHILD: + case LISTVIEW_ONSELECTEDITEM: { ListView* listView = static_cast(pSender); - CCLOG("select child index = %d", listView->getSelectedChildIndex()); + CCLOG("select child index = %ld", listView->getCurSelectedIndex()); } break; default: break; } - */ } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h index c52c33eb81..5efd46d704 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h @@ -33,7 +33,7 @@ public: UIListViewTest_Vertical(); ~UIListViewTest_Vertical(); bool init(); - void selectedItemEvent(Object* pSender, ScrollviewEventType type); + void selectedItemEvent(Object* pSender, ListViewEventType type); protected: UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical) @@ -48,7 +48,7 @@ public: UIListViewTest_Horizontal(); ~UIListViewTest_Horizontal(); bool init(); - void selectedItemEvent(Object* pSender, ScrollviewEventType type); + void selectedItemEvent(Object* pSender, ListViewEventType type); protected: UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal)