Cursor after newline character appears on beginning of next line.

DirectEntry.updateNumLines updates text geom.
DirectEntry API less inadequate.

Closes #257
This commit is contained in:
Sebastian Hoffmann 2018-02-25 15:41:26 +01:00 committed by rdb
parent 84915073e1
commit 78377ca10c
3 changed files with 11 additions and 0 deletions

View File

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

View File

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

View File

@ -864,6 +864,10 @@ update_cursor() {
ypos = _obscure_text.get_ypos(row, column); ypos = _obscure_text.get_ypos(row, column);
} else { } else {
_text.calc_r_c(row, column, _cursor_position); _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); xpos = _text.get_xpos(row, column);
ypos = _text.get_ypos(row, column); ypos = _text.get_ypos(row, column);
} }