From a72e65b4de8838595ba904bd254a00b75d19f3f5 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 20 Jan 2015 18:40:25 +0800 Subject: [PATCH] add function for uiText and uiTextField --- cocos/ui/UIText.cpp | 5 +++++ cocos/ui/UIText.h | 2 ++ cocos/ui/UITextField.cpp | 13 +++++++++++++ cocos/ui/UITextField.h | 1 + 4 files changed, 21 insertions(+) diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp index e96b8edc43..58cbfc65a4 100644 --- a/cocos/ui/UIText.cpp +++ b/cocos/ui/UIText.cpp @@ -283,6 +283,11 @@ void Text::adaptRenderers() } Size Text::getVirtualRendererSize() const +{ + return _labelRenderer->getContentSize(); +} + +Size Text::getAutoRenderSize() { Size virtualSize = _labelRenderer->getContentSize(); if (!_ignoreSize) diff --git a/cocos/ui/UIText.h b/cocos/ui/UIText.h index 0ad280783e..0f0eceed44 100644 --- a/cocos/ui/UIText.h +++ b/cocos/ui/UIText.h @@ -144,6 +144,8 @@ public: //override "getVirtualRenderer" method of widget. virtual Node* getVirtualRenderer() override; + virtual Size getAutoRenderSize(); + /** * Returns the "class name" of widget. */ diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp index 04a893de6e..0272c3cb4d 100644 --- a/cocos/ui/UITextField.cpp +++ b/cocos/ui/UITextField.cpp @@ -768,6 +768,19 @@ void TextField::textfieldRendererScaleChangedWithSize() _textFieldRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } +Size TextField::getAutoRenderSize() +{ + Size virtualSize = _textFieldRenderer->getContentSize(); + if (!_ignoreSize) + { + _textFieldRenderer->setDimensions(0, 0); + virtualSize = _textFieldRenderer->getContentSize(); + _textFieldRenderer->setDimensions(_contentSize.width, _contentSize.height); + } + + return virtualSize; +} + Size TextField::getVirtualRendererSize() const { return _textFieldRenderer->getContentSize(); diff --git a/cocos/ui/UITextField.h b/cocos/ui/UITextField.h index cc256f18e7..fcb9f86539 100644 --- a/cocos/ui/UITextField.h +++ b/cocos/ui/UITextField.h @@ -187,6 +187,7 @@ public: */ virtual std::string getDescription() const override; + virtual Size getAutoRenderSize(); virtual Size getVirtualRendererSize() const override; virtual Node* getVirtualRenderer() override; void attachWithIME();