mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/shared] Factorize go to parameter controllers in parent class
(used in regression, graph, sequence) Change-Id: I5e54bca17f9de7b21aeb705ea87818b064662904
This commit is contained in:
44
apps/shared/function_go_to_parameter_controller.cpp
Normal file
44
apps/shared/function_go_to_parameter_controller.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "function_go_to_parameter_controller.h"
|
||||
#include "text_field_delegate_app.h"
|
||||
#include <assert.h>
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
namespace Shared {
|
||||
|
||||
FunctionGoToParameterController::FunctionGoToParameterController(Responder * parentResponder, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, I18n::Message symbol) :
|
||||
GoToParameterController(parentResponder, graphRange, cursor, symbol),
|
||||
m_function(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
const char * FunctionGoToParameterController::title() {
|
||||
return I18n::translate(I18n::Message::Goto);
|
||||
}
|
||||
|
||||
float FunctionGoToParameterController::parameterAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return m_cursor->x();
|
||||
}
|
||||
|
||||
bool FunctionGoToParameterController::setParameterAtIndex(int parameterIndex, float f) {
|
||||
assert(parameterIndex == 0);
|
||||
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
||||
float y = m_function->evaluateAtAbscissa(f, myApp->localContext());
|
||||
if (fabsf(f) > k_maxDisplayableFloat || fabsf(y) > k_maxDisplayableFloat) {
|
||||
app()->displayWarning(I18n::Message::ForbiddenValue);
|
||||
return false;
|
||||
}
|
||||
if (isnan(y) || isinf(y)) {
|
||||
app()->displayWarning(I18n::Message::ValueNotReachedByFunction);
|
||||
return false;
|
||||
}
|
||||
m_cursor->moveTo(f, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FunctionGoToParameterController::setFunction(Function * function) {
|
||||
m_function = function;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user