diff --git a/modules/client_entergame/characterlist.otui b/modules/client_entergame/characterlist.otui index 35007fff..237e8e5e 100644 --- a/modules/client_entergame/characterlist.otui +++ b/modules/client_entergame/characterlist.otui @@ -41,6 +41,7 @@ MainWindow anchors.right: parent.right anchors.bottom: separator.top margin-bottom: 5 + text-auto-resize: true HorizontalSeparator id: separator diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index 32c0cb3d..220d2741 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -37,6 +37,7 @@ UITextEdit::UITextEdit() m_alwaysActive = false; m_shiftNavigation = false; m_multiline = false; + m_maxLength = 0; blinkCursor(); } @@ -281,6 +282,9 @@ void UITextEdit::appendText(std::string text) boost::replace_all(text, "\r", " "); if(text.length() > 0) { + // only add text if textedit can add it + if(m_maxLength > 0 && m_text.length() + text.length() > m_maxLength) + return; // only ignore text append if it contains invalid characters if(m_validCharacters.size() > 0) { @@ -306,6 +310,9 @@ void UITextEdit::appendCharacter(char c) return; if(m_cursorPos >= 0) { + if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength) + return; + if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos) return; @@ -416,6 +423,8 @@ void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s setShiftNavigation(node->value()); else if(node->tag() == "multiline") setMultiline(node->value()); + else if(node->tag() == "max-length") + setMaxLength(node->value()); } } diff --git a/src/framework/ui/uitextedit.h b/src/framework/ui/uitextedit.h index 413d0a76..04676ddf 100644 --- a/src/framework/ui/uitextedit.h +++ b/src/framework/ui/uitextedit.h @@ -44,6 +44,7 @@ public: void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; } void setShiftNavigation(bool enable) { m_shiftNavigation = enable; } void setMultiline(bool enable) { m_multiline = enable; } + void setMaxLength(uint maxLength) { m_maxLength = maxLength; } void moveCursor(bool right); void appendText(std::string text); @@ -84,6 +85,7 @@ private: bool m_shiftNavigation; bool m_multiline; std::string m_validCharacters; + uint m_maxLength; std::vector m_glyphsCoords; std::vector m_glyphsTexCoords;