mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-24 03:39:56 -04:00
add left alignment option to TextInput
This commit is contained in:
parent
547c0474db
commit
fe4dbd96ed
2 changed files with 26 additions and 1 deletions
loader
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue