mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/calculation] CanBeSingleLine differs if args are view/layout sizes
If the sizes are for layouts, we need to add the margins added by the views.
This commit is contained in:
committed by
EmilieNumworks
parent
4f50a72abf
commit
579485c8c0
@@ -125,7 +125,7 @@ Layout Calculation::createApproximateOutputLayout(Context * context, bool * coul
|
||||
}
|
||||
}
|
||||
|
||||
KDCoordinate Calculation::height(Context * context, KDCoordinate verticalMarginBetweenLayouts, KDCoordinate verticalMarginAroundLayouts, bool expanded, bool forceSingleLine, CanBeSingleLineFunction canBeSingleLine) {
|
||||
KDCoordinate Calculation::height(Context * context, KDCoordinate verticalMarginBetweenLayouts, KDCoordinate verticalMarginAroundLayouts, bool expanded, bool forceSingleLine, LayoutsCanBeSingleLineFunction canBeSingleLine) {
|
||||
KDCoordinate result = expanded ? m_expandedHeight : m_height;
|
||||
if (result >= 0) {
|
||||
// Height already computed
|
||||
|
||||
@@ -84,8 +84,8 @@ public:
|
||||
Poincare::Layout createApproximateOutputLayout(Poincare::Context * context, bool * couldNotCreateApproximateLayout);
|
||||
|
||||
// Memoization of height
|
||||
typedef bool (*CanBeSingleLineFunction)(KDCoordinate inputWidth, KDCoordinate outputWidth);
|
||||
KDCoordinate height(Poincare::Context * context, KDCoordinate verticalMarginBetweenLayouts, KDCoordinate verticalMarginAroundLayouts, bool expanded, bool forceSingleLine, CanBeSingleLineFunction canbeSingleLine = [](KDCoordinate inputWidth, KDCoordinate outputWidth) { assert(false); return true; });
|
||||
typedef bool (*LayoutsCanBeSingleLineFunction)(KDCoordinate inputWidth, KDCoordinate outputWidth);
|
||||
KDCoordinate height(Poincare::Context * context, KDCoordinate verticalMarginBetweenLayouts, KDCoordinate verticalMarginAroundLayouts, bool expanded, bool forceSingleLine, LayoutsCanBeSingleLineFunction canbeSingleLine = [](KDCoordinate inputLayoutWidth, KDCoordinate outputLayoutWidth) { assert(false); return true; });
|
||||
|
||||
// Displayed output
|
||||
DisplayOutput displayOutput(Poincare::Context * context);
|
||||
|
||||
@@ -214,7 +214,7 @@ KDCoordinate HistoryController::rowHeight(int j) {
|
||||
HistoryViewCell::k_inputOutputViewsVerticalMargin,
|
||||
j == selectedRow() && selectedSubviewType() == SubviewType::Output,
|
||||
false,
|
||||
&HistoryViewCell::CanBeSingleLine);
|
||||
&HistoryViewCell::LayoutsCanBeSingleLine);
|
||||
}
|
||||
|
||||
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, k_inputOutputViewsVerticalMargin),
|
||||
m_inputView(this, k_inputOutputViewsHorizontalMargin, k_inputOutputViewsVerticalMargin),
|
||||
m_scrollableOutputView(this)
|
||||
{
|
||||
m_calculationCRC32 = 0;
|
||||
@@ -169,9 +169,14 @@ View * HistoryViewCell::subviewAtIndex(int index) {
|
||||
return views[index];
|
||||
}
|
||||
|
||||
bool HistoryViewCell::CanBeSingleLine(KDCoordinate inputWidth, KDCoordinate outputWidth) {
|
||||
bool HistoryViewCell::LayoutsCanBeSingleLine(KDCoordinate inputLayoutWidth, KDCoordinate outputLayoutWidth) {
|
||||
// k_margin is the separation between the input and output.
|
||||
return (inputWidth + k_margin + outputWidth) < (Ion::Display::Width - Metric::EllipsisCellWidth - 2 * k_margin); //TODO LEA -2 ??
|
||||
return ViewsCanBeSingleLine(inputLayoutWidth + 2 * k_inputOutputViewsHorizontalMargin, outputLayoutWidth + 2 * k_inputOutputViewsHorizontalMargin);
|
||||
}
|
||||
|
||||
bool HistoryViewCell::ViewsCanBeSingleLine(KDCoordinate inputViewWidth, KDCoordinate outputViewWidth) {
|
||||
// k_margin is the separation between the input and output.
|
||||
return (inputViewWidth + k_margin + outputViewWidth) < Ion::Display::Width - Metric::EllipsisCellWidth;
|
||||
}
|
||||
|
||||
void HistoryViewCell::layoutSubviews(bool force) {
|
||||
@@ -185,7 +190,7 @@ void HistoryViewCell::layoutSubviews(bool force) {
|
||||
KDSize inputSize = m_inputView.minimalSizeForOptimalDisplay();
|
||||
KDSize outputSize = m_scrollableOutputView.minimalSizeForOptimalDisplay();
|
||||
|
||||
bool singleLine = CanBeSingleLine(inputSize.width(), outputSize.width());
|
||||
bool singleLine = ViewsCanBeSingleLine(inputSize.width(), outputSize.width());
|
||||
|
||||
KDCoordinate inputY = k_margin;
|
||||
KDCoordinate outputY = k_margin;
|
||||
|
||||
@@ -33,8 +33,10 @@ class HistoryViewCell : public ::EvenOddCell, public Responder {
|
||||
public:
|
||||
constexpr static KDCoordinate k_margin = Metric::CommonSmallMargin;
|
||||
constexpr static KDCoordinate k_inputOutputViewsVerticalMargin = k_margin;
|
||||
constexpr static KDCoordinate k_inputOutputViewsHorizontalMargin = Shared::AbstractScrollableMultipleExpressionsView::k_horizontalMargin;
|
||||
HistoryViewCell(Responder * parentResponder = nullptr);
|
||||
static bool CanBeSingleLine(KDCoordinate inputWidth, KDCoordinate outputWidth);
|
||||
static bool LayoutsCanBeSingleLine(KDCoordinate inputLayoutWidth, KDCoordinate outputLayoutWidth);
|
||||
static bool ViewsCanBeSingleLine(KDCoordinate inputViewWidth, KDCoordinate outputViewWidth);
|
||||
void cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type, HistoryViewCellDataSource::SubviewType previousType = HistoryViewCellDataSource::SubviewType::None);
|
||||
void setEven(bool even) override;
|
||||
void setHighlighted(bool highlight) override;
|
||||
|
||||
@@ -66,13 +66,13 @@ KDSize AbstractScrollableMultipleExpressionsView::ContentCell::minimalSizeForOpt
|
||||
KDSize leftSize = KDSizeZero;
|
||||
if (leftExpressionView() && !leftExpressionView()->layout().isUninitialized()) {
|
||||
leftSize = leftExpressionView()->minimalSizeForOptimalDisplay();
|
||||
width += leftSize.width() + k_horizontalMargin;
|
||||
width += leftSize.width() + AbstractScrollableMultipleExpressionsView::k_horizontalMargin;
|
||||
}
|
||||
|
||||
KDSize centerSize = KDSizeZero;
|
||||
if (displayCenter()) {
|
||||
centerSize = m_centeredExpressionView.minimalSizeForOptimalDisplay();
|
||||
width += centerSize.width() + 2 * k_horizontalMargin + m_approximateSign.minimalSizeForOptimalDisplay().width();
|
||||
width += centerSize.width() + 2 * AbstractScrollableMultipleExpressionsView::k_horizontalMargin + m_approximateSign.minimalSizeForOptimalDisplay().width();
|
||||
}
|
||||
|
||||
KDSize rightSize = m_rightExpressionView.minimalSizeForOptimalDisplay();
|
||||
@@ -157,7 +157,7 @@ View * AbstractScrollableMultipleExpressionsView::ContentCell::subviewAtIndex(in
|
||||
}
|
||||
|
||||
KDCoordinate AbstractScrollableMultipleExpressionsView::ContentCell::StandardApproximateViewAndMarginsSize() {
|
||||
return 2 * k_horizontalMargin + k_font->stringSize(I18n::translate(k_defaultApproximateMessage)).width(); //TODO LEA
|
||||
return 2 * AbstractScrollableMultipleExpressionsView::k_horizontalMargin + k_font->stringSize(I18n::translate(k_defaultApproximateMessage)).width();
|
||||
}
|
||||
|
||||
void AbstractScrollableMultipleExpressionsView::ContentCell::layoutSubviews(bool force) {
|
||||
@@ -176,16 +176,16 @@ void AbstractScrollableMultipleExpressionsView::ContentCell::layoutSubviews(bool
|
||||
KDCoordinate currentWidth = 0;
|
||||
if (leftExpressionView()) {
|
||||
leftExpressionView()->setFrame(KDRect(currentWidth, viewBaseline - leftBaseline, leftSize), force);
|
||||
currentWidth += leftSize.width() + k_horizontalMargin;
|
||||
currentWidth += leftSize.width() + AbstractScrollableMultipleExpressionsView::k_horizontalMargin;
|
||||
}
|
||||
|
||||
// Layout center expression
|
||||
if (displayCenter()) {
|
||||
KDSize approximateSignSize = m_approximateSign.minimalSizeForOptimalDisplay();
|
||||
m_centeredExpressionView.setFrame(KDRect(currentWidth, viewBaseline - centerBaseline, centerSize), force);
|
||||
currentWidth += k_horizontalMargin + centerSize.width();
|
||||
currentWidth += AbstractScrollableMultipleExpressionsView::k_horizontalMargin + centerSize.width();
|
||||
m_approximateSign.setFrame(KDRect(currentWidth, viewBaseline - approximateSignSize.height()/2, approximateSignSize), force);
|
||||
currentWidth += k_horizontalMargin + approximateSignSize.width();
|
||||
currentWidth += AbstractScrollableMultipleExpressionsView::k_horizontalMargin + approximateSignSize.width();
|
||||
}
|
||||
|
||||
// Layout right expression
|
||||
@@ -247,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 + ContentCell::k_horizontalMargin + centerExpressionWidth - contentOffset().x() > 0;
|
||||
centeredExpressionIsVisibleOnTheRight = minimalSizeForOptimalDisplay().width() - rightExpressionWidth - signWidth - centerExpressionWidth - 2 * ContentCell::k_horizontalMargin - contentOffset().x() < bounds().width();
|
||||
centeredExpressionIsVisibleOnTheLeft = leftWidth + k_horizontalMargin + centerExpressionWidth - contentOffset().x() > 0;
|
||||
centeredExpressionIsVisibleOnTheRight = minimalSizeForOptimalDisplay().width() - rightExpressionWidth - signWidth - centerExpressionWidth - 2 * k_horizontalMargin - contentOffset().x() < bounds().width();
|
||||
}
|
||||
// Select center
|
||||
if ((event == Ion::Events::Left && selectedSubviewPosition() == SubviewPosition::Right && centeredExpressionIsVisibleOnTheLeft) ||
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Shared {
|
||||
|
||||
class AbstractScrollableMultipleExpressionsView : public ScrollableView, public ScrollViewDataSource {
|
||||
public:
|
||||
constexpr static KDCoordinate k_horizontalMargin = Metric::CommonLargeMargin;
|
||||
enum class SubviewPosition : uint8_t {
|
||||
Left = 0,
|
||||
Center = 1,
|
||||
@@ -40,7 +41,6 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user