diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index d5363eb62..ba89fb659 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -61,7 +61,7 @@ public: } Position position() const { return m_position; } void setPosition(Position position) { m_position = position; } - int cursorHeight() { return 1; } //TODO + KDCoordinate cursorHeight(); int baseline() { return 1; } //TODO LayoutCursor clone() const { return LayoutCursor(m_layoutRef, m_position); @@ -112,11 +112,12 @@ public: void addLayoutAndMoveCursor(LayoutRef l) {} //TODO private: + constexpr static KDCoordinate k_cursorHeight = 18; LayoutCursor(LayoutNode * node, Position position = Position::Right) : m_layoutRef(node), m_position(position) - { - } + {} + KDCoordinate layoutHeight(); LayoutRef m_layoutRef; Position m_position; }; diff --git a/poincare/include/poincare/tree_reference.h b/poincare/include/poincare/tree_reference.h index 0ffead61e..9193120d2 100644 --- a/poincare/include/poincare/tree_reference.h +++ b/poincare/include/poincare/tree_reference.h @@ -75,6 +75,7 @@ public: // Hierarchy bool hasChild(TreeReference t) const { return node()->hasChild(t.node()); }; + bool hasSibling(TreeReference t) const { return node()->hasSibling(t.node()); }; int numberOfChildren() const { return node()->numberOfChildren(); } TreeReference parent() const { return TreeReference(node()->parentTree()); } TreeReference treeChildAtIndex(int i) const { return TreeReference(node()->childTreeAtIndex(i)); } diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index 544ca6a09..5be1a3240 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -4,6 +4,13 @@ namespace Poincare { +/* Getters and setters */ + +KDCoordinate LayoutCursor::cursorHeight() { + KDCoordinate height = layoutHeight(); + return height == 0 ? k_cursorHeight : height; +} + /* Comparison */ bool LayoutCursor::isEquivalentTo(LayoutCursor cursor) { @@ -37,4 +44,23 @@ void LayoutCursor::moveUnder(bool * shouldRecomputeLayout) { layoutReference().typedNode()->moveCursorDown(this, shouldRecomputeLayout); } +/* Private */ + +KDCoordinate LayoutCursor::layoutHeight() { + LayoutRef equivalentLayoutRef = m_layoutRef.equivalentCursor(this).layoutReference(); + if (m_layoutRef.hasChild(equivalentLayoutRef)) { + return equivalentLayoutRef.layoutSize().height(); + } + KDCoordinate pointedLayoutHeight = m_layoutRef.layoutSize().height(); + if (m_layoutRef.hasSibling(equivalentLayoutRef)) { + KDCoordinate equivalentLayoutHeight = equivalentLayoutRef.layoutSize().height(); + KDCoordinate pointedLayoutBaseline = m_layoutRef.baseline(); + KDCoordinate equivalentLayoutBaseline = equivalentLayoutRef.baseline(); + return max(pointedLayoutBaseline, equivalentLayoutBaseline) + + max(pointedLayoutHeight - pointedLayoutBaseline, equivalentLayoutHeight - equivalentLayoutBaseline); + } + return pointedLayoutHeight; + +} + }