mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/settings] Implement setting menu with a tree (for navigation)
Change-Id: Ie27c3c25085a279c47eb53f3f1054d970b607f8b
This commit is contained in:
@@ -2,6 +2,8 @@ app_objs += $(addprefix apps/settings/,\
|
||||
app.o\
|
||||
preference.o\
|
||||
main_controller.o\
|
||||
settings_node.o\
|
||||
sub_controller.o\
|
||||
)
|
||||
|
||||
app_images += apps/settings/settings_icon.png
|
||||
|
||||
@@ -3,17 +3,28 @@
|
||||
|
||||
namespace Settings {
|
||||
|
||||
const SettingsNode angleChildren[2] = {SettingsNode("Degre"), SettingsNode("Radian")};
|
||||
const SettingsNode displayModeChildren[2] = {SettingsNode("Auto"), SettingsNode("Scientifique")};
|
||||
const SettingsNode numberTypeChildren[2] = {SettingsNode("Reel"), SettingsNode("Complexe")};
|
||||
const SettingsNode complexFormatChildren[2] = {SettingsNode("Cartesien"), SettingsNode("Polaire")};
|
||||
const SettingsNode languageChildren[2] = {SettingsNode("Anglais"), SettingsNode("Francais")};
|
||||
|
||||
const SettingsNode menu[5] = {SettingsNode("Unite d'angles", angleChildren, 2), SettingsNode("Format resultat", displayModeChildren, 2),
|
||||
SettingsNode("Reel ou complexe", numberTypeChildren, 2), SettingsNode("Format complexe", complexFormatChildren, 2),
|
||||
SettingsNode("Langue", languageChildren, 2)};
|
||||
const SettingsNode model = SettingsNode("Parametres", menu, 5);
|
||||
|
||||
MainController::MainController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_cells{ChevronMenuListCell((char*)"Angles"), ChevronMenuListCell((char*)"Resultats"), ChevronMenuListCell((char*)"Forme nombre"),
|
||||
ChevronMenuListCell((char*)"Forme complexe"), ChevronMenuListCell((char*)"Langue")},
|
||||
m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin,
|
||||
Metric::BottomMargin, Metric::LeftMargin))
|
||||
Metric::BottomMargin, Metric::LeftMargin)),
|
||||
m_nodeModel((Node *)&model),
|
||||
m_subController(this)
|
||||
{
|
||||
}
|
||||
|
||||
const char * MainController::title() const {
|
||||
return "Parametres";
|
||||
return m_nodeModel->label();
|
||||
}
|
||||
|
||||
View * MainController::view() {
|
||||
@@ -28,11 +39,16 @@ void MainController::didBecomeFirstResponder() {
|
||||
}
|
||||
|
||||
bool MainController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK) {
|
||||
m_subController.setNodeModel(m_nodeModel->children(m_selectableTableView.selectedRow()));
|
||||
StackViewController * stack = stackController();
|
||||
stack->push(&m_subController);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int MainController::numberOfRows() {
|
||||
return k_totalNumberOfCell;
|
||||
return m_nodeModel->numberOfChildren();
|
||||
};
|
||||
|
||||
TableViewCell * MainController::reusableCell(int index) {
|
||||
@@ -49,4 +65,13 @@ KDCoordinate MainController::cellHeight() {
|
||||
return Metric::ParameterCellHeight;
|
||||
}
|
||||
|
||||
StackViewController * MainController::stackController() const {
|
||||
return (StackViewController *)parentResponder();
|
||||
}
|
||||
|
||||
void MainController::willDisplayCellForIndex(TableViewCell * cell, int index) {
|
||||
ChevronMenuListCell * myCell = (ChevronMenuListCell *)cell;
|
||||
myCell->setText(m_nodeModel->children(index)->label());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SETTINGS_MAIN_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "sub_controller.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
@@ -17,10 +18,14 @@ public:
|
||||
KDCoordinate cellHeight() override;
|
||||
TableViewCell * reusableCell(int index) override;
|
||||
int reusableCellCount() override;
|
||||
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
|
||||
private:
|
||||
StackViewController * stackController() const;
|
||||
constexpr static int k_totalNumberOfCell = 5;
|
||||
ChevronMenuListCell m_cells[k_totalNumberOfCell];
|
||||
SelectableTableView m_selectableTableView;
|
||||
Node * m_nodeModel;
|
||||
SubController m_subController;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
9
apps/settings/settings_node.cpp
Normal file
9
apps/settings/settings_node.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "settings_node.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
const Node * SettingsNode::children(int index) const {
|
||||
return &m_children[index];
|
||||
}
|
||||
|
||||
}
|
||||
23
apps/settings/settings_node.h
Normal file
23
apps/settings/settings_node.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef SETTINGS_NODE_H
|
||||
#define SETTINGS_NODE_H
|
||||
|
||||
#include "../node.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class SettingsNode : public Node {
|
||||
public:
|
||||
constexpr SettingsNode(const char * label = nullptr, const SettingsNode * children = nullptr, int numberOfChildren = 0) :
|
||||
Node(label, numberOfChildren),
|
||||
m_children(children)
|
||||
{
|
||||
};
|
||||
const Node * children(int index) const override;
|
||||
private:
|
||||
const SettingsNode * m_children;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
64
apps/settings/sub_controller.cpp
Normal file
64
apps/settings/sub_controller.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "sub_controller.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Settings {
|
||||
|
||||
SubController::SubController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin,
|
||||
Metric::BottomMargin, Metric::LeftMargin)),
|
||||
m_nodeModel(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
const char * SubController::title() const {
|
||||
if (m_nodeModel) {
|
||||
return m_nodeModel->label();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
View * SubController::view() {
|
||||
return &m_selectableTableView;
|
||||
}
|
||||
|
||||
void SubController::didBecomeFirstResponder() {
|
||||
m_selectableTableView.selectCellAtLocation(0, 0);
|
||||
app()->setFirstResponder(&m_selectableTableView);
|
||||
}
|
||||
|
||||
bool SubController::handleEvent(Ion::Events::Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int SubController::numberOfRows() {
|
||||
if (m_nodeModel) {
|
||||
return m_nodeModel->numberOfChildren();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableViewCell * SubController::reusableCell(int index) {
|
||||
assert(index >= 0);
|
||||
assert(index < k_totalNumberOfCell);
|
||||
return &m_cells[index];
|
||||
}
|
||||
|
||||
int SubController::reusableCellCount() {
|
||||
return k_totalNumberOfCell;
|
||||
}
|
||||
|
||||
KDCoordinate SubController::cellHeight() {
|
||||
return Metric::ParameterCellHeight;
|
||||
}
|
||||
|
||||
void SubController::willDisplayCellForIndex(TableViewCell * cell, int index) {
|
||||
MenuListCell * myCell = (MenuListCell *)cell;
|
||||
myCell->setText(m_nodeModel->children(index)->label());
|
||||
}
|
||||
|
||||
void SubController::setNodeModel(const Node * nodeModel) {
|
||||
m_nodeModel = (Node *)nodeModel;
|
||||
}
|
||||
|
||||
}
|
||||
31
apps/settings/sub_controller.h
Normal file
31
apps/settings/sub_controller.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef SETTINGS_SUB_CONTROLLER_H
|
||||
#define SETTINGS_SUB_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "settings_node.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
class SubController : public ViewController, public SimpleListViewDataSource {
|
||||
public:
|
||||
SubController(Responder * parentResponder);
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void didBecomeFirstResponder() override;
|
||||
int numberOfRows() override;
|
||||
KDCoordinate cellHeight() override;
|
||||
TableViewCell * reusableCell(int index) override;
|
||||
int reusableCellCount() override;
|
||||
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
|
||||
void setNodeModel(const Node * nodeModel);
|
||||
private:
|
||||
constexpr static int k_totalNumberOfCell = 2;
|
||||
MenuListCell m_cells[k_totalNumberOfCell];
|
||||
SelectableTableView m_selectableTableView;
|
||||
Node * m_nodeModel;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user