[expression_editor] Insert text char by char, using CharLayout.

Change-Id: Id5b146bf875c1cf1d9ac949258d43a5ed415a334
This commit is contained in:
Léa Saviot
2017-12-19 15:36:47 +01:00
parent 1c54da21c4
commit b3598e1713
4 changed files with 22 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
#include "controller.h"
#include <poincare/src/layout/char_layout.h> //TODO move from there.
namespace ExpressionEditor {
@@ -34,7 +35,8 @@ bool Controller::handleEvent(Ion::Events::Event event) {
{
returnValue = true;
}
else if (event.hasText() && m_expressionLayout->insertLayoutForTextAtCursor(event.text(), &m_cursor)) {
else if (event.hasText()) {
insertTextAtCursor(event.text());
returnValue = true;
m_expressionLayout->invalidAllSizesAndPositions();
m_view.layoutSubviews();
@@ -43,4 +45,20 @@ bool Controller::handleEvent(Ion::Events::Event event) {
return returnValue;
}
void Controller::insertTextAtCursor(const char * text) {
int textLength = strlen(text);
if (textLength <= 0) {
return;
}
Poincare::CharLayout * newChild = nullptr;
for (int i = 0; i < textLength; i++) {
newChild = new Poincare::CharLayout(text[i]);
m_cursor.pointedExpressionLayout()->addBrother(&m_cursor, newChild);
}
assert(newChild != nullptr);
m_cursor.setPointedExpressionLayout(newChild);
m_cursor.setPosition(Poincare::ExpressionLayoutCursor::Position::Right);
m_cursor.setPositionInside(0);
}
}