void Text::setCaretPosition(int x, int y, Font* font) { if (mRows.empty()) return; setCaretRow(y / font->getHeight()); setCaretColumn(font->getStringIndexAt(mRows[mCaretRow], x)); }
void TextBox::setTextRow(int row, const std::string& text) { mTextRows[row] = text; if (mCaretRow == row) { setCaretColumn(mCaretColumn); } adjustSize(); }
void Text::setCaretRow(int row) { if (mRows.empty() || row < 0) mCaretRow = 0; else if (row >= (int)mRows.size()) mCaretRow = mRows.size() - 1; else mCaretRow = row; setCaretColumn(mCaretColumn); }
void TextBox::setCaretRow(int row) { mCaretRow = row; if (mCaretRow >= (int)mTextRows.size()) { mCaretRow = mTextRows.size() - 1; } if (mCaretRow < 0) { mCaretRow = 0; } setCaretColumn(mCaretColumn); }
void TextBox::setCaretRowColumn(int row, int column) { setCaretRow(row); setCaretColumn(column); }
void Text::remove(int numberOfCharacters) { if (mRows.empty() || numberOfCharacters == 0) return; // We should remove characters left of the caret position. if (numberOfCharacters < 0) { while (numberOfCharacters != 0) { // If the caret position is zero there is nothing // more to do. if (mCaretPosition == 0) break; // If we are at the end of the row // and the row is not the first row we // need to merge two rows. if (mCaretColumn == 0 && mCaretRow != 0) { mRows[mCaretRow - 1] += mRows[mCaretRow]; mRows.erase(mRows.begin() + mCaretRow); setCaretRow(mCaretRow - 1); setCaretColumn(getNumberOfCharacters(mCaretRow)); } else { mRows[mCaretRow].erase(mCaretColumn - 1, 1); setCaretPosition(mCaretPosition - 1); } numberOfCharacters++; } } // We should remove characters right of the caret position. else if (numberOfCharacters > 0) { while (numberOfCharacters != 0) { // If all rows have been removed there is nothing // more to do. if (mRows.empty()) break; // If we are at the end of row and the row // is not the last row we need to merge two // rows. if (mCaretColumn == mRows[mCaretRow].size() && mCaretRow < (mRows.size() - 1)) { mRows[mCaretRow] += mRows[mCaretRow + 1]; mRows.erase(mRows.begin() + mCaretRow + 1); } else { mRows[mCaretRow].erase(mCaretColumn, 1); } numberOfCharacters--; } } }