mirror of https://github.com/axmolengine/axmol.git
fix text only button issue
This commit is contained in:
parent
bb0b7a9b8a
commit
ed22792a72
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -238,7 +238,7 @@ void ImageView::adaptRenderers()
|
|||
}
|
||||
}
|
||||
|
||||
const Size& ImageView::getVirtualRendererSize() const
|
||||
const Size ImageView::getVirtualRendererSize() const
|
||||
{
|
||||
return _imageTextureSize;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -265,7 +265,7 @@ void LoadingBar::ignoreContentAdaptWithSize(bool ignore)
|
|||
}
|
||||
}
|
||||
|
||||
const Size& LoadingBar::getVirtualRendererSize() const
|
||||
const Size LoadingBar::getVirtualRendererSize() const
|
||||
{
|
||||
return _barRendererTextureSize;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -449,7 +449,7 @@ void Slider::adaptRenderers()
|
|||
}
|
||||
}
|
||||
|
||||
const Size& Slider::getVirtualRendererSize() const
|
||||
const Size Slider::getVirtualRendererSize() const
|
||||
{
|
||||
return _barRenderer->getContentSize();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -292,7 +292,7 @@ void Text::adaptRenderers()
|
|||
}
|
||||
}
|
||||
|
||||
const Size& Text::getVirtualRendererSize() const
|
||||
const Size Text::getVirtualRendererSize() const
|
||||
{
|
||||
return _labelRenderer->getContentSize();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -135,7 +135,7 @@ void TextAtlas::adaptRenderers()
|
|||
}
|
||||
}
|
||||
|
||||
const Size& TextAtlas::getVirtualRendererSize() const
|
||||
const Size TextAtlas::getVirtualRendererSize() const
|
||||
{
|
||||
return _labelAtlasRenderer->getContentSize();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -129,7 +129,7 @@ void TextBMFont::adaptRenderers()
|
|||
}
|
||||
}
|
||||
|
||||
const Size& TextBMFont::getVirtualRendererSize() const
|
||||
const Size TextBMFont::getVirtualRendererSize() const
|
||||
{
|
||||
return _labelBMFontRenderer->getContentSize();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -468,7 +468,7 @@ void Widget::onSizeChanged()
|
|||
}
|
||||
}
|
||||
|
||||
const Size& Widget::getVirtualRendererSize() const
|
||||
const Size Widget::getVirtualRendererSize() const
|
||||
{
|
||||
return _contentSize;
|
||||
}
|
||||
|
|
|
@ -489,7 +489,7 @@ public:
|
|||
virtual Node* getVirtualRenderer();
|
||||
|
||||
|
||||
virtual const Size& getVirtualRendererSize() const;
|
||||
virtual const Size getVirtualRendererSize() const;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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__) */
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ enum
|
|||
kUIButtonTest_RemoveSelf,
|
||||
kUIButtonTestSwitchScale9,
|
||||
kUIButtonTestZoomScale,
|
||||
kUIButtonTextOnly,
|
||||
kUIEditBoxTest,
|
||||
kUICheckBoxTest,
|
||||
kUISliderTest,
|
||||
|
|
Loading…
Reference in New Issue