diff --git a/loader/include/Geode/ui/TextInput.hpp b/loader/include/Geode/ui/TextInput.hpp index f771c6755..8c6329cbf 100644 --- a/loader/include/Geode/ui/TextInput.hpp +++ b/loader/include/Geode/ui/TextInput.hpp @@ -43,6 +43,7 @@ namespace geode { CCTextInputNode* m_input; std::function m_onInput = nullptr; cocos2d::CCLabelBMFont* m_label = nullptr; + bool m_callbackEnabled = true; bool init(float width, std::string const& placeholder, std::string const& font); @@ -111,6 +112,10 @@ namespace geode { * the text input */ void setCallback(std::function onInput); + /** + * Enables/disables the callback. + */ + void setCallbackEnabled(bool enabled); /** * Enable/disable the input */ @@ -137,6 +142,10 @@ namespace geode { * Get the current value of the input */ std::string getString() const; + /** + * Gets if the callback is enabled or not. + */ + bool isCallbackEnabled() const; /** * Focus this input (activate the cursor) diff --git a/loader/src/ui/nodes/TextInput.cpp b/loader/src/ui/nodes/TextInput.cpp index a54fa744e..bcfbc5e77 100644 --- a/loader/src/ui/nodes/TextInput.cpp +++ b/loader/src/ui/nodes/TextInput.cpp @@ -91,7 +91,7 @@ TextInput* TextInput::create(float width, std::string const& placeholder, std::s } void TextInput::textChanged(CCTextInputNode* input) { - if (m_onInput) { + if (m_onInput && m_callbackEnabled) { m_onInput(input->getString()); } } @@ -150,6 +150,9 @@ void TextInput::setCallback(std::function onInput) { this->setDelegate(this); m_onInput = onInput; } +void TextInput::setCallbackEnabled(bool enabled) { + m_callbackEnabled = enabled; +} void TextInput::setEnabled(bool enabled) { m_input->setTouchEnabled(enabled); m_input->m_placeholderLabel->setOpacity(enabled ? 255 : 150); @@ -189,6 +192,9 @@ void TextInput::setString(std::string const& str, bool triggerCallback) { std::string TextInput::getString() const { return m_input->getString(); } +bool TextInput::isCallbackEnabled() const { + return m_callbackEnabled; +} void TextInput::focus() { m_input->onClickTrackNode(true);