[apps/sequence] Use the new layouts in the Sequence app.

Change-Id: I8b079bfabccd54472e0ba0fac17b87dbaf3678ee
This commit is contained in:
Léa Saviot
2018-01-12 11:09:12 +01:00
parent b7c0a15eb8
commit a435c548da
5 changed files with 82 additions and 49 deletions

View File

@@ -1,7 +1,9 @@
#include "sequence_toolbox.h"
#include "../sequence_store.h"
#include "../../../poincare/src/layout/baseline_relative_layout.h"
#include "../../../poincare/src/layout/string_layout.h"
#include "../../../poincare/src/layout/char_layout.h"
#include "../../../poincare/src/layout/horizontal_layout.h"
#include "../../../poincare/src/layout/vertical_offset_layout.h"
#include <poincare/layout_engine.h>
#include <assert.h>
using namespace Poincare;
@@ -91,30 +93,30 @@ void SequenceToolbox::setExtraCells(const char * sequenceName, int recurrenceDep
const char * otherSequenceName = SequenceStore::k_sequenceNames[1-sequenceIndex];
for (int j = 0; j < recurrenceDepth; j++) {
const char * indice = j == 0 ? "n" : "n+1";
m_addedCellLayout[j] = new BaselineRelativeLayout(new StringLayout(sequenceName, 1, KDText::FontSize::Large), new StringLayout(indice, strlen(indice), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
m_addedCellLayout[j+recurrenceDepth] = new BaselineRelativeLayout(new StringLayout(otherSequenceName, 1, KDText::FontSize::Large), new StringLayout(indice, strlen(indice), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
m_addedCellLayout[j] = new HorizontalLayout(
new CharLayout(sequenceName[0], KDText::FontSize::Large),
new VerticalOffsetLayout(LayoutEngine::createStringLayout(indice, strlen(indice), KDText::FontSize::Small), VerticalOffsetLayout::Type::Subscript, false),
false);
m_addedCellLayout[j+recurrenceDepth] = new HorizontalLayout(
new CharLayout(otherSequenceName[0], KDText::FontSize::Large),
new VerticalOffsetLayout(LayoutEngine::createStringLayout(indice, strlen(indice), KDText::FontSize::Small), VerticalOffsetLayout::Type::Subscript, false),
false);
}
if (recurrenceDepth < 2) {
const char * indice = recurrenceDepth == 0 ? "n" : (recurrenceDepth == 1 ? "n+1" : "n+2");
m_addedCellLayout[2*recurrenceDepth] = new BaselineRelativeLayout(new StringLayout(otherSequenceName, 1, KDText::FontSize::Large), new StringLayout(indice, strlen(indice), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
m_addedCellLayout[2*recurrenceDepth] = new HorizontalLayout(
new CharLayout(otherSequenceName[0], KDText::FontSize::Large),
new VerticalOffsetLayout(LayoutEngine::createStringLayout(indice, strlen(indice), KDText::FontSize::Small), VerticalOffsetLayout::Type::Subscript, false),
false);
}
}
bool SequenceToolbox::selectAddedCell(int selectedRow){
char buffer[10];
BaselineRelativeLayout * layout = (BaselineRelativeLayout *)m_addedCellLayout[selectedRow];
StringLayout * nameLayout = (StringLayout *)layout->baseLayout();
StringLayout * subscriptLayout = (StringLayout *)layout->indiceLayout();
int currentChar = 0;
strlcpy(buffer, nameLayout->text(), strlen(nameLayout->text())+1);
currentChar += strlen(nameLayout->text());
buffer[currentChar++] = '(';
strlcpy(buffer+currentChar, subscriptLayout->text(), strlen(subscriptLayout->text())+1);
currentChar += strlen(subscriptLayout->text());
buffer[currentChar++] = ')';
buffer[currentChar] = 0;
sender()->insertTextAtLocation(buffer, sender()->cursorLocation());
sender()->setCursorLocation(sender()->cursorLocation()+currentChar);
int bufferSize = 10;
char buffer[bufferSize];
int currentChar = m_addedCellLayout[selectedRow]->writeTextInBuffer(buffer, bufferSize);
textFieldSender()->insertTextAtLocation(buffer, textFieldSender()->cursorLocation());
textFieldSender()->setCursorLocation(textFieldSender()->cursorLocation()+currentChar);
app()->dismissModalViewController();
return true;
}