Adds logic to guiTextEditCtrl to have placeholder text when the control is empty.

This commit is contained in:
Areloch 2020-07-11 15:53:21 -05:00
parent 67dbe4dfe2
commit 758dd20724
2 changed files with 34 additions and 1 deletions

View file

@ -141,6 +141,8 @@ GuiTextEditCtrl::GuiTextEditCtrl()
mDoubleClickTimeMS = 50;
mMouseUpTime = 0;
mPlaceholderText = StringTable->EmptyString();
#if defined(__MACOSX__)
UTF8 bullet[4] = { 0xE2, 0x80, 0xA2, 0 };
@ -165,6 +167,9 @@ GuiTextEditCtrl::~GuiTextEditCtrl()
void GuiTextEditCtrl::initPersistFields()
{
addProtectedField("placeholderText", TypeCaseString, Offset(mPlaceholderText, GuiTextEditCtrl), setPlaceholderText, getPlaceholderText,
"The text to show on the control.");
addGroup( "Text Input" );
addField("validate", TypeRealString,Offset(mValidateCommand, GuiTextEditCtrl), "Script command to be called when the first validater is lost.\n");
@ -1335,6 +1340,13 @@ void GuiTextEditCtrl::drawText( const RectI &drawRect, bool isFocused )
textBuffer.set( renderText );
}
bool usePlaceholder = false;
if (textBuffer.length() == 0 && !isFocused)
{
textBuffer.set(mPlaceholderText);
usePlaceholder = true;
}
// Just a little sanity.
if(mCursorPos > textBuffer.length())
mCursorPos = textBuffer.length();
@ -1365,6 +1377,9 @@ void GuiTextEditCtrl::drawText( const RectI &drawRect, bool isFocused )
ColorI fontColor = mActive ? mProfile->mFontColor : mProfile->mFontColorNA;
if (usePlaceholder)
fontColor = mProfile->mFontColorNA;
// now draw the text
Point2I cursorStart, cursorEnd;
mTextOffset.y = drawPoint.y;