Files
Upsilon/apps/expression_text_field_delegate.cpp
Émilie Feral e56cf21a69 [apps] handle XNT event in the delegate text field
Change-Id: I077309e59e859006f79a097d16ad3db6a598fffb
2016-11-18 10:00:43 +01:00

43 lines
1.7 KiB
C++

#include "expression_text_field_delegate.h"
#include "apps_container.h"
#include <math.h>
const char * ExpressionTextFieldDelegate::XNT() {
return "x";
}
bool ExpressionTextFieldDelegate::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
if (event == Ion::Events::OK && Expression::parse(textField->text()) == nullptr) {
if (textField->textLength() == 0) {
return true;
}
textField->app()->displayWarning("Attention a la syntaxe jeune padawan");
return true;
}
if (event == Ion::Events::OK &&
isnan(Expression::parse(textField->text())->approximate(*evaluateContext()))) {
textField->app()->displayWarning("Relis ton cours de maths, veux tu?");
return true;
}
if (event == Ion::Events::Toolbox) {
AppsContainer * appsContainer = (AppsContainer *)textField->app()->container();
ToolboxController * toolboxController = appsContainer->toolboxController();
toolboxController->setTextFieldCaller(textField);
textField->app()->displayModalViewController(toolboxController, 0.f, 0.f, 50, 50, 0, 50);
return true;
}
if (event == Ion::Events::Var) {
AppsContainer * appsContainer = (AppsContainer *)textField->app()->container();
VariableBoxController * variableBoxController = appsContainer->variableBoxController();
variableBoxController->setTextFieldCaller(textField);
textField->app()->displayModalViewController(variableBoxController, 0.f, 0.f, 50, 50, 0, 50);
return true;
}
if (event == Ion::Events::XNT) {
textField->insertTextAtLocation(XNT(), textField->cursorLocation());
textField->setCursorLocation(textField->cursorLocation()+strlen(XNT()));
return true;
}
return false;
}