Files
Upsilon/apps/calculation/text_field.cpp
Émilie Feral f1516e57dc [apps/calculation] Insert ans when starting expression with -, ^, *, +,
/

Change-Id: Ifffeff85dbdaa902f25d0f4c615f252b5cd0d96c
2017-05-23 15:15:44 +02:00

37 lines
1.0 KiB
C++

#include "text_field.h"
namespace Calculation {
TextField::TextField(Responder * parentResponder, char * textBuffer, size_t textBufferSize, TextFieldDelegate * delegate) :
::TextField(parentResponder, textBuffer, textBuffer, textBufferSize, delegate, false)
{
setEditing(true);
}
bool TextField::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Back) {
return false;
}
if (event == Ion::Events::Ans) {
insertTextAtLocation("ans", cursorLocation());
setCursorLocation(cursorLocation() + strlen("ans"));
return true;
}
if (textLength() == 0 &&
(event == Ion::Events::Multiplication ||
event == Ion::Events::Plus ||
event == Ion::Events::Minus ||
event == Ion::Events::Power ||
event == Ion::Events::Division)) {
if (!isEditing()) {
setEditing(true);
setText("");
}
insertTextAtLocation("ans", cursorLocation());
setCursorLocation(cursorLocation() + strlen("ans"));
}
return(::TextField::handleEvent(event));
}
}