[poincare] Remove dummy layout use in sum and product layouts

This commit is contained in:
Léa Saviot
2018-07-26 17:40:16 +02:00
parent 37cdb615ab
commit cf0d22136a
4 changed files with 19 additions and 13 deletions

View File

@@ -38,6 +38,9 @@ protected:
constexpr static KDCoordinate k_boundHeightMargin = 2;
constexpr static KDCoordinate k_argumentWidthMargin = 2;
constexpr static KDText::FontSize k_fontSize = KDText::FontSize::Large;
constexpr static char k_nEquals[] = {'n', '=', 0};
KDSize lowerBoundSizeWithNEquals();
// LayoutNode
void computeSize() override;
@@ -57,10 +60,7 @@ protected:
assert(numberOfChildren() == 3);
return childAtIndex(2);
}
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
private:
KDSize lowerBoundSizeWithNEquals();
};
}

View File

@@ -4,6 +4,8 @@
namespace Poincare {
static inline KDCoordinate max(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; }
int ProductLayoutNode::writeTextInBuffer(char * buffer, int bufferSize, PrintFloat::Mode floatDisplayMode, int numberOfSignificantDigits) const {
return SequenceLayoutNode::writeDerivedClassInBuffer("product", buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits);
}
@@ -11,16 +13,16 @@ int ProductLayoutNode::writeTextInBuffer(char * buffer, int bufferSize, PrintFlo
void ProductLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
// Compute sizes.
KDSize upperBoundSize = upperBoundLayout()->layoutSize();
KDSize lowerBoundSizeWithNEquals = HorizontalLayoutRef(CharLayoutRef('n'), CharLayoutRef('='), LayoutRef(lowerBoundLayout()).clone()).layoutSize();
KDSize lowerBoundNEqualsSize = lowerBoundSizeWithNEquals();
// Render the Product symbol.
ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.width()-k_symbolWidth)/2),
ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2),
p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2),
k_lineThickness, k_symbolHeight), expressionColor);
ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.width()-k_symbolWidth)/2),
ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2),
p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2),
k_symbolWidth, k_lineThickness), expressionColor);
ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.width()-k_symbolWidth)/2)+k_symbolWidth,
ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2)+k_symbolWidth,
p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2),
k_lineThickness, k_symbolHeight), expressionColor);

View File

@@ -9,6 +9,8 @@ namespace Poincare {
static inline KDCoordinate max(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; }
constexpr char SequenceLayoutNode::k_nEquals[];
void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
if (cursor->position() == LayoutCursor::Position::Left
&& ((lowerBoundLayout() && cursor->layoutReference() == lowerBoundLayout())
@@ -148,7 +150,7 @@ void SequenceLayoutNode::computeBaseline() {
KDPoint SequenceLayoutNode::positionOfChild(LayoutNode * l) {
KDSize nEqualslowerBoundSize = lowerBoundSizeWithNEquals();
KDSize nEqualsSize = KDText::stringSize("n=", k_fontSize);
KDSize nEqualsSize = KDText::stringSize(k_nEquals, k_fontSize);
KDSize upperBoundSize = upperBoundLayout()->layoutSize();
KDCoordinate x = 0;
KDCoordinate y = 0;
@@ -212,8 +214,8 @@ int SequenceLayoutNode::writeDerivedClassInBuffer(const char * operatorName, cha
void SequenceLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
// Render the "n="
KDPoint nEqualsPosition = positionOfChild(lowerBoundLayout()).translatedBy(KDPoint(-KDText::stringSize("n=", k_fontSize).width(), 0));
ctx->drawString("n=", p.translatedBy(nEqualsPosition), k_fontSize, expressionColor, backgroundColor);
KDPoint nEqualsPosition = positionOfChild(lowerBoundLayout()).translatedBy(KDPoint(-KDText::stringSize(k_nEquals, k_fontSize).width(), 0));
ctx->drawString(k_nEquals, p.translatedBy(nEqualsPosition), k_fontSize, expressionColor, backgroundColor);
// Render the parentheses
KDCoordinate argumentWithParenthesesHeight = ParenthesisLayoutNode::HeightGivenChildHeight(argumentLayout()->layoutSize().height());
@@ -232,7 +234,7 @@ void SequenceLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCo
KDSize SequenceLayoutNode::lowerBoundSizeWithNEquals() {
KDSize lowerBoundSize = lowerBoundLayout()->layoutSize();
KDSize nEqualsSize = KDText::stringSize("n=", k_fontSize);
KDSize nEqualsSize = KDText::stringSize(k_nEquals, k_fontSize);
return KDSize(
nEqualsSize.width() + lowerBoundSize.width(),
max(nEqualsSize.height(), lowerBoundSize.height()));

View File

@@ -4,6 +4,8 @@
namespace Poincare {
static inline KDCoordinate max(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; }
const uint8_t symbolPixel[SumLayoutNode::k_symbolHeight][SumLayoutNode::k_symbolWidth] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
@@ -30,11 +32,11 @@ int SumLayoutNode::writeTextInBuffer(char * buffer, int bufferSize, PrintFloat::
void SumLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
// Computes sizes.
KDSize upperBoundSize = upperBoundLayout()->layoutSize();
KDSize lowerBoundSizeWithNEquals = HorizontalLayoutRef(CharLayoutRef('n'), CharLayoutRef('='), LayoutRef(lowerBoundLayout()).clone()).layoutSize();
KDSize lowerBoundNEqualsSize = lowerBoundSizeWithNEquals();
// Render the Sum symbol.
KDColor workingBuffer[k_symbolWidth*k_symbolHeight];
KDRect symbolFrame(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.width()-k_symbolWidth)/2),
KDRect symbolFrame(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2),
p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2),
k_symbolWidth, k_symbolHeight);
ctx->blendRectWithMask(symbolFrame, expressionColor, (const uint8_t *)symbolPixel, (KDColor *)workingBuffer);