From 2bb5c3d83132a711e91f033aabe80fdba7ef8f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 13 Jul 2018 10:53:18 +0200 Subject: [PATCH] [poincare] LayoutCursor::addEmptyExponentialLayout --- poincare/include/poincare/layout_cursor.h | 2 +- poincare/include/poincare/tree_reference.h | 4 ++++ poincare/src/layout_cursor.cpp | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index 761649306..8bb911329 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -107,7 +107,7 @@ public: } /* Layout modification */ - void addEmptyExponentialLayout() {} //TODO + void addEmptyExponentialLayout(); void addEmptyMatrixLayout() {} //TODO void addEmptyPowerLayout(); void addEmptySquareRootLayout() {} //TODO diff --git a/poincare/include/poincare/tree_reference.h b/poincare/include/poincare/tree_reference.h index d4e0d4bdc..096dab0ae 100644 --- a/poincare/include/poincare/tree_reference.h +++ b/poincare/include/poincare/tree_reference.h @@ -91,6 +91,10 @@ public: assert(isDefined()); return node()->hasSibling(t.node()); } + bool hasAncestor(TreeReference t, bool includeSelf) const { + assert(isDefined()); + return node()->hasAncestor(t.node(), includeSelf); + } int numberOfChildren() const { assert(isDefined()); return node()->numberOfChildren(); diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index abbf723d0..7957eb7f5 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -65,6 +65,18 @@ void LayoutCursor::moveUnder(bool * shouldRecomputeLayout) { /* Layout modification */ +void LayoutCursor::addEmptyExponentialLayout() { + EmptyLayoutRef emptyLayout; + HorizontalLayoutRef sibling = HorizontalLayoutRef( + CharLayoutRef(Ion::Charset::Exponential), + VerticalOffsetLayoutRef(emptyLayout, VerticalOffsetLayoutNode::Type::Superscript)); + LayoutRef rootRef = m_layoutRef.root(); + m_layoutRef.addSibling(this, sibling, false); + if (emptyLayout.hasAncestor(rootRef, false) && !emptyLayout.isAllocationFailure()) { + m_layoutRef = emptyLayout; + } +} + void LayoutCursor::addEmptyPowerLayout() { VerticalOffsetLayoutRef offsetLayout = VerticalOffsetLayoutRef(EmptyLayoutRef(), VerticalOffsetLayoutNode::Type::Superscript); privateAddEmptyPowerLayout(offsetLayout);