fix text only button issue

This commit is contained in:
andyque 2014-09-12 13:50:13 +08:00
parent bb0b7a9b8a
commit ed22792a72
26 changed files with 90 additions and 23 deletions

View File

@ -470,8 +470,12 @@ void Button::adaptRenderers()
}
}
const Size& Button::getVirtualRendererSize() const
const Size Button::getVirtualRendererSize() const
{
Size titleSize = _titleRenderer->getContentSize();
if (titleSize.width > _normalTextureSize.width) {
return titleSize;
}
return _normalTextureSize;
}

View File

@ -170,7 +170,7 @@ public:
virtual void ignoreContentAdaptWithSize(bool ignore) override;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -184,7 +184,7 @@ public:
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -238,7 +238,7 @@ void ImageView::adaptRenderers()
}
}
const Size& ImageView::getVirtualRendererSize() const
const Size ImageView::getVirtualRendererSize() const
{
return _imageTextureSize;
}

View File

@ -108,7 +108,7 @@ public:
*/
virtual std::string getDescription() const override;
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override;
CC_CONSTRUCTOR_ACCESS:

View File

@ -265,7 +265,7 @@ void LoadingBar::ignoreContentAdaptWithSize(bool ignore)
}
}
const Size& LoadingBar::getVirtualRendererSize() const
const Size LoadingBar::getVirtualRendererSize() const
{
return _barRendererTextureSize;
}

View File

@ -130,7 +130,7 @@ public:
virtual void ignoreContentAdaptWithSize(bool ignore) override;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -451,7 +451,7 @@ void RichText::setAnchorPoint(const Vec2 &pt)
_elementRenderersContainer->setAnchorPoint(pt);
}
const Size& RichText::getVirtualRendererSize() const
const Size RichText::getVirtualRendererSize() const
{
return _elementRenderersContainer->getContentSize();
}

View File

@ -106,7 +106,7 @@ public:
void setVerticalSpace(float space);
virtual void setAnchorPoint(const Vec2 &pt);
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
void formatText();
virtual void ignoreContentAdaptWithSize(bool ignore);
virtual std::string getDescription() const override;

View File

@ -449,7 +449,7 @@ void Slider::adaptRenderers()
}
}
const Size& Slider::getVirtualRendererSize() const
const Size Slider::getVirtualRendererSize() const
{
return _barRenderer->getContentSize();
}

View File

@ -194,7 +194,7 @@ public:
virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -292,7 +292,7 @@ void Text::adaptRenderers()
}
}
const Size& Text::getVirtualRendererSize() const
const Size Text::getVirtualRendererSize() const
{
return _labelRenderer->getContentSize();
}

View File

@ -139,7 +139,7 @@ public:
bool isTouchScaleChangeEnabled()const;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -135,7 +135,7 @@ void TextAtlas::adaptRenderers()
}
}
const Size& TextAtlas::getVirtualRendererSize() const
const Size TextAtlas::getVirtualRendererSize() const
{
return _labelAtlasRenderer->getContentSize();
}

View File

@ -93,7 +93,7 @@ public:
ssize_t getStringLength()const;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -129,7 +129,7 @@ void TextBMFont::adaptRenderers()
}
}
const Size& TextBMFont::getVirtualRendererSize() const
const Size TextBMFont::getVirtualRendererSize() const
{
return _labelBMFontRenderer->getContentSize();
}

View File

@ -81,7 +81,7 @@ public:
*/
ssize_t getStringLength()const;
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override;
/**
* Returns the "class name" of widget.

View File

@ -737,7 +737,7 @@ void TextField::textfieldRendererScaleChangedWithSize()
_textFieldRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
}
const Size& TextField::getVirtualRendererSize() const
const Size TextField::getVirtualRendererSize() const
{
return _textFieldRenderer->getContentSize();
}

View File

@ -187,7 +187,7 @@ public:
*/
virtual std::string getDescription() const override;
virtual const Size& getVirtualRendererSize() const override;
virtual const Size getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override;
void attachWithIME();
virtual void onEnter() override;

View File

@ -468,7 +468,7 @@ void Widget::onSizeChanged()
}
}
const Size& Widget::getVirtualRendererSize() const
const Size Widget::getVirtualRendererSize() const
{
return _contentSize;
}

View File

@ -489,7 +489,7 @@ public:
virtual Node* getVirtualRenderer();
virtual const Size& getVirtualRendererSize() const;
virtual const Size getVirtualRendererSize() const;
/**

View File

@ -89,7 +89,7 @@ g_guisTests[] =
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
sceneManager->setCurrentUISceneId(kUIButtonTest);
sceneManager->setMinUISceneId(kUIButtonTest);
sceneManager->setMaxUISceneId(kUIButtonTestZoomScale);
sceneManager->setMaxUISceneId(kUIButtonTextOnly);
Scene* scene = sceneManager->currentUIScene();
Director::getInstance()->replaceScene(scene);
}

View File

@ -297,7 +297,7 @@ bool UIButtonTest_Title::init()
// Create the button with title
Button* button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
button->setTitleText("Title Button");
button->setTitleText("Title Button Large than button!");
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->setTitleColor(Color3B::YELLOW);
CCASSERT(button->getTitleColor() == Color3B::YELLOW, "Button setTitleColotr & getTitleColor not match!");
@ -592,3 +592,51 @@ void UIButtonTestZoomScale::sliderEvent(Ref *pSender, Slider::EventType type)
_displayValueLabel->setString(String::createWithFormat("Zoom Scale: %f", zoomScale)->getCString());
}
}
// UIButtonTestZoomScale
UIButtonTextOnly::UIButtonTextOnly()
: _displayValueLabel(nullptr)
{
}
UIButtonTextOnly::~UIButtonTextOnly()
{
}
bool UIButtonTextOnly::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create("Text Only Button", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button
auto button = Button::create();
button->setNormalizedPosition(Vec2(0.5, 0.5));
button->setTitleText("PLAY GAME");
button->setPressedActionEnabled(true);
button->addClickEventListener([this](Ref* sender) {
CCLOG("touched!");
});
_uiLayer->addChild(button);
return true;
}
return false;
}

View File

@ -118,4 +118,15 @@ protected:
Text* _displayValueLabel;
};
class UIButtonTextOnly : public UIScene
{
public:
UIButtonTextOnly();
~UIButtonTextOnly();
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIButtonTextOnly)
Text* _displayValueLabel;
};
#endif /* defined(__TestCpp__UIButtonTest__) */

View File

@ -39,6 +39,7 @@ static const char* s_testArray[] =
"UIButtonTest_RemoveSelf",
"UIButtonTestSwitchScale9",
"UIButtonTestZoomScale",
"UIButtonTextOnly",
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
"UIEditBoxTest",
#endif
@ -195,6 +196,8 @@ Scene *UISceneManager::currentUIScene()
return UIButtonTestSwitchScale9::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIButtonTestZoomScale:
return UIButtonTestZoomScale::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIButtonTextOnly:
return UIButtonTextOnly::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUICheckBoxTest:
return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]);

View File

@ -38,6 +38,7 @@ enum
kUIButtonTest_RemoveSelf,
kUIButtonTestSwitchScale9,
kUIButtonTestZoomScale,
kUIButtonTextOnly,
kUIEditBoxTest,
kUICheckBoxTest,
kUISliderTest,