mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Merge changes I2947f0e0,Ibeb77958
* changes: [apps] create a tool box controller [escher] add optional margins to modal view
This commit is contained in:
@@ -9,6 +9,7 @@ app_objs += $(addprefix apps/,\
|
||||
constant.o\
|
||||
expression_text_field_delegate.o\
|
||||
main.o\
|
||||
tool_box_controller.o\
|
||||
)
|
||||
|
||||
$(app_objs): $(inline_images:.png=.o)
|
||||
|
||||
95
apps/tool_box_controller.cpp
Normal file
95
apps/tool_box_controller.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "tool_box_controller.h"
|
||||
#include <assert.h>
|
||||
|
||||
static const char * labels[] = {
|
||||
"Abs()",
|
||||
"Root()",
|
||||
"Log()",
|
||||
"Calcul",
|
||||
"Nombres complexes",
|
||||
"Probabilite",
|
||||
"Arithmetiques",
|
||||
"Matrices",
|
||||
"Listes",
|
||||
"Approximation",
|
||||
"Trigonometrie hyperbolique"
|
||||
};
|
||||
|
||||
ToolBoxController::ToolBoxController() :
|
||||
StackViewController(nullptr, this, true),
|
||||
m_selectableTableView(SelectableTableView(this, this))
|
||||
{
|
||||
}
|
||||
|
||||
const char * ToolBoxController::title() const {
|
||||
return "ToolBoxController";
|
||||
}
|
||||
|
||||
bool ToolBoxController::handleEvent(Ion::Events::Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ToolBoxController::didBecomeFirstResponder() {
|
||||
m_selectableTableView.selectCellAtLocation(0, 0);
|
||||
app()->setFirstResponder(&m_selectableTableView);
|
||||
}
|
||||
|
||||
int ToolBoxController::numberOfRows() {
|
||||
return k_numberOfCommandRows + k_numberOfMenuRows;
|
||||
}
|
||||
|
||||
TableViewCell * ToolBoxController::reusableCell(int index, int type) {
|
||||
assert(type < 2);
|
||||
assert(index >= 0);
|
||||
if (type == 0) {
|
||||
assert(index < k_numberOfCommandRows);
|
||||
return &m_commandCells[index];
|
||||
}
|
||||
assert(index < k_maxNumberOfDisplayedRows);
|
||||
return &m_menuCells[index];
|
||||
}
|
||||
|
||||
int ToolBoxController::reusableCellCount(int type) {
|
||||
assert(type < 2);
|
||||
if (type == 0) {
|
||||
return k_numberOfCommandRows;
|
||||
}
|
||||
return k_maxNumberOfDisplayedRows;
|
||||
}
|
||||
|
||||
void ToolBoxController::willDisplayCellForIndex(TableViewCell * cell, int index) {
|
||||
MenuListCell * myCell = (MenuListCell *)cell;
|
||||
myCell->setText(labels[index]);
|
||||
}
|
||||
|
||||
KDCoordinate ToolBoxController::rowHeight(int j) {
|
||||
if (typeAtLocation(0, j) == 0) {
|
||||
return k_commandRowHeight;
|
||||
}
|
||||
return k_menuRowHeight;
|
||||
}
|
||||
|
||||
KDCoordinate ToolBoxController::cumulatedHeightFromIndex(int j) {
|
||||
if (j < k_numberOfCommandRows) {
|
||||
return j*k_commandRowHeight;
|
||||
}
|
||||
return k_commandRowHeight*k_numberOfCommandRows + k_menuRowHeight*(j-k_numberOfCommandRows);
|
||||
}
|
||||
|
||||
int ToolBoxController::indexFromCumulatedHeight(KDCoordinate offsetY) {
|
||||
if (offsetY < k_commandRowHeight*k_numberOfCommandRows) {
|
||||
return offsetY/k_commandRowHeight;
|
||||
}
|
||||
return k_numberOfCommandRows + (offsetY - k_commandRowHeight*k_numberOfCommandRows)/k_menuRowHeight;
|
||||
}
|
||||
|
||||
int ToolBoxController::typeAtLocation(int i, int j) {
|
||||
if (j < k_numberOfCommandRows) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ToolBoxController::setTextFieldCaller(TextField * textField) {
|
||||
m_textFieldCaller = textField;
|
||||
}
|
||||
33
apps/tool_box_controller.h
Normal file
33
apps/tool_box_controller.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef APPS_TOOL_BOX_CONTROLLER_H
|
||||
#define APPS_TOOL_BOX_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
class ToolBoxController : public StackViewController, public ListViewDataSource {
|
||||
public:
|
||||
ToolBoxController();
|
||||
const char * title() const override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void didBecomeFirstResponder() override;
|
||||
int numberOfRows() override;
|
||||
TableViewCell * reusableCell(int index, int type) override;
|
||||
int reusableCellCount(int type) override;
|
||||
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
|
||||
KDCoordinate rowHeight(int j) override;
|
||||
KDCoordinate cumulatedHeightFromIndex(int j) override;
|
||||
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
|
||||
int typeAtLocation(int i, int j) override;
|
||||
void setTextFieldCaller(TextField * textField);
|
||||
private:
|
||||
constexpr static int k_numberOfCommandRows = 3;
|
||||
constexpr static int k_numberOfMenuRows = 8;
|
||||
constexpr static int k_maxNumberOfDisplayedRows = 6;
|
||||
constexpr static KDCoordinate k_commandRowHeight = 50;
|
||||
constexpr static KDCoordinate k_menuRowHeight = 40;
|
||||
MenuListCell m_commandCells[k_numberOfCommandRows];
|
||||
MenuListCell m_menuCells[k_maxNumberOfDisplayedRows];
|
||||
SelectableTableView m_selectableTableView;
|
||||
TextField * m_textFieldCaller;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -24,7 +24,8 @@ public:
|
||||
void setFirstResponder(Responder * responder);
|
||||
Responder * firstResponder();
|
||||
void processEvent(Ion::Events::Event event);
|
||||
void displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment);
|
||||
void displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment,
|
||||
KDCoordinate topMargin = 0, KDCoordinate leftMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate rightMargin = 0);
|
||||
void dismissModalViewController();
|
||||
void displayWarning(const char * warningMessage);
|
||||
const char * name();
|
||||
|
||||
@@ -12,7 +12,8 @@ public:
|
||||
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void didBecomeFirstResponder() override;
|
||||
void displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment);
|
||||
void displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment,
|
||||
KDCoordinate topMargin = 0, KDCoordinate leftMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate rightMargin = 0);
|
||||
void dismissModalViewController();
|
||||
bool isDisplayingModal();
|
||||
private:
|
||||
@@ -23,7 +24,8 @@ private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
void presentModalView(View * modalView, float verticalAlignment, float horizontalAlignment);
|
||||
void presentModalView(View * modalView, float verticalAlignment, float horizontalAlignment,
|
||||
KDCoordinate topMargin, KDCoordinate leftMargin, KDCoordinate bottomMargin, KDCoordinate rightMargin);
|
||||
void dismissModalView();
|
||||
bool isDisplayingModal() const;
|
||||
private:
|
||||
@@ -33,6 +35,10 @@ private:
|
||||
bool m_isDisplayingModal;
|
||||
float m_verticalAlignment;
|
||||
float m_horizontalAlignment;
|
||||
KDCoordinate m_topMargin;
|
||||
KDCoordinate m_leftMargin;
|
||||
KDCoordinate m_bottomMargin;
|
||||
KDCoordinate m_rightMargin;
|
||||
};
|
||||
ContentView m_contentView;
|
||||
Responder * m_previousResponder;
|
||||
|
||||
@@ -62,8 +62,9 @@ const Image * App::icon() {
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
void App::displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment) {
|
||||
m_modalViewController.displayModalViewController(vc, verticalAlignment, horizontalAlignment);
|
||||
void App::displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment,
|
||||
KDCoordinate topMargin, KDCoordinate leftMargin, KDCoordinate bottomMargin, KDCoordinate rightMargin) {
|
||||
m_modalViewController.displayModalViewController(vc, verticalAlignment, horizontalAlignment, topMargin, leftMargin, bottomMargin, rightMargin);
|
||||
}
|
||||
|
||||
void App::dismissModalViewController() {
|
||||
|
||||
@@ -8,7 +8,11 @@ ModalViewController::ContentView::ContentView() :
|
||||
m_currentModalView(nullptr),
|
||||
m_isDisplayingModal(false),
|
||||
m_verticalAlignment(0.0f),
|
||||
m_horizontalAlignment(0.0f)
|
||||
m_horizontalAlignment(0.0f),
|
||||
m_topMargin(0),
|
||||
m_leftMargin(0),
|
||||
m_bottomMargin(0),
|
||||
m_rightMargin(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,11 +46,11 @@ View * ModalViewController::ContentView::subviewAtIndex(int index) {
|
||||
|
||||
KDRect ModalViewController::ContentView::frame() {
|
||||
KDCoordinate modalHeight = m_currentModalView->minimalSizeForOptimalDisplay().height();
|
||||
modalHeight = modalHeight == 0 ? bounds().height() : modalHeight;
|
||||
modalHeight = modalHeight == 0 ? bounds().height()-m_topMargin-m_bottomMargin : modalHeight;
|
||||
KDCoordinate modalWidth = m_currentModalView->minimalSizeForOptimalDisplay().width();
|
||||
modalWidth = modalWidth == 0 ? bounds().width() : modalWidth;
|
||||
KDRect modalViewFrame(m_horizontalAlignment*(bounds().width()-modalWidth), m_verticalAlignment*(bounds().height()-modalHeight),
|
||||
modalWidth, modalHeight);
|
||||
modalWidth = modalWidth == 0 ? bounds().width()-m_leftMargin-m_rightMargin : modalWidth;
|
||||
KDRect modalViewFrame(m_leftMargin + m_horizontalAlignment*(bounds().width()-m_leftMargin-m_rightMargin-modalWidth),
|
||||
m_topMargin+m_verticalAlignment*(bounds().height()-m_topMargin-m_bottomMargin-modalHeight), modalWidth, modalHeight);
|
||||
return modalViewFrame;
|
||||
}
|
||||
|
||||
@@ -57,11 +61,16 @@ void ModalViewController::ContentView::layoutSubviews() {
|
||||
}
|
||||
}
|
||||
|
||||
void ModalViewController::ContentView::presentModalView(View * modalView, float verticalAlignment, float horizontalAlignment) {
|
||||
void ModalViewController::ContentView::presentModalView(View * modalView, float verticalAlignment, float horizontalAlignment,
|
||||
KDCoordinate topMargin, KDCoordinate leftMargin, KDCoordinate bottomMargin, KDCoordinate rightMargin) {
|
||||
m_isDisplayingModal = true;
|
||||
m_currentModalView = modalView;
|
||||
m_horizontalAlignment = horizontalAlignment;
|
||||
m_verticalAlignment = verticalAlignment;
|
||||
m_topMargin = topMargin;
|
||||
m_leftMargin = leftMargin;
|
||||
m_bottomMargin = bottomMargin;
|
||||
m_rightMargin = rightMargin;
|
||||
markRectAsDirty(frame());
|
||||
layoutSubviews();
|
||||
}
|
||||
@@ -101,12 +110,13 @@ const char * ModalViewController::title() const {
|
||||
return "Modal View Controller";
|
||||
}
|
||||
|
||||
void ModalViewController::displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment) {
|
||||
void ModalViewController::displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment,
|
||||
KDCoordinate topMargin, KDCoordinate leftMargin, KDCoordinate bottomMargin, KDCoordinate rightMargin) {
|
||||
m_currentModalViewController = vc;
|
||||
vc->setParentResponder(this);
|
||||
m_previousResponder = app()->firstResponder();
|
||||
app()->setFirstResponder(vc);
|
||||
m_contentView.presentModalView(vc->view(), verticalAlignment, horizontalAlignment);
|
||||
m_contentView.presentModalView(vc->view(), verticalAlignment, horizontalAlignment, topMargin, leftMargin, bottomMargin, rightMargin);
|
||||
}
|
||||
|
||||
void ModalViewController::dismissModalViewController() {
|
||||
|
||||
Reference in New Issue
Block a user