[apps/settings] Improve settings rendering

Change-Id: I717fe46d4ac302fbd992f83d1fe910903059eedd
This commit is contained in:
Émilie Feral
2017-03-03 14:20:13 +01:00
committed by Romain Goyet
parent af44acd80f
commit f34379d14e
9 changed files with 131 additions and 58 deletions

View File

@@ -1,5 +1,7 @@
#include "main_controller.h"
#include "../global_preferences.h"
#include "../../poincare/src/layout/baseline_relative_layout.h"
#include "../../poincare/src/layout/string_layout.h"
#include <assert.h>
#include <poincare.h>
@@ -7,21 +9,20 @@ using namespace Poincare;
namespace Settings {
const SettingsNode angleChildren[2] = {SettingsNode("Degre"), SettingsNode("Radian")};
const SettingsNode FloatDisplayModeChildren[2] = {SettingsNode("Auto"), SettingsNode("Scientifique")};
const SettingsNode numberTypeChildren[2] = {SettingsNode("Reel"), SettingsNode("Complexe")};
const SettingsNode complexFormatChildren[2] = {SettingsNode("Algebrique"), SettingsNode("Polaire")};
const SettingsNode languageChildren[3] = {SettingsNode("Anglais"), SettingsNode("Francais"), SettingsNode("Espagnol")};
const SettingsNode angleChildren[2] = {SettingsNode("Degre "), SettingsNode("Radian ")};
const SettingsNode FloatDisplayModeChildren[2] = {SettingsNode("Auto "), SettingsNode("Scientifique ")};
const SettingsNode complexFormatChildren[2] = {SettingsNode("a+ib "), SettingsNode("eitheta ")};
const SettingsNode languageChildren[3] = {SettingsNode("Anglais "), SettingsNode("Francais "), SettingsNode("Espagnol ")};
const SettingsNode menu[5] = {SettingsNode("Unite d'angles", angleChildren, 2), SettingsNode("Format resultat", FloatDisplayModeChildren, 2),
SettingsNode("Reel ou complexe", numberTypeChildren, 2), SettingsNode("Format complexe", complexFormatChildren, 2),
const SettingsNode menu[4] = {SettingsNode("Unite d'angles", angleChildren, 2), SettingsNode("Format resultat", FloatDisplayModeChildren, 2), SettingsNode("Format complexe", complexFormatChildren, 2),
SettingsNode("Langue", languageChildren, 3)};
const SettingsNode model = SettingsNode("Parametres", menu, 5);
const SettingsNode model = SettingsNode("Parametres", menu, 4);
MainController::MainController(Responder * parentResponder) :
ViewController(parentResponder),
m_cells{PointerTableCellWithChevronAndPointer(KDText::FontSize::Large), PointerTableCellWithChevronAndPointer(KDText::FontSize::Large), PointerTableCellWithChevronAndPointer(KDText::FontSize::Large),
PointerTableCellWithChevronAndPointer(KDText::FontSize::Large), PointerTableCellWithChevronAndPointer(KDText::FontSize::Large)},
m_cells{PointerTableCellWithChevronAndPointer(KDText::FontSize::Large, KDText::FontSize::Small),
PointerTableCellWithChevronAndPointer(KDText::FontSize::Large, KDText::FontSize::Small), PointerTableCellWithChevronAndPointer(KDText::FontSize::Large, KDText::FontSize::Small)},
m_complexFormatCell(PointerTableCellWithChevronAndExpression(nullptr, KDText::FontSize::Large)),
m_selectableTableView(SelectableTableView(this, this, Metric::CommonTopMargin, Metric::CommonRightMargin,
Metric::CommonBottomMargin, Metric::CommonLeftMargin)),
m_nodeModel((Node *)&model),
@@ -29,6 +30,12 @@ MainController::MainController(Responder * parentResponder) :
{
}
MainController::~MainController() {
if (m_complexFormatLayout) {
delete m_complexFormatLayout;
m_complexFormatLayout = nullptr;
}
}
const char * MainController::title() const {
return m_nodeModel->label();
}
@@ -57,38 +64,73 @@ int MainController::numberOfRows() {
return m_nodeModel->numberOfChildren();
};
HighlightCell * MainController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_totalNumberOfCell);
return &m_cells[index];
}
int MainController::reusableCellCount() {
return k_totalNumberOfCell;
}
KDCoordinate MainController::cellHeight() {
KDCoordinate MainController::rowHeight(int j) {
return Metric::ParameterCellHeight;
}
KDCoordinate MainController::cumulatedHeightFromIndex(int j) {
return j*rowHeight(0);
}
int MainController::indexFromCumulatedHeight(KDCoordinate offsetY) {
return offsetY/rowHeight(0);
}
HighlightCell * MainController::reusableCell(int index, int type) {
assert(index >= 0);
if (type == 0) {
assert(index < k_totalNumberOfCell-1);
return &m_cells[index];
}
assert(index == 0);
return &m_complexFormatCell;
}
int MainController::reusableCellCount(int type) {
if (type == 0) {
return k_totalNumberOfCell-1;
}
return 1;
}
int MainController::typeAtLocation(int i, int j) {
if (j == 2) {
return 1;
}
return 0;
}
void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) {
PointerTableCellWithChevronAndPointer * myCell = (PointerTableCellWithChevronAndPointer *)cell;
PointerTableCell * myCell = (PointerTableCell *)cell;
myCell->setText(m_nodeModel->children(index)->label());
if (index == 2) {
if (m_complexFormatLayout) {
delete m_complexFormatLayout;
m_complexFormatLayout = nullptr;
}
if (Preferences::sharedPreferences()->complexFormat() == Preferences::ComplexFormat::Algebric) {
const char text[6] = {'a','+', Ion::Charset::IComplex, 'b', ' ', 0};
m_complexFormatLayout = new StringLayout(text, 6, KDText::FontSize::Small);
} else {
const char base[3] = {'r', Ion::Charset::Exponential, 0};
const char superscrit[4] = {Ion::Charset::IComplex, Ion::Charset::SmallTheta, ' ', 0};
m_complexFormatLayout = new BaselineRelativeLayout(new StringLayout(base, 4, KDText::FontSize::Small), new StringLayout(superscrit, 3, KDText::FontSize::Small), BaselineRelativeLayout::Type::Superscript);
}
PointerTableCellWithChevronAndExpression * myExpCell = (PointerTableCellWithChevronAndExpression *)cell;
myExpCell->setExpression(m_complexFormatLayout);
return;
}
PointerTableCellWithChevronAndPointer * myTextCell = (PointerTableCellWithChevronAndPointer *)cell;
switch (index) {
case 0:
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->angleUnit())->label());
myTextCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->angleUnit())->label());
break;
case 1:
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->displayMode())->label());
break;
case 2:
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->numberType())->label());
myTextCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->displayMode())->label());
break;
case 3:
myCell->setSubtitle(m_nodeModel->children(index)->children((int)Preferences::sharedPreferences()->complexFormat())->label());
break;
case 4:
myCell->setSubtitle(m_nodeModel->children(index)->children((int)GlobalPreferences::sharedGlobalPreferences()->language())->label());
myTextCell->setSubtitle(m_nodeModel->children(index)->children((int)GlobalPreferences::sharedGlobalPreferences()->language())->label());
break;
}
}

