mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 17:20:53 +01:00
[apps] Enable to specialize the sum layout in Sum Graph Controller
This commit is contained in:
committed by
EmilieNumworks
parent
e5032b8c30
commit
ac6c8379ed
@@ -1,5 +1,6 @@
|
||||
#include "integral_graph_controller.h"
|
||||
#include "../../shared/text_field_delegate.h"
|
||||
#include "../../../poincare/src/layout/string_layout.h"
|
||||
#include "../app.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -35,4 +36,10 @@ double IntegralGraphController::cursorNextStep(double x, int direction) {
|
||||
return (direction > 0 ? x + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : x - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit);
|
||||
}
|
||||
|
||||
ExpressionLayout * IntegralGraphController::createFunctionLayout(const char * functionName) {
|
||||
char buffer[7] = "0(x)dx";
|
||||
buffer[0] = functionName[0];
|
||||
return new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
private:
|
||||
I18n::Message legendMessageAtStep(Step step) override;
|
||||
double cursorNextStep(double position, int direction) override;
|
||||
Poincare::ExpressionLayout * createFunctionLayout(const char * functionName) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "term_sum_controller.h"
|
||||
#include "../../shared/text_field_delegate.h"
|
||||
#include "../../../poincare/src/layout/baseline_relative_layout.h"
|
||||
#include "../../../poincare/src/layout/string_layout.h"
|
||||
#include "../app.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -43,4 +45,8 @@ double TermSumController::cursorNextStep(double x, int direction) {
|
||||
return std::round(m_cursor->x()+delta);
|
||||
}
|
||||
|
||||
ExpressionLayout * TermSumController::createFunctionLayout(const char * functionName) {
|
||||
return new BaselineRelativeLayout(new StringLayout(functionName, 1, KDText::FontSize::Small), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ private:
|
||||
bool moveCursorHorizontallyToPosition(double position) override;
|
||||
I18n::Message legendMessageAtStep(Step step) override;
|
||||
double cursorNextStep(double position, int direction) override;
|
||||
Poincare::ExpressionLayout * createFunctionLayout(const char * functionName) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "sum_graph_controller.h"
|
||||
#include "../apps_container.h"
|
||||
#include "../../poincare/src/layout/baseline_relative_layout.h"
|
||||
#include "../../poincare/src/layout/condensed_sum_layout.h"
|
||||
#include "../../poincare/src/layout/string_layout.h"
|
||||
#include "../../poincare/src/layout/horizontal_layout.h"
|
||||
@@ -194,7 +193,7 @@ bool SumGraphController::handleEnter() {
|
||||
m_step = (Step)((int)m_step+1);
|
||||
TextFieldDelegateApp * myApp = static_cast<TextFieldDelegateApp *>(app());
|
||||
double sum = m_function->sumBetweenBounds(m_startSum, m_endSum, myApp->localContext());
|
||||
m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, sum, m_function->name());
|
||||
m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, sum, createFunctionLayout(m_function->name()));
|
||||
m_legendView.setLegendMessage(I18n::Message::Default, m_step);
|
||||
m_graphView->setAreaHighlightColor(true);
|
||||
m_graphView->setCursorView(nullptr);
|
||||
@@ -240,7 +239,8 @@ void SumGraphController::LegendView::setEditableZone(double d) {
|
||||
m_editableZone.setText(buffer);
|
||||
}
|
||||
|
||||
void SumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, const char * sequenceName) {
|
||||
void SumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, ExpressionLayout * functionLayout) {
|
||||
assert(step == Step::Result || functionLayout == nullptr);
|
||||
if (m_sumLayout) {
|
||||
delete m_sumLayout;
|
||||
m_sumLayout = nullptr;
|
||||
@@ -263,10 +263,10 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl
|
||||
ExpressionLayout * childrenLayouts[3];
|
||||
strlcpy(buffer, "= ", 3);
|
||||
Complex<double>::convertFloatToText(result, buffer+2, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
|
||||
childrenLayouts[2] = new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small);
|
||||
childrenLayouts[1] = new BaselineRelativeLayout(new StringLayout(sequenceName, 1, KDText::FontSize::Small), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
|
||||
childrenLayouts[0] = m_sumLayout;
|
||||
m_sumLayout = new HorizontalLayout(childrenLayouts, 3);
|
||||
childrenLayouts[2] = new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small);
|
||||
childrenLayouts[1] = functionLayout;
|
||||
childrenLayouts[0] = m_sumLayout;
|
||||
m_sumLayout = new HorizontalLayout(childrenLayouts, 3);
|
||||
}
|
||||
m_sum.setExpression(m_sumLayout);
|
||||
if (step == Step::Result) {
|
||||
|
||||
@@ -41,6 +41,7 @@ private:
|
||||
constexpr static float k_cursorLeftMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth
|
||||
virtual I18n::Message legendMessageAtStep(Step step) = 0;
|
||||
virtual double cursorNextStep(double position, int direction) = 0;
|
||||
virtual Poincare::ExpressionLayout * createFunctionLayout(const char * functionName) = 0;
|
||||
Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; }
|
||||
Shared::CurveView * curveView() override { return m_graphView; }
|
||||
TextFieldDelegateApp * textFieldDelegateApp() override {
|
||||
@@ -60,7 +61,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, const char * sequenceName = nullptr);
|
||||
void setSumSymbol(Step step, double start = NAN, double end = NAN, double result = NAN, Poincare::ExpressionLayout * sequenceName = nullptr);
|
||||
private:
|
||||
constexpr static KDCoordinate k_legendHeight = 35;
|
||||
constexpr static KDCoordinate k_editableZoneWidth = 4*KDText::charSize(KDText::FontSize::Small).width();
|
||||
|
||||
Reference in New Issue
Block a user