textedit maxlength, fix charlist status height
This commit is contained in:
parent
9ca09d9849
commit
2f3c83e858
|
@ -41,6 +41,7 @@ MainWindow
|
|||
anchors.right: parent.right
|
||||
anchors.bottom: separator.top
|
||||
margin-bottom: 5
|
||||
text-auto-resize: true
|
||||
|
||||
HorizontalSeparator
|
||||
id: separator
|
||||
|
|
|
@ -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<bool>());
|
||||
else if(node->tag() == "multiline")
|
||||
setMultiline(node->value<bool>());
|
||||
else if(node->tag() == "max-length")
|
||||
setMaxLength(node->value<int>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Rect> m_glyphsCoords;
|
||||
std::vector<Rect> m_glyphsTexCoords;
|
||||
|
|
Loading…
Reference in New Issue