[poincare] CondensedSumLayoutNode

This commit is contained in:
Léa Saviot
2018-07-19 14:59:25 +02:00
parent a3032e5ec3
commit e0790f1fd0
4 changed files with 107 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ objs += $(addprefix poincare/src/,\
bracket_layout_node.o\
bracket_pair_layout_node.o\
char_layout_node.o\
condensed_sum_layout_node.o\
conjugate_layout_node.o\
empty_layout_node.o\
horizontal_layout_node.o\

View File

@@ -17,6 +17,7 @@
#include <poincare/ceiling.h>
#include <poincare/ceiling_layout_node.h>
#include <poincare/complex_argument.h>
#include <poincare/condensed_sum_layout_node.h>
#include <poincare/confidence_interval.h>
#include <poincare/conjugate.h>
#include <poincare/conjugate_layout_node.h>

View File

@@ -0,0 +1,64 @@
#ifndef POINCARE_CONDENSED_SUM_LAYOUT_NODE_H
#define POINCARE_CONDENSED_SUM_LAYOUT_NODE_H
#include <poincare/layout_cursor.h>
#include <poincare/layout_node.h>
#include <poincare/layout_engine.h>
#include <poincare/layout_reference.h>
namespace Poincare {
class CondensedSumLayoutNode : public LayoutNode {
public:
using LayoutNode::LayoutNode;
/* CondensedSumLayout is only used in apps/shared/sum_graph_controller.cpp, in
* a view with no cursor. */
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override { assert(false); }
void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override { assert(false); }
int writeTextInBuffer(char * buffer, int bufferSize, PrintFloat::Mode floatDisplayMode, int numberOfSignificantDigits) const override {
return LayoutEngine::writePrefixSerializableRefTextInBuffer(SerializableRef(const_cast<CondensedSumLayoutNode *>(this)), buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "sum");
}
LayoutNode * layoutToPointWhenInserting() override {
assert(false);
return nullptr;
}
// TreeNode
size_t size() const override { return sizeof(CondensedSumLayoutNode); }
int numberOfChildren() const override { return 3; }
#if TREE_LOG
const char * description() const override {
return "CondensedSumLayout";
}
#endif
protected:
// LayoutNode
void computeSize() override;
void computeBaseline() override;
KDPoint positionOfChild(LayoutNode * child) override;
private:
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override {}
LayoutNode * baseLayout() { return childAtIndex(0); }
LayoutNode * subscriptLayout() { return childAtIndex(1); }
LayoutNode * superscriptLayout() { return childAtIndex(2); }
};
class CondensedSumLayoutRef : public LayoutReference<CondensedSumLayoutNode> {
public:
CondensedSumLayoutRef(LayoutRef base, LayoutRef subscript, LayoutRef superscript) :
LayoutReference<CondensedSumLayoutNode>()
{
addChildTreeAtIndex(base, 0);
addChildTreeAtIndex(subscript, 1);
addChildTreeAtIndex(superscript, 2);
}
CondensedSumLayoutRef(TreeNode * t) : LayoutReference<CondensedSumLayoutNode>(t) {}
};
}
#endif

View File

@@ -0,0 +1,41 @@
#include <poincare/condensed_sum_layout_node.h>
#include <string.h>
#include <assert.h>
namespace Poincare {
void CondensedSumLayoutNode::computeBaseline() {
KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->layoutSize();
m_baseline = baseLayout()->baseline() + max(0, superscriptSize.height() - baseLayout()->layoutSize().height()/2);
m_baselined = true;
}
void CondensedSumLayoutNode::computeSize() {
KDSize baseSize = baseLayout()->layoutSize();
KDSize subscriptSize = subscriptLayout()->layoutSize();
KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->layoutSize();
KDCoordinate sizeWidth = baseSize.width() + max(subscriptSize.width(), superscriptSize.width());
KDCoordinate sizeHeight = max(baseSize.height()/2, subscriptSize.height()) + max(baseSize.height()/2, superscriptSize.height());
m_frame.setSize(KDSize(sizeWidth, sizeHeight));
m_sized = true;
}
KDPoint CondensedSumLayoutNode::positionOfChild(LayoutNode * child) {
KDCoordinate x = 0;
KDCoordinate y = 0;
KDSize baseSize = baseLayout()->layoutSize();
KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->layoutSize();
if (child == baseLayout()) {
y = max(0, superscriptSize.height() - baseSize.height()/2);
}
if (child == subscriptLayout()) {
x = baseSize.width();
y = max(baseSize.height()/2, superscriptSize.height());
}
if (child == superscriptLayout()) {
x = baseSize.width();
}
return KDPoint(x,y);
}
}