Browse Source

Fix text edits wrapping

Eduardo Bart 6 years ago
parent
commit
cf77c2baf3

+ 5
- 4
modules/game_textwindow/textwindow.lua View File

@@ -26,7 +26,7 @@ end
26 26
 function onGameEditText(id, itemId, maxLength, text, writter, time)
27 27
   local textWindow = g_ui.createWidget('TextWindow', rootWidget)
28 28
 
29
-  local writeable = (maxLength ~= #text) and maxLength > 0
29
+  local writeable = #text < maxLength and maxLength > 0
30 30
   local textItem = textWindow:getChildById('textItem')
31 31
   local description = textWindow:getChildById('description')
32 32
   local textEdit = textWindow:getChildById('text')
@@ -38,7 +38,9 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
38 38
   textItem:setItemId(itemId)
39 39
   textEdit:setMaxLength(maxLength)
40 40
   textEdit:setText(text)
41
-  textEdit:setEnabled(writeable)
41
+  textEdit:setEditable(writeable)
42
+  textEdit:setCursorVisible(writeable)
43
+  textEdit:wrapText()
42 44
   
43 45
   local desc = ''
44 46
   if #writter > 0 then
@@ -63,7 +65,6 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
63 65
 
64 66
   if not writeable then
65 67
     textWindow:setText(tr('Show Text'))
66
-    textEdit:wrapText()
67 68
     cancelButton:hide()
68 69
     cancelButton:setWidth(0)
69 70
     okButton:setMarginRight(0)
@@ -105,7 +106,7 @@ function onGameEditList(id, doorId, text)
105 106
 
106 107
   textEdit:setMaxLength(8192)
107 108
   textEdit:setText(text)
108
-  textEdit:setEnabled(true)
109
+  textEdit:setEditable(true)
109 110
   description:setText(tr('Enter one name per line.'))
110 111
   textWindow:setText(tr('Edit List'))
111 112
 

+ 1
- 0
otclientrc.lua View File

@@ -2,3 +2,4 @@
2 2
 -- you can place any custom user code here
3 3
 
4 4
 print 'Startup done :]'
5
+

+ 5
- 4
src/framework/ui/uitextedit.cpp View File

@@ -368,7 +368,7 @@ void UITextEdit::removeCharacter(bool right)
368 368
 
369 369
 void UITextEdit::wrapText()
370 370
 {
371
-    m_text = m_font->wrapText(m_text, getPaddingRect().width());
371
+    setText(m_font->wrapText(m_text, getPaddingRect().width()));
372 372
 }
373 373
 
374 374
 void UITextEdit::moveCursor(bool right)
@@ -427,7 +427,8 @@ void UITextEdit::onHoverChange(bool hovered)
427 427
 
428 428
 void UITextEdit::onTextChange(const std::string& text, const std::string& oldText)
429 429
 {
430
-    m_cursorPos = text.length();
430
+    if(m_cursorPos > (int)text.length())
431
+        m_cursorPos = text.length();
431 432
     blinkCursor();
432 433
     update(true);
433 434
     UIWidget::onTextChange(text, oldText);
@@ -435,7 +436,7 @@ void UITextEdit::onTextChange(const std::string& text, const std::string& oldTex
435 436
 
436 437
 void UITextEdit::onFontChange(const std::string& font)
437 438
 {
438
-    update();
439
+    update(true);
439 440
     UIWidget::onFontChange(font);
440 441
 }
441 442
 
@@ -464,7 +465,7 @@ void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s
464 465
 
465 466
 void UITextEdit::onGeometryChange(const Rect& oldRect, const Rect& newRect)
466 467
 {
467
-    update();
468
+    update(true);
468 469
     UIWidget::onGeometryChange(oldRect, newRect);
469 470
 }
470 471
 

+ 1
- 1
src/framework/ui/uitextedit.h View File

@@ -38,7 +38,7 @@ private:
38 38
 
39 39
 public:
40 40
     void setCursorPos(int pos);
41
-    void setCursorVisible(bool enable) { m_cursorVisible = false; }
41
+    void setCursorVisible(bool enable) { m_cursorVisible = enable; }
42 42
     void setTextHidden(bool hidden);
43 43
     void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
44 44
     void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }

Loading…
Cancel
Save