[apps/shared/sum_graph_controller] Factor constexpr

This commit is contained in:
Ruben Dashyan
2020-03-02 18:00:19 +01:00
committed by LeaNumworks
parent f0ef84b3bc
commit afb1d18d65
2 changed files with 8 additions and 11 deletions

View File

@@ -3,7 +3,6 @@
#include <poincare/empty_layout.h> #include <poincare/empty_layout.h>
#include <poincare/condensed_sum_layout.h> #include <poincare/condensed_sum_layout.h>
#include <poincare/layout_helper.h> #include <poincare/layout_helper.h>
#include <poincare/preferences.h>
#include "poincare_helpers.h" #include "poincare_helpers.h"
#include <assert.h> #include <assert.h>
@@ -178,10 +177,8 @@ void SumGraphController::LegendView::setLegendMessage(I18n::Message message, Ste
} }
void SumGraphController::LegendView::setEditableZone(double d) { void SumGraphController::LegendView::setEditableZone(double d) {
constexpr int precision = Preferences::MediumNumberOfSignificantDigits; char buffer[k_valuesBufferSize];
constexpr int bufferSize = PrintFloat::charSizeForFloatsWithPrecision(precision); PoincareHelpers::ConvertFloatToTextWithDisplayMode<double>(d, buffer, k_valuesBufferSize, k_valuesPrecision, Preferences::PrintFloatMode::Decimal);
char buffer[bufferSize];
PoincareHelpers::ConvertFloatToTextWithDisplayMode<double>(d, buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal);
m_editableZone.setText(buffer); m_editableZone.setText(buffer);
} }
@@ -191,23 +188,21 @@ void SumGraphController::LegendView::setSumLayout(Step step, double start, doubl
const CodePoint sigma[sigmaLength] = {' ', m_sumSymbol}; const CodePoint sigma[sigmaLength] = {' ', m_sumSymbol};
Poincare::Layout sumLayout = LayoutHelper::CodePointString(sigma, sigmaLength); Poincare::Layout sumLayout = LayoutHelper::CodePointString(sigma, sigmaLength);
if (step != Step::FirstParameter) { if (step != Step::FirstParameter) {
constexpr int precision = Preferences::MediumNumberOfSignificantDigits; char buffer[k_valuesBufferSize];
constexpr int bufferSize = PrintFloat::charSizeForFloatsWithPrecision(precision);
char buffer[bufferSize];
Layout endLayout; Layout endLayout;
if (step == Step::SecondParameter) { if (step == Step::SecondParameter) {
endLayout = EmptyLayout::Builder(EmptyLayoutNode::Color::Yellow, false, k_font, false); endLayout = EmptyLayout::Builder(EmptyLayoutNode::Color::Yellow, false, k_font, false);
} else { } else {
PoincareHelpers::ConvertFloatToTextWithDisplayMode<double>(end, buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal); PoincareHelpers::ConvertFloatToTextWithDisplayMode<double>(end, buffer, k_valuesBufferSize, k_valuesPrecision, Preferences::PrintFloatMode::Decimal);
endLayout = LayoutHelper::String(buffer, strlen(buffer), k_font); endLayout = LayoutHelper::String(buffer, strlen(buffer), k_font);
} }
PoincareHelpers::ConvertFloatToTextWithDisplayMode<double>(start, buffer, bufferSize, precision, Preferences::PrintFloatMode::Decimal); PoincareHelpers::ConvertFloatToTextWithDisplayMode<double>(start, buffer, k_valuesBufferSize, k_valuesPrecision, Preferences::PrintFloatMode::Decimal);
sumLayout = CondensedSumLayout::Builder( sumLayout = CondensedSumLayout::Builder(
sumLayout, sumLayout,
LayoutHelper::String(buffer, strlen(buffer), k_font), LayoutHelper::String(buffer, strlen(buffer), k_font),
endLayout); endLayout);
if (step == Step::Result) { if (step == Step::Result) {
PoincareHelpers::ConvertFloatToText<double>(result, buffer, bufferSize, precision); PoincareHelpers::ConvertFloatToText<double>(result, buffer, k_valuesBufferSize, k_valuesPrecision);
sumLayout = HorizontalLayout::Builder( sumLayout = HorizontalLayout::Builder(
sumLayout, sumLayout,
functionLayout, functionLayout,

View File

@@ -58,6 +58,8 @@ private:
void setSumLayout(Step step, double start, double end, double result, Poincare::Layout functionLayout); void setSumLayout(Step step, double start, double end, double result, Poincare::Layout functionLayout);
private: private:
constexpr static size_t k_editableZoneBufferSize = Poincare::PrintFloat::k_maxFloatCharSize; constexpr static size_t k_editableZoneBufferSize = Poincare::PrintFloat::k_maxFloatCharSize;
constexpr static int k_valuesPrecision = Poincare::Preferences::MediumNumberOfSignificantDigits;
constexpr static int k_valuesBufferSize = Poincare::PrintFloat::charSizeForFloatsWithPrecision(k_valuesPrecision);
constexpr static KDCoordinate k_legendHeight = 35; constexpr static KDCoordinate k_legendHeight = 35;
constexpr static const KDFont * k_font = KDFont::SmallFont; constexpr static const KDFont * k_font = KDFont::SmallFont;
static KDCoordinate editableZoneWidth() { return 12*k_font->glyphSize().width(); } static KDCoordinate editableZoneWidth() { return 12*k_font->glyphSize().width(); }