From ee996a5cfb10861c1562915d5d6d2f22e0d321d2 Mon Sep 17 00:00:00 2001 From: rh101 Date: Fri, 27 Nov 2020 16:59:34 +1100 Subject: [PATCH] Ensure global Z is correctly set on all child items of EditBox --- cocos/ui/UIEditBox/UIEditBox.cpp | 9 +++++++++ cocos/ui/UIEditBox/UIEditBox.h | 2 ++ cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp | 15 +++++++++++++++ cocos/ui/UIEditBox/UIEditBoxImpl-common.h | 1 + cocos/ui/UIEditBox/UIEditBoxImpl.h | 4 +++- 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cocos/ui/UIEditBox/UIEditBox.cpp b/cocos/ui/UIEditBox/UIEditBox.cpp index efc3d6a826..8fff0e81bc 100755 --- a/cocos/ui/UIEditBox/UIEditBox.cpp +++ b/cocos/ui/UIEditBox/UIEditBox.cpp @@ -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) { diff --git a/cocos/ui/UIEditBox/UIEditBox.h b/cocos/ui/UIEditBox/UIEditBox.h index 1e8bb2fef5..f1c8a347e0 100755 --- a/cocos/ui/UIEditBox/UIEditBox.h +++ b/cocos/ui/UIEditBox/UIEditBox.h @@ -648,6 +648,8 @@ namespace ui { */ virtual void keyboardDidHide(IMEKeyboardNotificationInfo& info) override; + void setGlobalZOrder(float globalZOrder) override; + void openKeyboard() const; protected: diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp b/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp index 96ef5fc132..1f1ce1d8f9 100755 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-common.cpp @@ -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) diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-common.h b/cocos/ui/UIEditBox/UIEditBoxImpl-common.h index 6e193077a0..ff27690ba6 100755 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-common.h +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-common.h @@ -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 diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl.h b/cocos/ui/UIEditBox/UIEditBoxImpl.h index d016bedc12..c303743db4 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl.h +++ b/cocos/ui/UIEditBox/UIEditBoxImpl.h @@ -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 */