@@ -144,12 +144,12 @@ void EditBoxImplCommon::setInactiveText(const char* pText)
144
144
_label->setString (pText);
145
145
}
146
146
// Clip the text width to fit to the text box
147
- float fMaxWidth = _editBox->getContentSize (). width ;
148
- float fMaxHeight = _editBox-> getContentSize (). height ;
147
+ const auto & editBoxSize = _editBox->getContentSize ();
148
+ const auto maxSize = applyPadding ( cocos2d::Size (editBoxSize. width , editBoxSize. height )) ;
149
149
Size labelSize = _label->getContentSize ();
150
- if (labelSize.width > fMaxWidth || labelSize.height > fMaxHeight )
150
+ if (labelSize.width > maxSize. width || labelSize.height > maxSize. height )
151
151
{
152
- _label->setDimensions (fMaxWidth , fMaxHeight );
152
+ _label->setDimensions (maxSize. width , maxSize. height );
153
153
}
154
154
}
155
155
@@ -201,7 +201,7 @@ void EditBoxImplCommon::setInputMode(EditBox::InputMode inputMode)
201
201
{
202
202
_editBoxInputMode = inputMode;
203
203
this ->setNativeInputMode (inputMode);
204
- this ->placeInactiveLabels (_editBox->getContentSize ());
204
+ this ->placeInactiveLabels (applyPadding ( _editBox->getContentSize () ));
205
205
}
206
206
207
207
void EditBoxImplCommon::setMaxLength (int maxLength)
@@ -282,9 +282,9 @@ void EditBoxImplCommon::setVisible(bool visible)
282
282
283
283
void EditBoxImplCommon::setContentSize (const Size& size)
284
284
{
285
- _contentSize = size;
286
- CCLOG (" [Edit text] content size = (%f, %f)" , size .width , size .height );
287
- placeInactiveLabels (size );
285
+ _contentSize = applyPadding ( size) ;
286
+ CCLOG (" [Edit text] content size = (%f, %f)" , _contentSize .width , _contentSize .height );
287
+ placeInactiveLabels (_contentSize );
288
288
}
289
289
290
290
void EditBoxImplCommon::draw (Renderer* /* renderer*/ , const Mat4& /* transform*/ , uint32_t flags)
@@ -413,6 +413,11 @@ void EditBoxImplCommon::editBoxEditingChanged(const std::string& text)
413
413
414
414
}
415
415
416
+ Size ui::EditBoxImplCommon::applyPadding (const Size& sizeToCorrect) const {
417
+ constexpr auto paddingLeftRight = CC_EDIT_BOX_PADDING * 2 ;
418
+ return Size (sizeToCorrect.width - paddingLeftRight, sizeToCorrect.height );
419
+ }
420
+
416
421
NS_CC_END
417
422
418
423
0 commit comments