mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/calculation] Calculation::height has CanBeSingleLine argument
This commit is contained in:
committed by
EmilieNumworks
parent
1c2801907f
commit
78cac6ddae
@@ -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;
|
||||
return calculation->height(App::app()->localContext(), Metric::CommonSmallMargin, true, true) + Metric::CellSeparatorThickness; //TODO LEA
|
||||
}
|
||||
|
||||
int IllustratedListController::typeAtLocation(int i, int j) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -208,7 +208,7 @@ 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);
|
||||
return calculation->height(App::app()->localContext(), HistoryViewCell::k_verticalMargin, j == selectedRow() && selectedSubviewType() == SubviewType::Output, false, &HistoryViewCell::CanBeSingleLine);
|
||||
}
|
||||
|
||||
int HistoryController::typeAtLocation(int i, int j) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user