From cf77c2baf35557ef56a5fe86020f79d18adc19ff Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 17 Jan 2013 09:34:13 -0200 Subject: [PATCH] Fix text edits wrapping --- modules/game_textwindow/textwindow.lua | 9 +++++---- otclientrc.lua | 1 + src/framework/ui/uitextedit.cpp | 9 +++++---- src/framework/ui/uitextedit.h | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/game_textwindow/textwindow.lua b/modules/game_textwindow/textwindow.lua index cc236fd2..db252937 100644 --- a/modules/game_textwindow/textwindow.lua +++ b/modules/game_textwindow/textwindow.lua @@ -26,7 +26,7 @@ end function onGameEditText(id, itemId, maxLength, text, writter, time) local textWindow = g_ui.createWidget('TextWindow', rootWidget) - local writeable = (maxLength ~= #text) and maxLength > 0 + local writeable = #text < maxLength and maxLength > 0 local textItem = textWindow:getChildById('textItem') local description = textWindow:getChildById('description') local textEdit = textWindow:getChildById('text') @@ -38,7 +38,9 @@ function onGameEditText(id, itemId, maxLength, text, writter, time) textItem:setItemId(itemId) textEdit:setMaxLength(maxLength) textEdit:setText(text) - textEdit:setEnabled(writeable) + textEdit:setEditable(writeable) + textEdit:setCursorVisible(writeable) + textEdit:wrapText() local desc = '' if #writter > 0 then @@ -63,7 +65,6 @@ function onGameEditText(id, itemId, maxLength, text, writter, time) if not writeable then textWindow:setText(tr('Show Text')) - textEdit:wrapText() cancelButton:hide() cancelButton:setWidth(0) okButton:setMarginRight(0) @@ -105,7 +106,7 @@ function onGameEditList(id, doorId, text) textEdit:setMaxLength(8192) textEdit:setText(text) - textEdit:setEnabled(true) + textEdit:setEditable(true) description:setText(tr('Enter one name per line.')) textWindow:setText(tr('Edit List')) diff --git a/otclientrc.lua b/otclientrc.lua index b8b0805b..b3a88ef7 100644 --- a/otclientrc.lua +++ b/otclientrc.lua @@ -2,3 +2,4 @@ -- you can place any custom user code here print 'Startup done :]' + diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index 3c43baef..5d43bcb5 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -368,7 +368,7 @@ void UITextEdit::removeCharacter(bool right) void UITextEdit::wrapText() { - m_text = m_font->wrapText(m_text, getPaddingRect().width()); + setText(m_font->wrapText(m_text, getPaddingRect().width())); } void UITextEdit::moveCursor(bool right) @@ -427,7 +427,8 @@ void UITextEdit::onHoverChange(bool hovered) void UITextEdit::onTextChange(const std::string& text, const std::string& oldText) { - m_cursorPos = text.length(); + if(m_cursorPos > (int)text.length()) + m_cursorPos = text.length(); blinkCursor(); update(true); UIWidget::onTextChange(text, oldText); @@ -435,7 +436,7 @@ void UITextEdit::onTextChange(const std::string& text, const std::string& oldTex void UITextEdit::onFontChange(const std::string& font) { - update(); + update(true); UIWidget::onFontChange(font); } @@ -464,7 +465,7 @@ void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s void UITextEdit::onGeometryChange(const Rect& oldRect, const Rect& newRect) { - update(); + update(true); UIWidget::onGeometryChange(oldRect, newRect); } diff --git a/src/framework/ui/uitextedit.h b/src/framework/ui/uitextedit.h index 01aa22d8..0ee5a2f3 100644 --- a/src/framework/ui/uitextedit.h +++ b/src/framework/ui/uitextedit.h @@ -38,7 +38,7 @@ private: public: void setCursorPos(int pos); - void setCursorVisible(bool enable) { m_cursorVisible = false; } + void setCursorVisible(bool enable) { m_cursorVisible = enable; } void setTextHidden(bool hidden); void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; } void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }