mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
Adds logic to guiTextEditCtrl to have placeholder text when the control is empty.
This commit is contained in:
parent
67dbe4dfe2
commit
758dd20724
2 changed files with 34 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue