[poincare] ProductLayoutNode

This commit is contained in:
Léa Saviot
2018-07-13 14:39:29 +02:00
parent 1057b3ba2e
commit cfe3e7aa91
5 changed files with 66 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ objs += $(addprefix poincare/src/,\
layout_cursor.o\
layout_node.o\
layout_reference.o\
product_layout_node.o\
sequence_layout_node.o\
sum_layout_node.o\
vertical_offset_layout_node.o\

View File

@@ -67,6 +67,7 @@
#include <poincare/prediction_interval.h>
#include <poincare/preferences.h>
#include <poincare/product.h>
#include <poincare/product_layout_node.h>
#include <poincare/randint.h>
#include <poincare/random.h>
#include <poincare/rational.h>

View File

@@ -0,0 +1,31 @@
#ifndef POINCARE_PRODUCT_LAYOUT_NODE_H
#define POINCARE_PRODUCT_LAYOUT_NODE_H
#include <poincare/layout_engine.h>
#include <poincare/sequence_layout_node.h>
namespace Poincare {
class ProductLayoutNode : public SequenceLayoutNode {
public:
using SequenceLayoutNode::SequenceLayoutNode;
int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override;
protected:
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
private:
constexpr static KDCoordinate k_lineThickness = 1;
};
class ProductLayoutRef : public LayoutReference<ProductLayoutNode> {
public:
ProductLayoutRef(TreeNode * n) : LayoutReference<ProductLayoutNode>(n) {}
ProductLayoutRef(LayoutRef argument, LayoutRef lowerB, LayoutRef upperB) : LayoutReference<ProductLayoutNode>() {
addChildTreeAtIndex(argument, 0);
addChildTreeAtIndex(lowerB, 1);
addChildTreeAtIndex(upperB, 2);
}
};
}
#endif

View File

@@ -1,7 +1,6 @@
#include <poincare/product.h>
#include <poincare/multiplication.h>
#include <poincare/sum_layout_node.h> //TODO remove
//#include <poincare/product_layout_node.h>
#include <poincare/product_layout_node.h>
extern "C" {
#include <assert.h>
#include <stdlib.h>
@@ -28,8 +27,7 @@ int Product::emptySequenceValue() const {
}
LayoutRef Product::createSequenceLayout(LayoutRef argumentLayout, LayoutRef subscriptLayout, LayoutRef superscriptLayout) const {
return SumLayoutRef(argumentLayout, subscriptLayout, superscriptLayout);
// TODO return ProductLayoutRef(argumentLayout, subscriptLayout, superscriptLayout);
return ProductLayoutRef(argumentLayout, subscriptLayout, superscriptLayout);
}
template<typename T>

View File

@@ -0,0 +1,31 @@
#include <poincare/product_layout_node.h>
#include <poincare/char_layout_node.h>
#include <poincare/horizontal_layout_node.h>
namespace Poincare {
int ProductLayoutNode::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits) const {
return SequenceLayoutNode::writeDerivedClassInBuffer("product", buffer, bufferSize, numberOfSignificantDigits);
}
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();
// Render the Product symbol.
ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.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),
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,
p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2),
k_lineThickness, k_symbolHeight), expressionColor);
// Render the "n=" and the parentheses.
SequenceLayoutNode::render(ctx, p, expressionColor, backgroundColor);
}
}