Ensure global Z is correctly set on all child items of EditBox

This commit is contained in:
rh101 2020-11-27 16:59:34 +11:00
parent 192a59f39e
commit ee996a5cfb
5 changed files with 30 additions and 1 deletions

View File

@ -864,6 +864,15 @@ void EditBox::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/)
}
void EditBox::setGlobalZOrder(float globalZOrder)
{
Widget::setGlobalZOrder(globalZOrder);
if (_editBoxImpl)
{
_editBoxImpl->setGlobalZOrder(globalZOrder);
}
}
#if CC_ENABLE_SCRIPT_BINDING
void EditBox::registerScriptEditBoxHandler(int handler)
{

View File

@ -648,6 +648,8 @@ namespace ui {
*/
virtual void keyboardDidHide(IMEKeyboardNotificationInfo& info) override;
void setGlobalZOrder(float globalZOrder) override;
void openKeyboard() const;
protected:

View File

@ -96,12 +96,14 @@ void EditBoxImplCommon::initInactiveLabels(const Size& size)
_label->setAnchorPoint(Vec2(0.0f,1.0f));
_label->setOverflow(Label::Overflow::CLAMP);
_label->setVisible(false);
_label->setGlobalZOrder(_editBox->getGlobalZOrder());
_editBox->addChild(_label, kLabelZOrder);
_labelPlaceHolder = Label::create();
_labelPlaceHolder->setAnchorPoint(Vec2(0.0f, 1.0f));
_labelPlaceHolder->setTextColor(Color4B::GRAY);
_labelPlaceHolder->enableWrap(false);
_labelPlaceHolder->setGlobalZOrder(_editBox->getGlobalZOrder());
_editBox->addChild(_labelPlaceHolder, kLabelZOrder);
setFont(pDefaultFontName, size.height*2/3);
@ -291,6 +293,19 @@ void EditBoxImplCommon::setContentSize(const Size& size)
placeInactiveLabels(_contentSize);
}
void EditBoxImplCommon::setGlobalZOrder(float globalZOrder)
{
if (_label)
{
_label->setGlobalZOrder(globalZOrder);
}
if (_labelPlaceHolder)
{
_labelPlaceHolder->setGlobalZOrder(globalZOrder);
}
}
void EditBoxImplCommon::draw(Renderer* /*renderer*/, const Mat4& /*transform*/, uint32_t flags)
{
if(flags)

View File

@ -91,6 +91,7 @@ public:
virtual void setAnchorPoint(const Vec2& anchorPoint) override {}
virtual void setPosition(const Vec2& pos) override {}
virtual void setGlobalZOrder(float globalZOrder) override;
/**
* @js NA

View File

@ -86,7 +86,9 @@ namespace cocos2d {
virtual void setVisible(bool visible) = 0;
virtual void setContentSize(const Size& size) = 0;
virtual void setAnchorPoint(const Vec2& anchorPoint) = 0;
virtual void setGlobalZOrder(float globalZOrder) = 0;
/**
* check the editbox's position, update it when needed
*/