mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/graph] Fix cursor navigation
This commit is contained in:
@@ -22,6 +22,7 @@ app_objs += $(addprefix apps/graph/,\
|
||||
graph/storage_calculation_parameter_controller.o\
|
||||
graph/storage_curve_parameter_controller.o\
|
||||
graph/storage_graph_controller.o\
|
||||
graph/storage_graph_controller_helper.o\
|
||||
graph/storage_graph_view.o\
|
||||
graph/storage_intersection_graph_controller.o\
|
||||
graph/storage_tangent_graph_controller.o\
|
||||
|
||||
@@ -75,7 +75,7 @@ void StorageGraphController::reloadBannerView() {
|
||||
bool StorageGraphController::moveCursorHorizontally(int direction) {
|
||||
StorageCartesianFunction f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor());
|
||||
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
|
||||
return true; //TODO privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, &f, myApp, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
|
||||
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, &f, myApp, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
|
||||
}
|
||||
|
||||
InteractiveCurveViewRange * StorageGraphController::interactiveCurveViewRange() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef GRAPH_STORAGE_GRAPH_CONTROLLER_H
|
||||
#define GRAPH_STORAGE_GRAPH_CONTROLLER_H
|
||||
|
||||
#include "graph_controller_helper.h"
|
||||
#include "banner_view.h"
|
||||
#include "storage_curve_parameter_controller.h"
|
||||
#include "storage_graph_controller_helper.h"
|
||||
#include "storage_graph_view.h"
|
||||
#include "../../shared/storage_function_graph_controller.h"
|
||||
#include "../../shared/curve_view_cursor.h"
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class StorageGraphController : public Shared::StorageFunctionGraphController<StorageCartesianFunction>, public GraphControllerHelper {
|
||||
class StorageGraphController : public Shared::StorageFunctionGraphController<StorageCartesianFunction>, public StorageGraphControllerHelper {
|
||||
public:
|
||||
StorageGraphController(Responder * parentResponder, StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header);
|
||||
I18n::Message emptyMessage() override;
|
||||
|
||||
35
apps/graph/graph/storage_graph_controller_helper.cpp
Normal file
35
apps/graph/graph/storage_graph_controller_helper.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "storage_graph_controller_helper.h"
|
||||
#include "../../constant.h"
|
||||
#include "../../shared/poincare_helpers.h"
|
||||
|
||||
using namespace Shared;
|
||||
using namespace Poincare;
|
||||
|
||||
namespace Graph {
|
||||
|
||||
bool StorageGraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, StorageCartesianFunction * function, Shared::TextFieldDelegateApp * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio) {
|
||||
double xCursorPosition = cursor->x();
|
||||
double x = direction > 0 ? xCursorPosition + range->xGridUnit()/numberOfStepsInGradUnit : xCursorPosition - range->xGridUnit()/numberOfStepsInGradUnit;
|
||||
double y = function->evaluateAtAbscissa(x, app->localContext());
|
||||
cursor->moveTo(x, y);
|
||||
range->panToMakePointVisible(x, y, cursorTopMarginRatio, cursorRightMarginRatio, cursorBottomMarginRatio, cursorLeftMarginRatio);
|
||||
return true;
|
||||
}
|
||||
|
||||
void StorageGraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, StorageCartesianFunction * function, TextFieldDelegateApp * app) {
|
||||
char buffer[StorageFunctionBannerDelegate<StorageCartesianFunction>::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
const char * space = " ";
|
||||
int spaceLength = strlen(space);
|
||||
const char * legend = "00(x)=";
|
||||
int legendLength = strlen(legend);
|
||||
int numberOfChar = strlcpy(buffer, legend, legendLength+1);
|
||||
buffer[0] = function->name()[0];
|
||||
buffer[1] = '\'';
|
||||
double y = function->approximateDerivative(cursor->x(), app->localContext());
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits);
|
||||
strlcpy(buffer+numberOfChar, space, spaceLength+1);
|
||||
buffer[k_maxDigitLegendLength+6] = 0;
|
||||
bannerView()->setLegendAtIndex(buffer, 2);
|
||||
}
|
||||
|
||||
}
|
||||
21
apps/graph/graph/storage_graph_controller_helper.h
Normal file
21
apps/graph/graph/storage_graph_controller_helper.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef GRAPH_STORAGE_GRAPH_CONTROLLER_HELPER_H
|
||||
#define GRAPH_STORAGE_GRAPH_CONTROLLER_HELPER_H
|
||||
|
||||
#include "../../shared/storage_function_banner_delegate.h"
|
||||
#include "../../shared/text_field_delegate_app.h"
|
||||
#include "../../shared/interactive_curve_view_range.h"
|
||||
#include "../storage_cartesian_function.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class StorageGraphControllerHelper {
|
||||
protected:
|
||||
constexpr static int k_maxDigitLegendLength = 10;
|
||||
bool privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, StorageCartesianFunction * function, Shared::TextFieldDelegateApp * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio);
|
||||
void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, StorageCartesianFunction * function, Shared::TextFieldDelegateApp * app);
|
||||
virtual Shared::BannerView * bannerView() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user