diff --git a/apps/calculation/additional_outputs/illustrated_list_controller.cpp b/apps/calculation/additional_outputs/illustrated_list_controller.cpp index 432bf49c1..e8b3fbb8d 100644 --- a/apps/calculation/additional_outputs/illustrated_list_controller.cpp +++ b/apps/calculation/additional_outputs/illustrated_list_controller.cpp @@ -78,7 +78,7 @@ KDCoordinate IllustratedListController::rowHeight(int j) { return 0; } Shared::ExpiringPointer calculation = m_calculationStore.calculationAtIndex(calculationIndex); - return calculation->height(App::app()->localContext(), Metric::CommonSmallMargin, true, true) + Metric::CellSeparatorThickness; + return calculation->height(App::app()->localContext(), Metric::CommonSmallMargin, true, true) + Metric::CellSeparatorThickness; //TODO LEA } int IllustratedListController::typeAtLocation(int i, int j) { diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 22c84be74..0ec02edb3 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -124,7 +124,7 @@ Layout Calculation::createApproximateOutputLayout(Context * context, bool * coul } } -KDCoordinate Calculation::height(Context * context, float verticalMargin, bool expanded, bool forceSingleLine) { +KDCoordinate Calculation::height(Context * context, float verticalMargin, bool expanded, bool forceSingleLine, CanBeSingleLineFunction canBeSingleLine) { KDCoordinate result = expanded ? m_expandedHeight : m_height; if (result >= 0) { // Height already computed @@ -157,7 +157,7 @@ KDCoordinate Calculation::height(Context * context, float verticalMargin, bool e if (displayOutput(context) == DisplayOutput::ExactOnly) { KDCoordinate exactOutputHeight = exactLayout.layoutSize().height(); KDCoordinate exactOutputWidth = exactLayout.layoutSize().width(); - bool singleLine = forceSingleLine || ((exactOutputWidth + inputWidth) < maxWidth - 2); //TODO LEA 2 + bool singleLine = forceSingleLine || canBeSingleLine(inputWidth, exactOutputWidth); if (singleLine) { KDCoordinate exactOutputBaseline = exactLayout.baseline(); result = std::max(inputBaseline, exactOutputBaseline) // Above the baseline @@ -188,7 +188,7 @@ KDCoordinate Calculation::height(Context * context, float verticalMargin, bool e KDCoordinate approximateOutputHeight = approximateLayout.layoutSize().height(); KDCoordinate approximateOutputWidth = approximateLayout.layoutSize().width(); if (displayOutput(context) == DisplayOutput::ApproximateOnly || (!expanded && displayOutput(context) == DisplayOutput::ExactAndApproximateToggle)) { - bool singleLine = forceSingleLine || ((approximateOutputWidth + inputWidth) < maxWidth); // TODO LEA 2 + bool singleLine = forceSingleLine || canBeSingleLine(inputWidth, approximateOutputWidth); if (singleLine) { KDCoordinate approximateOutputBaseline = approximateLayout.baseline(); result = std::max(inputBaseline, approximateOutputBaseline) // Above the baseline @@ -203,7 +203,7 @@ KDCoordinate Calculation::height(Context * context, float verticalMargin, bool e KDCoordinate exactOutputWidth = exactLayout.layoutSize().width(); KDCoordinate approximateOutputWidth = approximateLayout.layoutSize().width(); KDCoordinate approximateOutputBaseline = approximateLayout.baseline(); - bool singleLine = forceSingleLine || ((inputWidth + exactOutputWidth + approximateOutputWidth) < (maxWidth - 30)); // the 30 represents the = sign (example: sin(30)) TODO LEA + bool singleLine = forceSingleLine || canBeSingleLine(inputWidth, exactOutputWidth + /*TODO LEA equal sign " = "*/ + approximateOutputWidth); if (singleLine) { result = std::max(inputBaseline, std::max(exactOutputBaseline, approximateOutputBaseline)) // Above the baseline + std::max(inputHeight - inputBaseline, // Beloxw the baseline diff --git a/apps/calculation/calculation.h b/apps/calculation/calculation.h index 767fc1e67..ec7dc3895 100644 --- a/apps/calculation/calculation.h +++ b/apps/calculation/calculation.h @@ -84,7 +84,8 @@ public: Poincare::Layout createApproximateOutputLayout(Poincare::Context * context, bool * couldNotCreateApproximateLayout); // Memoization of height - KDCoordinate height(Poincare::Context * context, float verticalMargin, bool expanded, bool forceSingleLine); + typedef bool (*CanBeSingleLineFunction)(KDCoordinate inputWidth, KDCoordinate outputWidth); + KDCoordinate height(Poincare::Context * context, float verticalMargin, bool expanded, bool forceSingleLine, CanBeSingleLineFunction canbeSingleLine = [](KDCoordinate inputWidth, KDCoordinate outputWidth) { assert(false); return true; }); // Displayed output DisplayOutput displayOutput(Poincare::Context * context); @@ -95,7 +96,6 @@ public: // Additional Information AdditionalInformationType additionalInformationType(Poincare::Context * context); private: - static constexpr int maxWidth = Ion::Display::Width - (Metric::CommonSmallMargin * 2) - Metric::EllipsisCellWidth - 48; // 48 is the difference history_view_cell's width and calculation's static constexpr int k_numberOfExpressions = 4; static constexpr KDCoordinate k_heightComputationFailureHeight = 50; static constexpr const char * k_maximalIntegerWithAdditionalInformation = "10000000000000000"; diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 7d763ec22..18669503f 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -208,7 +208,7 @@ KDCoordinate HistoryController::rowHeight(int j) { return 0; } Shared::ExpiringPointer calculation = calculationAtIndex(j); - return calculation->height(App::app()->localContext(), HistoryViewCell::k_verticalMargin, j == selectedRow() && selectedSubviewType() == SubviewType::Output, false); + return calculation->height(App::app()->localContext(), HistoryViewCell::k_verticalMargin, j == selectedRow() && selectedSubviewType() == SubviewType::Output, false, &HistoryViewCell::CanBeSingleLine); } int HistoryController::typeAtLocation(int i, int j) { diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index 43251acc8..8ea49b677 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -169,6 +169,11 @@ View * HistoryViewCell::subviewAtIndex(int index) { return views[index]; } +bool HistoryViewCell::CanBeSingleLine(KDCoordinate inputWidth, KDCoordinate outputWidth) { + // k_margin is the separation between the input and output. + return (inputWidth + k_margin + outputWidth) < (Ion::Display::Width - Metric::EllipsisCellWidth - 2 * k_margin); +} + void HistoryViewCell::layoutSubviews(bool force) { KDCoordinate maxFrameWidth = bounds().width(); if (displayedEllipsis()) { @@ -179,7 +184,8 @@ void HistoryViewCell::layoutSubviews(bool force) { } KDSize inputSize = m_inputView.minimalSizeForOptimalDisplay(); KDSize outputSize = m_scrollableOutputView.minimalSizeForOptimalDisplay(); - bool singleLine = (inputSize.width() + k_margin + outputSize.width()) < bounds().width() - Metric::EllipsisCellWidth; // k_margin the separation between the input and output. inputSize and outputSize already handle their left and right margins TODO LEA factorize singleLine() + + bool singleLine = CanBeSingleLine(inputSize.width(), outputSize.width()); KDCoordinate inputY = k_margin; KDCoordinate outputY = k_margin; diff --git a/apps/calculation/history_view_cell.h b/apps/calculation/history_view_cell.h index 0df307b5e..a47b43a4d 100644 --- a/apps/calculation/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -33,6 +33,7 @@ class HistoryViewCell : public ::EvenOddCell, public Responder { public: constexpr static KDCoordinate k_verticalMargin = Metric::CommonLargeMargin; //TODO LEA same as k_horizontalMargin? HistoryViewCell(Responder * parentResponder = nullptr); + static bool CanBeSingleLine(KDCoordinate inputWidth, KDCoordinate outputWidth); void cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type, HistoryViewCellDataSource::SubviewType previousType = HistoryViewCellDataSource::SubviewType::None); void setEven(bool even) override; void setHighlighted(bool highlight) override;