mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/calculation] Calculation::height has two types of margin arguments
One for the margin between layouts and on top / at the bottom of the cell, the other for the margin surrounding each layout.
This commit is contained in:
committed by
EmilieNumworks
parent
78cac6ddae
commit
11c39b6206
@@ -78,7 +78,7 @@ KDCoordinate IllustratedListController::rowHeight(int j) {
|
||||
return 0;
|
||||
}
|
||||
Shared::ExpiringPointer<Calculation> calculation = m_calculationStore.calculationAtIndex(calculationIndex);
|
||||
return calculation->height(App::app()->localContext(), Metric::CommonSmallMargin, true, true) + Metric::CellSeparatorThickness; //TODO LEA
|
||||
return calculation->height(App::app()->localContext(), Metric::CommonSmallMargin, ScrollableThreeExpressionsView::k_margin, true, true) + Metric::CellSeparatorThickness;
|
||||
}
|
||||
|
||||
int IllustratedListController::typeAtLocation(int i, int j) {
|
||||
|
||||
@@ -10,8 +10,9 @@ namespace Calculation {
|
||||
|
||||
class ScrollableThreeExpressionsView : public Shared::AbstractScrollableMultipleExpressionsView {
|
||||
public:
|
||||
static constexpr KDCoordinate k_margin = Metric::CommonSmallMargin;
|
||||
ScrollableThreeExpressionsView(Responder * parentResponder) : Shared::AbstractScrollableMultipleExpressionsView(parentResponder, &m_contentCell), m_contentCell() {
|
||||
setMargins(Metric::CommonSmallMargin, Metric::CommonSmallMargin, Metric::CommonSmallMargin, Metric::CommonSmallMargin); // Left Right margins are already added by TableCell
|
||||
setMargins(k_margin, k_margin, k_margin, k_margin); // Left Right margins are already added by TableCell
|
||||
setBackgroundColor(KDColorWhite);
|
||||
}
|
||||
void resetMemoization();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "calculation.h"
|
||||
#include "../shared/poincare_helpers.h"
|
||||
#include "../shared/scrollable_multiple_expressions_view.h"
|
||||
#include "../global_preferences.h"
|
||||
#include "../exam_mode_configuration.h"
|
||||
#include <poincare/exception_checkpoint.h>
|
||||
@@ -124,7 +125,7 @@ Layout Calculation::createApproximateOutputLayout(Context * context, bool * coul
|
||||
}
|
||||
}
|
||||
|
||||
KDCoordinate Calculation::height(Context * context, float verticalMargin, bool expanded, bool forceSingleLine, CanBeSingleLineFunction canBeSingleLine) {
|
||||
KDCoordinate Calculation::height(Context * context, KDCoordinate verticalMarginBetweenLayouts, KDCoordinate verticalMarginAroundLayouts, bool expanded, bool forceSingleLine, CanBeSingleLineFunction canBeSingleLine) {
|
||||
KDCoordinate result = expanded ? m_expandedHeight : m_height;
|
||||
if (result >= 0) {
|
||||
// Height already computed
|
||||
@@ -161,9 +162,10 @@ KDCoordinate Calculation::height(Context * context, float verticalMargin, bool e
|
||||
if (singleLine) {
|
||||
KDCoordinate exactOutputBaseline = exactLayout.baseline();
|
||||
result = std::max(inputBaseline, exactOutputBaseline) // Above the baseline
|
||||
+ std::max(inputHeight - inputBaseline, exactOutputHeight - exactOutputBaseline); // Below the baseline
|
||||
+ std::max(inputHeight - inputBaseline, exactOutputHeight - exactOutputBaseline) // Below the baseline
|
||||
+ 2 * verticalMarginAroundLayouts;
|
||||
} else {
|
||||
result = inputHeight + verticalMargin + exactOutputHeight;
|
||||
result = inputHeight + verticalMarginBetweenLayouts + exactOutputHeight + 4 * verticalMarginAroundLayouts;
|
||||
}
|
||||
} else {
|
||||
// Create the approximate output layout
|
||||
@@ -192,9 +194,10 @@ KDCoordinate Calculation::height(Context * context, float verticalMargin, bool e
|
||||
if (singleLine) {
|
||||
KDCoordinate approximateOutputBaseline = approximateLayout.baseline();
|
||||
result = std::max(inputBaseline, approximateOutputBaseline) // Above the baseline
|
||||
+ std::max(inputHeight - inputBaseline, approximateOutputHeight - approximateOutputBaseline); // Below the baseline
|
||||
+ std::max(inputHeight - inputBaseline, approximateOutputHeight - approximateOutputBaseline) // Below the baseline
|
||||
+ 2 * verticalMarginAroundLayouts;
|
||||
} else {
|
||||
result = inputHeight + verticalMargin + approximateOutputHeight;
|
||||
result = inputHeight + verticalMarginBetweenLayouts + approximateOutputHeight + 4 * verticalMarginAroundLayouts;
|
||||
}
|
||||
} else {
|
||||
assert(displayOutput(context) == DisplayOutput::ExactAndApproximate || (displayOutput(context) == DisplayOutput::ExactAndApproximateToggle && expanded));
|
||||
@@ -203,22 +206,23 @@ 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 || canBeSingleLine(inputWidth, exactOutputWidth + /*TODO LEA equal sign " = "*/ + approximateOutputWidth);
|
||||
bool singleLine = forceSingleLine || canBeSingleLine(inputWidth, exactOutputWidth + AbstractScrollableMultipleExpressionsView::StandardApproximateViewAndMarginsSize() + approximateOutputWidth);
|
||||
if (singleLine) {
|
||||
result = std::max(inputBaseline, std::max(exactOutputBaseline, approximateOutputBaseline)) // Above the baseline
|
||||
+ std::max(inputHeight - inputBaseline, // Beloxw the baseline
|
||||
std::max(exactOutputHeight - exactOutputBaseline,
|
||||
approximateOutputHeight - approximateOutputBaseline));
|
||||
approximateOutputHeight - approximateOutputBaseline))
|
||||
+ 2 * verticalMarginAroundLayouts;
|
||||
} else {
|
||||
KDCoordinate outputHeight = std::max(exactOutputBaseline, approximateOutputBaseline) // Above the baseline
|
||||
+ std::max(exactOutputHeight - exactOutputBaseline, approximateOutputHeight - approximateOutputBaseline); // Below the baseline
|
||||
result = inputHeight + verticalMargin + outputHeight;
|
||||
result = inputHeight + verticalMarginBetweenLayouts + outputHeight + 4 * verticalMarginAroundLayouts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the top and bottom margins
|
||||
result += 2 * verticalMargin;
|
||||
result += 2 * verticalMarginBetweenLayouts;
|
||||
|
||||
/* For all display outputs except ExactAndApproximateToggle, the selected
|
||||
* height and the usual height are identical. We update both heights in
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
|
||||
// Memoization of height
|
||||
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; });
|
||||
KDCoordinate height(Poincare::Context * context, KDCoordinate verticalMarginBetweenLayouts, KDCoordinate verticalMarginAroundLayouts, bool expanded, bool forceSingleLine, CanBeSingleLineFunction canbeSingleLine = [](KDCoordinate inputWidth, KDCoordinate outputWidth) { assert(false); return true; });
|
||||
|
||||
// Displayed output
|
||||
DisplayOutput displayOutput(Poincare::Context * context);
|
||||
|
||||
@@ -208,7 +208,13 @@ KDCoordinate HistoryController::rowHeight(int j) {
|
||||
return 0;
|
||||
}
|
||||
Shared::ExpiringPointer<Calculation> calculation = calculationAtIndex(j);
|
||||
return calculation->height(App::app()->localContext(), HistoryViewCell::k_verticalMargin, j == selectedRow() && selectedSubviewType() == SubviewType::Output, false, &HistoryViewCell::CanBeSingleLine);
|
||||
return calculation->height(
|
||||
App::app()->localContext(),
|
||||
HistoryViewCell::k_margin,
|
||||
HistoryViewCell::k_inputOutputViewsVerticalMargin,
|
||||
j == selectedRow() && selectedSubviewType() == SubviewType::Output,
|
||||
false,
|
||||
&HistoryViewCell::CanBeSingleLine);
|
||||
}
|
||||
|
||||
int HistoryController::typeAtLocation(int i, int j) {
|
||||
|
||||
@@ -42,7 +42,7 @@ HistoryViewCell::HistoryViewCell(Responder * parentResponder) :
|
||||
m_calculationDisplayOutput(Calculation::DisplayOutput::Unknown),
|
||||
m_calculationAdditionInformation(Calculation::AdditionalInformationType::None),
|
||||
m_calculationExpanded(false),
|
||||
m_inputView(this, Metric::CommonLargeMargin, Metric::CommonSmallMargin),
|
||||
m_inputView(this, Metric::CommonLargeMargin, k_inputOutputViewsVerticalMargin),
|
||||
m_scrollableOutputView(this)
|
||||
{
|
||||
m_calculationCRC32 = 0;
|
||||
@@ -171,7 +171,7 @@ View * HistoryViewCell::subviewAtIndex(int 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);
|
||||
return (inputWidth + k_margin + outputWidth) < (Ion::Display::Width - Metric::EllipsisCellWidth - 2 * k_margin); //TODO LEA -2 ??
|
||||
}
|
||||
|
||||
void HistoryViewCell::layoutSubviews(bool force) {
|
||||
|
||||
@@ -31,7 +31,8 @@ private:
|
||||
|
||||
class HistoryViewCell : public ::EvenOddCell, public Responder {
|
||||
public:
|
||||
constexpr static KDCoordinate k_verticalMargin = Metric::CommonLargeMargin; //TODO LEA same as k_horizontalMargin?
|
||||
constexpr static KDCoordinate k_margin = Metric::CommonSmallMargin;
|
||||
constexpr static KDCoordinate k_inputOutputViewsVerticalMargin = k_margin;
|
||||
HistoryViewCell(Responder * parentResponder = nullptr);
|
||||
static bool CanBeSingleLine(KDCoordinate inputWidth, KDCoordinate outputWidth);
|
||||
void cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type, HistoryViewCellDataSource::SubviewType previousType = HistoryViewCellDataSource::SubviewType::None);
|
||||
@@ -54,7 +55,6 @@ public:
|
||||
Shared::ScrollableTwoExpressionsView * outputView();
|
||||
Calculation::AdditionalInformationType additionalInformationType() const { return m_calculationAdditionInformation; }
|
||||
private:
|
||||
constexpr static KDCoordinate k_margin = Metric::CommonSmallMargin;
|
||||
constexpr static KDCoordinate k_resultWidth = 80;
|
||||
void reloadScroll();
|
||||
void reloadOutputSelection(HistoryViewCellDataSource::SubviewType previousType);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Shared {
|
||||
|
||||
AbstractScrollableMultipleExpressionsView::ContentCell::ContentCell() :
|
||||
m_rightExpressionView(),
|
||||
m_approximateSign(KDFont::LargeFont, I18n::Message::AlmostEqual, 0.5f, 0.5f, Palette::GreyVeryDark),
|
||||
m_approximateSign(k_font, k_defaultApproximateMessage, 0.5f, 0.5f, Palette::GreyVeryDark),
|
||||
m_centeredExpressionView(),
|
||||
m_selectedSubviewPosition(SubviewPosition::Center),
|
||||
m_displayCenter(true)
|
||||
@@ -66,13 +66,13 @@ KDSize AbstractScrollableMultipleExpressionsView::ContentCell::minimalSizeForOpt
|
||||
KDSize leftSize = KDSizeZero;
|
||||
if (leftExpressionView() && !leftExpressionView()->layout().isUninitialized()) {
|
||||
leftSize = leftExpressionView()->minimalSizeForOptimalDisplay();
|
||||
width += leftSize.width() + Metric::CommonLargeMargin;
|
||||
width += leftSize.width() + k_horizontalMargin;
|
||||
}
|
||||
|
||||
KDSize centerSize = KDSizeZero;
|
||||
if (displayCenter()) {
|
||||
centerSize = m_centeredExpressionView.minimalSizeForOptimalDisplay();
|
||||
width += centerSize.width() + 2 * Metric::CommonLargeMargin + m_approximateSign.minimalSizeForOptimalDisplay().width();
|
||||
width += centerSize.width() + 2 * k_horizontalMargin + m_approximateSign.minimalSizeForOptimalDisplay().width();
|
||||
}
|
||||
|
||||
KDSize rightSize = m_rightExpressionView.minimalSizeForOptimalDisplay();
|
||||
@@ -156,6 +156,10 @@ View * AbstractScrollableMultipleExpressionsView::ContentCell::subviewAtIndex(in
|
||||
return views[index - leftIsVisible];
|
||||
}
|
||||
|
||||
KDCoordinate AbstractScrollableMultipleExpressionsView::ContentCell::StandardApproximateViewAndMarginsSize() {
|
||||
return 2 * k_horizontalMargin + k_font->stringSize(I18n::translate(k_defaultApproximateMessage)).width(); //TODO LEA
|
||||
}
|
||||
|
||||
void AbstractScrollableMultipleExpressionsView::ContentCell::layoutSubviews(bool force) {
|
||||
// Subviews sizes
|
||||
KDSize leftSize = leftExpressionView() ? leftExpressionView()->minimalSizeForOptimalDisplay() : KDSizeZero;
|
||||
@@ -172,16 +176,16 @@ void AbstractScrollableMultipleExpressionsView::ContentCell::layoutSubviews(bool
|
||||
KDCoordinate currentWidth = 0;
|
||||
if (leftExpressionView()) {
|
||||
leftExpressionView()->setFrame(KDRect(currentWidth, viewBaseline - leftBaseline, leftSize), force);
|
||||
currentWidth += leftSize.width() + Metric::CommonLargeMargin;
|
||||
currentWidth += leftSize.width() + k_horizontalMargin;
|
||||
}
|
||||
|
||||
// Layout center expression
|
||||
if (displayCenter()) {
|
||||
KDSize approximateSignSize = m_approximateSign.minimalSizeForOptimalDisplay();
|
||||
m_centeredExpressionView.setFrame(KDRect(currentWidth, viewBaseline - centerBaseline, centerSize), force);
|
||||
currentWidth += Metric::CommonLargeMargin + centerSize.width();
|
||||
currentWidth += k_horizontalMargin + centerSize.width();
|
||||
m_approximateSign.setFrame(KDRect(currentWidth, viewBaseline - approximateSignSize.height()/2, approximateSignSize), force);
|
||||
currentWidth += Metric::CommonLargeMargin + approximateSignSize.width();
|
||||
currentWidth += k_horizontalMargin + approximateSignSize.width();
|
||||
}
|
||||
|
||||
// Layout right expression
|
||||
@@ -243,8 +247,8 @@ bool AbstractScrollableMultipleExpressionsView::handleEvent(Ion::Events::Event e
|
||||
if (contentCell()->displayCenter()) {
|
||||
KDCoordinate centerExpressionWidth = contentCell()->centeredExpressionView()->minimalSizeForOptimalDisplay().width();
|
||||
KDCoordinate signWidth = contentCell()->approximateSign()->minimalSizeForOptimalDisplay().width();
|
||||
centeredExpressionIsVisibleOnTheLeft = leftWidth + Metric::CommonLargeMargin + centerExpressionWidth - contentOffset().x() > 0;
|
||||
centeredExpressionIsVisibleOnTheRight = minimalSizeForOptimalDisplay().width() - rightExpressionWidth - signWidth - centerExpressionWidth - 2*Metric::CommonLargeMargin - contentOffset().x() < bounds().width();
|
||||
centeredExpressionIsVisibleOnTheLeft = leftWidth + ContentCell::k_horizontalMargin + centerExpressionWidth - contentOffset().x() > 0;
|
||||
centeredExpressionIsVisibleOnTheRight = minimalSizeForOptimalDisplay().width() - rightExpressionWidth - signWidth - centerExpressionWidth - 2 * ContentCell::k_horizontalMargin - contentOffset().x() < bounds().width();
|
||||
}
|
||||
// Select center
|
||||
if ((event == Ion::Events::Left && selectedSubviewPosition() == SubviewPosition::Right && centeredExpressionIsVisibleOnTheLeft) ||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SHARED_SCROLLABLE_MULTIPLE_EXPRESSIONS_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
#include <apps/i18n.h>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
@@ -12,6 +13,11 @@ public:
|
||||
Center = 1,
|
||||
Right = 2
|
||||
};
|
||||
|
||||
static KDCoordinate StandardApproximateViewAndMarginsSize() {
|
||||
return ContentCell::StandardApproximateViewAndMarginsSize();
|
||||
}
|
||||
|
||||
AbstractScrollableMultipleExpressionsView(Responder * parentResponder, View * contentCell);
|
||||
::EvenOddCell * evenOddCell() {
|
||||
return contentCell();
|
||||
@@ -33,6 +39,8 @@ public:
|
||||
protected:
|
||||
class ContentCell : public ::EvenOddCell {
|
||||
public:
|
||||
static KDCoordinate StandardApproximateViewAndMarginsSize();
|
||||
constexpr static KDCoordinate k_horizontalMargin = Metric::CommonLargeMargin;
|
||||
ContentCell();
|
||||
KDColor backgroundColor() const override;
|
||||
void setHighlighted(bool highlight) override;
|
||||
@@ -60,6 +68,8 @@ protected:
|
||||
virtual Poincare::Layout layout() const override;
|
||||
KDCoordinate baseline(KDCoordinate * leftBaseline = nullptr, KDCoordinate * centerBaseline = nullptr, KDCoordinate * rightBaseline = nullptr) const;
|
||||
private:
|
||||
constexpr static const KDFont * k_font = KDFont::LargeFont;
|
||||
const static I18n::Message k_defaultApproximateMessage = I18n::Message::AlmostEqual;
|
||||
View * subviewAtIndex(int index) override;
|
||||
ExpressionView m_rightExpressionView;
|
||||
MessageTextView m_approximateSign;
|
||||
|
||||
Reference in New Issue
Block a user