View File

@@ -7,24 +7,29 @@
namespace Settings {
class MainController : public ViewController, public SimpleListViewDataSource {
class MainController : public ViewController, public ListViewDataSource {
public:
MainController(Responder * parentResponder);
~MainController();
View * view() override;
const char * title() const override;
bool handleEvent(Ion::Events::Event event) override;
void didBecomeFirstResponder() override;
int numberOfRows() override;
KDCoordinate cellHeight() override;
HighlightCell * reusableCell(int index) override;
int reusableCellCount() override;
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
void viewWillAppear() override;
private:
StackViewController * stackController() const;
constexpr static int k_totalNumberOfCell = 5;
PointerTableCellWithChevronAndPointer m_cells[k_totalNumberOfCell];
constexpr static int k_totalNumberOfCell = 4;
PointerTableCellWithChevronAndPointer m_cells[k_totalNumberOfCell-1];
PointerTableCellWithChevronAndExpression m_complexFormatCell;
Poincare::ExpressionLayout * m_complexFormatLayout;
SelectableTableView m_selectableTableView;
Node * m_nodeModel;
SubController m_subController;

View File

@@ -1,6 +1,8 @@
#include "sub_controller.h"
#include "../global_preferences.h"
#include "../apps_container.h"
#include "../../poincare/src/layout/baseline_relative_layout.h"
#include "../../poincare/src/layout/string_layout.h"
#include <assert.h>
using namespace Poincare;
@@ -16,6 +18,23 @@ SubController::SubController(Responder * parentResponder) :
m_nodeModel(nullptr),
m_preferenceIndex(0)
{
const char text[6] = {'a','+', Ion::Charset::IComplex, 'b', ' ', 0};
m_complexFormatLayout[0] = new StringLayout(text, 6);
const char base[3] = {'r', Ion::Charset::Exponential, 0};
const char superscript[4] = {Ion::Charset::IComplex, Ion::Charset::SmallTheta, ' ', 0};
m_complexFormatLayout[1] = new BaselineRelativeLayout(new StringLayout(base, 4), new StringLayout(superscript, 3), BaselineRelativeLayout::Type::Superscript);
for (int i = 0; i < 2; i++) {
m_complexFormatCells[i].setExpression(m_complexFormatLayout[i]);
}
}
SubController::~SubController() {
for (int i = 0; i < 2; i++) {
if (m_complexFormatLayout[i]) {
delete m_complexFormatLayout[i];
m_complexFormatLayout[i] = nullptr;
}
}
}
const char * SubController::title() const {
@@ -55,10 +74,16 @@ int SubController::numberOfRows() {
HighlightCell * SubController::reusableCell(int index) {
assert(index >= 0);
assert(index < k_totalNumberOfCell);
if (m_preferenceIndex == 2) {
return &m_complexFormatCells[index];
}
return &m_cells[index];
}
int SubController::reusableCellCount() {
if (m_preferenceIndex == 2) {
return 2;
}
return k_totalNumberOfCell;
}
@@ -67,6 +92,9 @@ KDCoordinate SubController::cellHeight() {
}
void SubController::willDisplayCellForIndex(HighlightCell * cell, int index) {
if (m_preferenceIndex == 2) {
return;
}
PointerTableCell * myCell = (PointerTableCell *)cell;
myCell->setText(m_nodeModel->children(index)->label());
}
@@ -93,12 +121,9 @@ void SubController::setPreferenceAtIndexWithValueIndex(int preferenceIndex, int
Preferences::sharedPreferences()->setDisplayMode((Expression::FloatDisplayMode)valueIndex);
break;
case 2:
Preferences::sharedPreferences()->setNumberType((Preferences::NumberType)valueIndex);
break;
case 3:
Preferences::sharedPreferences()->setComplexFormat((Preferences::ComplexFormat)valueIndex);
break;
case 4:
case 3:
GlobalPreferences::sharedGlobalPreferences()->setLanguage((GlobalPreferences::Language)valueIndex);
break;
}
@@ -111,10 +136,8 @@ int SubController::valueIndexAtPreferenceIndex(int preferenceIndex) {
case 1:
return (int)Preferences::sharedPreferences()->displayMode();
case 2:
return (int)Preferences::sharedPreferences()->numberType();
case 3:
return (int)Preferences::sharedPreferences()->complexFormat();
case 4:
case 3:
return (int)GlobalPreferences::sharedGlobalPreferences()->language();
default:
assert(false);

View File

@@ -9,6 +9,7 @@ namespace Settings {
class SubController : public ViewController, public SimpleListViewDataSource {
public:
SubController(Responder * parentResponder);
~SubController();
View * view() override;
const char * title() const override;
bool handleEvent(Ion::Events::Event event) override;
@@ -26,6 +27,8 @@ private:
int valueIndexAtPreferenceIndex(int preferenceIndex);
constexpr static int k_totalNumberOfCell = 3;
PointerTableCell m_cells[k_totalNumberOfCell];
ExpressionTableCell m_complexFormatCells[2];
Poincare::ExpressionLayout * m_complexFormatLayout[2];
SelectableTableView m_selectableTableView;
Node * m_nodeModel;
int m_preferenceIndex;

View File

@@ -6,7 +6,7 @@
class PointerTableCellWithChevronAndExpression : public PointerTableCellWithChevron {
public:
PointerTableCellWithChevronAndExpression(char * label = nullptr);
PointerTableCellWithChevronAndExpression(char * label = nullptr, KDText::FontSize size = KDText::FontSize::Small);
View * subAccessoryView() const override;
void setHighlighted(bool highlight) override;
void setExpression(Poincare::ExpressionLayout * expressionLayout);

View File

@@ -5,7 +5,7 @@
class PointerTableCellWithChevronAndPointer : public PointerTableCellWithChevron {
public:
PointerTableCellWithChevronAndPointer(KDText::FontSize size = KDText::FontSize::Small);
PointerTableCellWithChevronAndPointer(KDText::FontSize labelSize = KDText::FontSize::Small, KDText::FontSize contentSize = KDText::FontSize::Small);
View * subAccessoryView() const override;
void setHighlighted(bool highlight) override;
void setSubtitle(const char * text);

View File

@@ -1,8 +1,8 @@
#include <escher/pointer_table_cell_with_chevron_and_expression.h>
#include <escher/palette.h>
PointerTableCellWithChevronAndExpression::PointerTableCellWithChevronAndExpression(char * label) :
PointerTableCellWithChevron(label),
PointerTableCellWithChevronAndExpression::PointerTableCellWithChevronAndExpression(char * label, KDText::FontSize size) :
PointerTableCellWithChevron(label, size),
m_subtitleView(1.0f, 0.5f, Palette::GreyDark)
{
}

View File

@@ -1,9 +1,9 @@
#include <escher/pointer_table_cell_with_chevron_and_pointer.h>
#include <escher/palette.h>
PointerTableCellWithChevronAndPointer::PointerTableCellWithChevronAndPointer(KDText::FontSize size) :
PointerTableCellWithChevron(nullptr, size),
m_subtitleView(size, "", 1.0f, 0.5f, Palette::GreyDark)
PointerTableCellWithChevronAndPointer::PointerTableCellWithChevronAndPointer(KDText::FontSize labelSize, KDText::FontSize contentSize) :
PointerTableCellWithChevron(nullptr, labelSize),
m_subtitleView(contentSize, "", 1.0f, 0.5f, Palette::GreyDark)
{
}

View File

@@ -17,17 +17,17 @@ public:
};
Preferences();
static Preferences * sharedPreferences();
Poincare::Expression::AngleUnit angleUnit() const;
void setAngleUnit(Poincare::Expression::AngleUnit angleUnit);
Poincare::Expression::FloatDisplayMode displayMode() const;
void setDisplayMode(Poincare::Expression::FloatDisplayMode FloatDisplayMode);
Expression::AngleUnit angleUnit() const;
void setAngleUnit(Expression::AngleUnit angleUnit);
Expression::FloatDisplayMode displayMode() const;
void setDisplayMode(Expression::FloatDisplayMode FloatDisplayMode);
NumberType numberType() const;
void setNumberType(NumberType numberType);
ComplexFormat complexFormat() const;
void setComplexFormat(ComplexFormat complexFormat);
private:
Poincare::Expression::AngleUnit m_angleUnit;
Poincare::Expression::FloatDisplayMode m_displayMode;
Expression::AngleUnit m_angleUnit;
Expression::FloatDisplayMode m_displayMode;
NumberType m_numberType;
ComplexFormat m_complexFormat;
};