Browse Source

Cursor after newline character appears on beginning of next line.
DirectEntry.updateNumLines updates text geom.
DirectEntry API less inadequate.

Closes #257

Sebastian Hoffmann 7 years ago
parent
commit
78377ca10c
3 changed files with 11 additions and 0 deletions
  1. 6 0
      direct/src/gui/DirectEntry.py
  2. 1 0
      panda/src/pgui/pgEntry.I
  3. 4 0
      panda/src/pgui/pgEntry.cxx

+ 6 - 0
direct/src/gui/DirectEntry.py

@@ -302,12 +302,18 @@ class DirectEntry(DirectFrame):
             else:
                 return self.guiItem.getText()
 
+    def getCursorPosition(self):
+        return self.guiItem.getCursorPosition()
+
     def setCursorPosition(self, pos):
         if (pos < 0):
             self.guiItem.setCursorPosition(self.guiItem.getNumCharacters() + pos)
         else:
             self.guiItem.setCursorPosition(pos)
 
+    def getNumCharacters(self):
+        return self.guiItem.getNumCharacters()
+
     def enterText(self, text):
         """ sets the entry's text, and moves the cursor to the end """
         self.set(text)

+ 1 - 0
panda/src/pgui/pgEntry.I

@@ -208,6 +208,7 @@ set_num_lines(int num_lines) {
   nassertv(num_lines >= 1);
   _num_lines = num_lines;
   _text_geom_stale = true;
+  update_text();
 }
 
 /**

+ 4 - 0
panda/src/pgui/pgEntry.cxx

@@ -864,6 +864,10 @@ update_cursor() {
       ypos = _obscure_text.get_ypos(row, column);
     } else {
       _text.calc_r_c(row, column, _cursor_position);
+      if (_cursor_position > 0 && _text.get_character(_cursor_position - 1) == '\n') {
+        row += 1;
+        column = 0;
+      }
       xpos = _text.get_xpos(row, column);
       ypos = _text.get_ypos(row, column);
     }