This commit is contained in:
SpaghettDev 2025-04-02 20:06:09 -04:00 committed by GitHub
commit f6f79fc8fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions
loader
include/Geode/ui
src/ui/nodes

View file

@ -43,6 +43,7 @@ namespace geode {
CCTextInputNode* m_input;
std::function<void(std::string const&)> 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<void(std::string const&)> 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)

View file

@ -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<void(std::string const&)> 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);