From fe4dbd96ed5c5d3bf011aa15cfddbdfb1f5a9419 Mon Sep 17 00:00:00 2001
From: HJfod <60038575+HJfod@users.noreply.github.com>
Date: Tue, 27 Feb 2024 23:32:37 +0200
Subject: [PATCH] add left alignment option to TextInput

---
 loader/include/Geode/ui/TextInput.hpp |  9 +++++++++
 loader/src/ui/nodes/TextInput.cpp     | 18 +++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/loader/include/Geode/ui/TextInput.hpp b/loader/include/Geode/ui/TextInput.hpp
index aae8dc1d..2090432b 100644
--- a/loader/include/Geode/ui/TextInput.hpp
+++ b/loader/include/Geode/ui/TextInput.hpp
@@ -28,6 +28,11 @@ namespace geode {
 
     GEODE_DLL const char* getCommonFilterAllowedChars(CommonFilter filter);
 
+    enum class TextInputAlign {
+        Center,
+        Left,
+    };
+
     /**
      * A single-line text input node
      */
@@ -103,6 +108,10 @@ namespace geode {
          * Enable/disable the input
          */
         void setEnabled(bool enabled);
+        /**
+         * Align the button's content to the left. If false, aligns to the center
+         */
+        void setTextAlign(TextInputAlign align);
 
         /**
          * Hides the background of this input. Shorthand for 
diff --git a/loader/src/ui/nodes/TextInput.cpp b/loader/src/ui/nodes/TextInput.cpp
index dbd56b4b..df307581 100644
--- a/loader/src/ui/nodes/TextInput.cpp
+++ b/loader/src/ui/nodes/TextInput.cpp
@@ -71,7 +71,7 @@ bool TextInput::init(float width, std::string const& placeholder, std::string co
 
     m_input = CCTextInputNode::create(width, HEIGHT, placeholder.c_str(), 24, font.c_str());
     m_input->setLabelPlaceholderColor({ 150, 150, 150 });
-    m_input->setLabelPlaceholderScale(.6f);
+    m_input->setLabelPlaceholderScale(.5f);
     m_input->setMaxLabelScale(.6f);
     m_input->setUserObject("fix-text-input", CCBool::create(true));
     this->addChildAtPosition(m_input, cocos2d::Anchor::Center);
@@ -133,6 +133,22 @@ void TextInput::setEnabled(bool enabled) {
     m_input->setTouchEnabled(enabled);
     m_input->m_placeholderLabel->setOpacity(enabled ? 255 : 150);
 }
+void TextInput::setTextAlign(TextInputAlign align) {
+    switch (align) {
+        default:
+        case TextInputAlign::Center: {
+            m_input->m_textField->setAnchorPoint({ .5f, .5f });
+            m_input->m_placeholderLabel->setAnchorPoint({ .5f, .5f });
+            m_input->updateAnchoredPosition(Anchor::Center);
+        } break;
+
+        case TextInputAlign::Left: {
+            m_input->m_textField->setAnchorPoint({ .0f, .5f });
+            m_input->m_placeholderLabel->setAnchorPoint({ .0f, .5f });
+            m_input->updateAnchoredPosition(Anchor::Left, ccp(5, 0));
+        } break;
+    }
+}
 
 void TextInput::hideBG() {
     m_bgSprite->setVisible(false);