From 52596dc97f9cc7a8b17d9e6f934a61bf5a6f80bf Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 15 Jul 2014 11:46:53 +0800 Subject: [PATCH 1/2] fix Text line wrap issue --- cocos/ui/UIText.cpp | 1 - cocos/ui/UIWidget.h | 18 +++++++----------- .../UITextTest/UITextTest.cpp | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index e0d0f1ae38..2a0cd717b8 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -296,7 +296,6 @@ void Text::labelScaleChangedWithSize() { if (_ignoreSize) { - _labelRenderer->setDimensions(0,0); _labelRenderer->setScale(1.0f); _normalScaleValueX = _normalScaleValueY = 1.0f; } diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 935d6f8628..ecb8c375c4 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -456,16 +456,18 @@ public: /** - * Ignore the widget size * - * @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true. + * Note: when you set _ignoreSize to true, no matther you call setContentSize or not, + * the widget size is always equal to the return value of the member function getVirtualRendererSize. + * + * @param ignore, set member variabl _ignoreSize to ignore */ virtual void ignoreContentAdaptWithSize(bool ignore); /** - * Gets the widget if is ignore it's size. + * Query whether the widget ignores user deinfed content size or not * - * @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true. + * @return bool */ bool isIgnoreContentAdaptWithSize() const; @@ -485,15 +487,9 @@ public: */ virtual Node* getVirtualRenderer(); -// /** -// * Gets the content size of widget. -// * -// * Content size is widget's texture size. -// */ -// virtual const Size& getContentSize() const; + virtual const Size& getVirtualRendererSize() const; - /** * Returns the "class name" of widget. diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp index 98dcbfba44..3496c455b2 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp @@ -40,10 +40,25 @@ bool UITextTest_LineWrap::init() _uiLayer->addChild(alert); // Create the line wrap - Text* text = Text::create("Text can line wrap","AmericanTypewriter",32); + Text* text = Text::create("TextArea Widget can line wrap","AmericanTypewriter",32); text->ignoreContentAdaptWithSize(false); text->setContentSize(Size(280, 150)); text->setTextHorizontalAlignment(TextHAlignment::CENTER); + text->setTouchScaleChangeEnabled(true); + text->setTouchEnabled(true); + text->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type) + { + if (type == Widget::TouchEventType::ENDED) + { + if ((int)text->getContentSize().width == 280) + { + text->setContentSize(Size(380,100)); + }else + { + text->setContentSize(Size(280, 150)); + } + } + }); text->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - text->getContentSize().height / 8.0f)); _uiLayer->addChild(text); From e2bbc3d54d92ca2e642b4062d6421e11cd6bcc33 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 15 Jul 2014 11:48:55 +0800 Subject: [PATCH 2/2] [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index ad5c3e1d42..ed3a595aa7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ cocos2d-x-3.2 ?? [FIX] SpriteBatchNode: opacity can not work [FIX] Sprite3D: may crash on Android if playing animation and replace Scene after come from background [FIX] UIdget: opacity is wrong when replace texture + [FIX] UIText: can not wrap words automatically [FIX] UITextField: keyboard can not hide if touching space outside of keyboard [FIX] Others: don't release singleton objects correctly that are needed in the whole game, which will be treated