SparrowInput/textbuffer.cpp

45 lines
558 B
C++

#include "textbuffer.h"
TextBuffer::TextBuffer()
{
resetBuffer();
}
void TextBuffer::resetBuffer()
{
buffer.clear();
cursor = 0;
}
int TextBuffer::getCursorPosition() const
{
return cursor;
}
void TextBuffer::setCursorPosition(int pos)
{
cursor = pos;
}
void TextBuffer::moveCursorLeft()
{
if (cursor > 0) cursor--;
}
void TextBuffer::moveCursorRight()
{
if (cursor < buffer.size()) cursor++;
}
std::string TextBuffer::getText() const
{
return buffer;
}
void TextBuffer::insertText(char c)
{
buffer.insert(cursor,&c);
moveCursorRight();
}