mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 12:10:03 +02:00
[poincare] ProductLayoutNode
This commit is contained in:
@@ -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\
|
||||
|
||||
@@ -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>
|
||||
|
||||
31
poincare/include/poincare/product_layout_node.h
Normal file
31
poincare/include/poincare/product_layout_node.h
Normal 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
|
||||
@@ -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>
|
||||
|
||||
31
poincare/src/product_layout_node.cpp
Normal file
31
poincare/src/product_layout_node.cpp
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user