Skip to content

Commit 62aa66a

Browse files
committed
faet(placeholder): Fix placeholder not showing up
1 parent 9eafa7c commit 62aa66a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/BetterTextInputNode.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ bool BetterTextInputNode::init(float p0, float p1, char const* p2, char const* p
1010
{
1111
if (!CCTextInputNode::init(p0, p1, p2, p3, p4, p5)) return false;
1212

13+
m_fields->m_placeholder_str = p2;
14+
1315
appendHighlightNode();
1416

1517
return true;
@@ -26,6 +28,9 @@ bool BetterTextInputNode::onTextFieldDetachWithIME(cocos2d::CCTextFieldTTF* tFie
2628
{
2729
g_selectedInput = nullptr;
2830

31+
if (m_fields->m_string.empty())
32+
onStringEmpty();
33+
2934
return CCTextInputNode::onTextFieldDetachWithIME(tField);
3035
}
3136

@@ -432,12 +437,19 @@ void BetterTextInputNode::onCut()
432437
// other events
433438
void BetterTextInputNode::onStringEmpty()
434439
{
440+
std::string&& newString = "";
441+
442+
if (g_selectedInput)
443+
newString = "";
444+
else
445+
newString = m_fields->m_placeholder_str;
446+
435447
if (this->m_placeholderLabel)
436-
this->m_placeholderLabel->setString("");
448+
this->m_placeholderLabel->setString(newString.c_str());
437449
else
438-
this->m_textArea->setString("");
450+
this->m_textArea->setString(newString.c_str());
439451
updateBlinkLabelToCharForced(-1);
440-
showTextOrPlaceholder(false);
452+
showTextOrPlaceholder(true);
441453
}
442454

443455

src/BetterTextInputNode.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class BetterTextInputNode : public geode::Modify<BetterTextInputNode, CCTextInpu
1414
// the actual string, because we basically rework everything about the input text insertion is broken :D
1515
// (getString() normally returns the last character or is empty, we hook CCTextFieldTTF::getString to fix this)
1616
std::string m_string = "";
17+
std::string m_placeholder_str = "";
1718

1819
// current cursor position
1920
int m_pos = -1;

0 commit comments

Comments
 (0)