[apps/shared] Implement SumGraphController::reloadBannerView

This commit is contained in:
Ruben Dashyan
2019-03-22 18:18:41 +01:00
committed by Émilie Feral
parent e47ab69e53
commit a400a5024b
3 changed files with 38 additions and 35 deletions

View File

@@ -22,7 +22,7 @@ public:
protected:
virtual bool handleZoom(Ion::Events::Event event);
virtual bool handleLeftRightEvent(Ion::Events::Event event);
virtual void reloadBannerView() {};
virtual void reloadBannerView() = 0;
/* the result of moveCursorVertically/Horizontally means:
* false -> the cursor cannot move in this direction
* true -> the cursor moved */

View File

@@ -40,9 +40,7 @@ void SumGraphController::viewWillAppear() {
m_startSum = m_cursor->x();
m_endSum = NAN;
m_step = Step::FirstParameter;
m_legendView.setLegendMessage(legendMessageAtStep(Step::FirstParameter), Step::FirstParameter);
m_legendView.setEditableZone(m_startSum);
m_legendView.setSumSymbol(m_step);
reloadBannerView();
}
@@ -53,21 +51,16 @@ void SumGraphController::didEnterResponderChain(Responder * previousFirstRespond
bool SumGraphController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Back && m_step != Step::FirstParameter) {
m_step = (Step)((int)m_step-1);
m_legendView.setLegendMessage(legendMessageAtStep(m_step), m_step);
if (m_step == Step::SecondParameter) {
app()->setFirstResponder(m_legendView.textField());
m_graphView->setAreaHighlightColor(false);
m_graphView->setCursorView(&m_cursorView);
m_legendView.setEditableZone(m_endSum);
m_legendView.setSumSymbol(m_step, m_startSum);
}
if (m_step == Step::FirstParameter) {
m_graphView->setAreaHighlight(NAN,NAN);
moveCursorHorizontallyToPosition(m_startSum);
m_legendView.setLegendMessage(legendMessageAtStep(m_step), m_step);
m_legendView.setEditableZone(m_startSum);
m_legendView.setSumSymbol(m_step);
}
reloadBannerView();
return true;
}
return SimpleInteractiveCurveViewController::handleEvent(event);
@@ -141,30 +134,39 @@ bool SumGraphController::handleEnter() {
if (m_step == Step::Result) {
StackViewController * stack = (StackViewController *)parentResponder();
stack->pop();
return true;
} else {
if (m_step == Step::FirstParameter) {
m_graphView->setAreaHighlight(m_startSum, m_startSum);
m_endSum = m_startSum;
} else {
m_graphView->setAreaHighlightColor(true);
m_graphView->setCursorView(nullptr);
app()->setFirstResponder(this);
}
m_step = (Step)((int)m_step+1);
reloadBannerView();
}
if (m_step == Step::FirstParameter) {
m_step = Step::SecondParameter;
m_graphView->setAreaHighlight(m_startSum,m_startSum);
m_endSum = m_cursor->x();
m_legendView.setEditableZone(m_endSum);
m_legendView.setSumSymbol(m_step, m_startSum);
m_legendView.setLegendMessage(legendMessageAtStep(m_step), m_step);
return true;
}
m_step = (Step)((int)m_step+1);
FunctionApp * myApp = static_cast<FunctionApp *>(app());
assert(!m_record.isNull());
ExpiringPointer<Function> function = myApp->functionStore()->modelForRecord(m_record);
double sum = function->sumBetweenBounds(m_startSum, m_endSum, myApp->localContext());
m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, sum, createFunctionLayout(function));
m_legendView.setLegendMessage(I18n::Message::Default, m_step);
m_graphView->setAreaHighlightColor(true);
m_graphView->setCursorView(nullptr);
myApp->setFirstResponder(this);
return true;
}
void SumGraphController::reloadBannerView() {
m_legendView.setLegendMessage(legendMessageAtStep(m_step), m_step);
double result;
Poincare::Layout functionLayout;
if (m_step == Step::Result) {
FunctionApp * myApp = static_cast<FunctionApp *>(app());
assert(!m_record.isNull());
ExpiringPointer<Function> function = myApp->functionStore()->modelForRecord(m_record);
result = function->sumBetweenBounds(m_startSum, m_endSum, myApp->localContext());
functionLayout = createFunctionLayout(function);
} else {
m_legendView.setEditableZone(m_cursor->x());
result = NAN;
functionLayout = Poincare::Layout();
}
m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, result, functionLayout);
}
/* Legend View */
SumGraphController::LegendView::LegendView(SumGraphController * controller, InputEventHandlerDelegate * inputEventHandlerDelegate, CodePoint sumSymbol) :

View File

@@ -37,15 +37,16 @@ private:
constexpr static float k_cursorTopMarginRatio = 0.06f; // (cursorHeight/2)/graphViewHeight
constexpr static float k_cursorBottomMarginRatio = 0.28f; // (cursorHeight/2+bannerHeigh)/graphViewHeight
bool handleLeftRightEvent(Ion::Events::Event event) override;
virtual I18n::Message legendMessageAtStep(Step step) = 0;
virtual double cursorNextStep(double position, int direction) = 0;
virtual Poincare::Layout createFunctionLayout(ExpiringPointer<Function> function) = 0;
bool handleEnter() override;
void reloadBannerView() override;
Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; }
Shared::CurveView * curveView() override { return m_graphView; }
TextFieldDelegateApp * textFieldDelegateApp() override {
return static_cast<TextFieldDelegateApp *>(app());
}
bool handleEnter() override;
virtual I18n::Message legendMessageAtStep(Step step) = 0;
virtual double cursorNextStep(double position, int direction) = 0;
virtual Poincare::Layout createFunctionLayout(ExpiringPointer<Function> function) = 0;
class LegendView : public View {
public:
LegendView(SumGraphController * controller, InputEventHandlerDelegate * inputEventHandlerDelegate, CodePoint sumSymbol);
@@ -58,7 +59,7 @@ private:
void drawRect(KDContext * ctx, KDRect rect) const override;
void setLegendMessage(I18n::Message message, Step step);
void setEditableZone(double d);
void setSumSymbol(Step step, double start = NAN, double end = NAN, double result = NAN, Poincare::Layout sequenceName = Poincare::Layout());
void setSumSymbol(Step step, double start, double end, double result, Poincare::Layout functionLayout);
private:
constexpr static KDCoordinate k_legendHeight = 35;
constexpr static const KDFont * k_font = KDFont::SmallFont;