[poincare] LayoutCursor::addEmptyPowerLayout

This commit is contained in:
Léa Saviot
2018-07-13 10:43:39 +02:00
parent 5ad469c654
commit 4eb5b4355a
2 changed files with 25 additions and 12 deletions

View File

@@ -8,6 +8,7 @@
namespace Poincare {
class HorizontalLayoutNode;
class VerticalOffsetLayoutRef;
class LayoutCursor {
template <typename T>
@@ -108,7 +109,7 @@ public:
/* Layout modification */
void addEmptyExponentialLayout() {} //TODO
void addEmptyMatrixLayout() {} //TODO
void addEmptyPowerLayout() {} //TODO
void addEmptyPowerLayout();
void addEmptySquareRootLayout() {} //TODO
void addEmptySquarePowerLayout();
void addEmptyTenPowerLayout() {} //TODO
@@ -137,6 +138,7 @@ public:
private:
constexpr static KDCoordinate k_cursorHeight = 18;
KDCoordinate layoutHeight();
void privateAddEmptyPowerLayout(VerticalOffsetLayoutRef v);
bool baseForNewPowerLayout();
bool privateShowHideEmptyLayoutIfNeeded(bool show);
LayoutRef m_layoutRef;

View File

@@ -65,18 +65,17 @@ void LayoutCursor::moveUnder(bool * shouldRecomputeLayout) {
/* Layout modification */
void LayoutCursor::addEmptySquarePowerLayout() {
CharLayoutRef indiceLayout = CharLayoutRef('2');
VerticalOffsetLayoutRef offsetLayout = VerticalOffsetLayoutRef(indiceLayout, VerticalOffsetLayoutNode::Type::Superscript);
// If there is already a base
if (baseForNewPowerLayout()) {
m_layoutRef.addSibling(this, offsetLayout, true);
return;
void LayoutCursor::addEmptyPowerLayout() {
VerticalOffsetLayoutRef offsetLayout = VerticalOffsetLayoutRef(EmptyLayoutRef(), VerticalOffsetLayoutNode::Type::Superscript);
privateAddEmptyPowerLayout(offsetLayout);
if (offsetLayout.parent().isDefined() && offsetLayout.numberOfChildren() == 1 && !offsetLayout.childAtIndex(0).isAllocationFailure()) {
m_layoutRef = offsetLayout.childAtIndex(0);
}
// Else, add an empty base
EmptyLayoutRef child1 = EmptyLayoutRef();
HorizontalLayoutRef newChild = HorizontalLayoutRef(child1, offsetLayout);
m_layoutRef.addSibling(this, newChild, true);
}
void LayoutCursor::addEmptySquarePowerLayout() {
VerticalOffsetLayoutRef offsetLayout = VerticalOffsetLayoutRef(CharLayoutRef('2'), VerticalOffsetLayoutNode::Type::Superscript);
privateAddEmptyPowerLayout(offsetLayout);
}
void LayoutCursor::addXNTCharLayout() {
@@ -170,6 +169,18 @@ KDCoordinate LayoutCursor::layoutHeight() {
}
void LayoutCursor::privateAddEmptyPowerLayout(VerticalOffsetLayoutRef v) {
// If there is already a base
if (baseForNewPowerLayout()) {
m_layoutRef.addSibling(this, v, true);
return;
}
// Else, add an empty base
EmptyLayoutRef e = EmptyLayoutRef();
HorizontalLayoutRef newChild = HorizontalLayoutRef(e, v);
m_layoutRef.addSibling(this, newChild, true);
}
bool LayoutCursor::baseForNewPowerLayout() {
/* Returns true if the layout on the left of the pointed layout is suitable to
* be the base of a new power layout: the base layout should be anything but