[solver] Fix SolutionsController with new Poincare API

This commit is contained in:
Émilie Feral
2018-09-07 10:03:22 +02:00
parent 33f7ca841c
commit 8e992c58ed
2 changed files with 12 additions and 21 deletions

View File

@@ -63,12 +63,12 @@ SolutionsController::SolutionsController(Responder * parentResponder, EquationSt
ViewController(parentResponder),
m_equationStore(equationStore),
m_deltaCell(0.5f, 0.5f),
m_delta2Layout(nullptr),
m_delta2Layout(),
m_contentView(this)
{
m_delta2Layout = HorizontalLayoutRef(VerticalOffsetLayoutRef(CharLayoutRef('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript), LayoutHelper::String("-4ac", 4, KDText::FontSize::Small));
char deltaB[] = {Ion::Charset::CapitalDelta, '=', 'b'};
static_cast<HorizontalLayoutRef>(m_delta2Layout)->addOrMergeChildAtIndex(LayoutHelper::String(deltaB, 3, KDText::FontSize::Small), 0, false);
static_cast<HorizontalLayoutRef&>(m_delta2Layout).addOrMergeChildAtIndex(LayoutHelper::String(deltaB, 3, KDText::FontSize::Small), 0, false);
for (int i = 0; i < EquationStore::k_maxNumberOfExactSolutions; i++) {
m_exactValueCells[i].setParentResponder(m_contentView.selectableTableView());
}
@@ -80,13 +80,6 @@ SolutionsController::SolutionsController(Responder * parentResponder, EquationSt
}
}
SolutionsController::~SolutionsController() {
if (m_delta2Layout) {
delete m_delta2Layout;
m_delta2Layout = nullptr;
}
}
/* ViewController */
const char * SolutionsController::title() {
if (m_equationStore->type() == EquationStore::Type::Monovariable) {
@@ -152,7 +145,7 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i,
if (i == 0) {
if (m_equationStore->type() == EquationStore::Type::PolynomialMonovariable && j == m_equationStore->numberOfSolutions()) {
EvenOddExpressionCell * deltaCell = static_cast<EvenOddExpressionCell *>(cell);
deltaCell->setExpressionLayout(m_delta2Layout);
deltaCell->setLayoutRef(m_delta2Layout);
} else {
EvenOddBufferTextCell * symbolCell = static_cast<EvenOddBufferTextCell *>(cell);
symbolCell->setFontSize(KDText::FontSize::Large);
@@ -178,10 +171,9 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i,
valueCell->setText(bufferValue);
} else {
Shared::ScrollableExactApproximateExpressionsCell * valueCell = static_cast<ScrollableExactApproximateExpressionsCell *>(cell);
Poincare::ExpressionLayout * exactLayout = m_equationStore->exactSolutionLayoutsAtIndexAreIdentical(j) ? nullptr : m_equationStore->exactSolutionLayoutAtIndex(j, true);
Poincare::ExpressionLayout * exactSolutionLayouts[2] = {m_equationStore->exactSolutionLayoutAtIndex(j, false), exactLayout};
valueCell->setExpressions(exactSolutionLayouts);
if (exactLayout) {
Poincare::LayoutReference exactLayout = m_equationStore->exactSolutionLayoutsAtIndexAreIdentical(j) ? Poincare::LayoutReference() : m_equationStore->exactSolutionLayoutAtIndex(j, true);
valueCell->setLayouts(m_equationStore->exactSolutionLayoutAtIndex(j, false), exactLayout);
if (!exactLayout.isUninitialized()) {
valueCell->setEqualMessage(m_equationStore->exactSolutionLayoutsAtIndexAreEqual(j) ? I18n::Message::Equal : I18n::Message::AlmostEqual);
}
}
@@ -202,11 +194,11 @@ KDCoordinate SolutionsController::rowHeight(int j) {
if (m_equationStore->type() == EquationStore::Type::Monovariable) {
return k_defaultCellHeight;
}
Poincare::ExpressionLayout * exactLayout = m_equationStore->exactSolutionLayoutAtIndex(j, true);
Poincare::ExpressionLayout * approximateLayout = m_equationStore->exactSolutionLayoutAtIndex(j, false);
KDCoordinate exactLayoutHeight = exactLayout->size().height();
KDCoordinate approximateLayoutHeight = approximateLayout->size().height();
KDCoordinate layoutHeight = max(exactLayout->baseline(), approximateLayout->baseline()) + max(exactLayoutHeight-exactLayout->baseline(), approximateLayoutHeight-approximateLayout->baseline());
Poincare::LayoutReference exactLayout = m_equationStore->exactSolutionLayoutAtIndex(j, true);
Poincare::LayoutReference approximateLayout = m_equationStore->exactSolutionLayoutAtIndex(j, false);
KDCoordinate exactLayoutHeight = exactLayout.layoutSize().height();
KDCoordinate approximateLayoutHeight = approximateLayout.layoutSize().height();
KDCoordinate layoutHeight = max(exactLayout.baseline(), approximateLayout.baseline()) + max(exactLayoutHeight-exactLayout.baseline(), approximateLayoutHeight-approximateLayout.baseline());
return layoutHeight+ScrollableExactApproximateExpressionsCell::k_margin*2;
}

View File

@@ -11,7 +11,6 @@ namespace Solver {
class SolutionsController : public ViewController, public AlternateEmptyViewDelegate, public SelectableTableViewDataSource, public TableViewDataSource {
public:
SolutionsController(Responder * parentResponder, EquationStore * equationStore);
~SolutionsController();
/* ViewController */
const char * title() override;
View * view() override;
@@ -59,7 +58,7 @@ private:
EquationStore * m_equationStore;
EvenOddBufferTextCell m_symbolCells[EquationStore::k_maxNumberOfSolutions];
EvenOddExpressionCell m_deltaCell;
Poincare::ExpressionLayout * m_delta2Layout;
Poincare::LayoutReference m_delta2Layout;
Shared::ScrollableExactApproximateExpressionsCell m_exactValueCells[EquationStore::k_maxNumberOfExactSolutions];
EvenOddBufferTextCell m_approximateValueCells[EquationStore::k_maxNumberOfApproximateSolutions];
ContentView m_contentView;