Merge changes Iab0d283d,Ib1ca31d4,Iac52d377,Iee2efaab,If5cc51c3, ...

* changes:
  [apps] create a class variable box lead cell
  [apps] Ensure const methods when needed in node class
  [apps] use toolbox leaf cell in the toolbox controller
  [apps] create a class toolbox leaf cell
  [apps] Improve the drawing of boxes (variable and toolbox)
  [escher] enable stack view controller to have different stack view colors
  [escher] Change palette names to make them consistant
  [apps] enable node navigation controller to use different cell types (implemented by its subclasses)
  [escher] Correct int comparison issue in text field
  [escher] improve stack view drawing
  [escher] add default constructor for text menu list cell
This commit is contained in:
Émilie Feral
2016-11-15 11:58:55 +01:00
committed by Gerrit
25 changed files with 316 additions and 45 deletions

View File

@@ -13,8 +13,10 @@ app_objs += $(addprefix apps/,\
node_list_view_controller.o\
node_navigation_controller.o\
toolbox_controller.o\
toolbox_leaf_cell.o\
toolbox_node.o\
variable_box_controller.o\
variable_box_leaf_cell.o\
variable_box_node.o\
)

View File

@@ -22,7 +22,7 @@ void FunctionExpressionView::reloadCell() {
m_expressionView.setBackgroundColor(backgroundColor());
if (m_function) {
bool active = m_function->isActive();
KDColor textColor = active ? KDColorBlack : Palette::k_desactiveTextColor;
KDColor textColor = active ? KDColorBlack : Palette::DesactiveTextColor;
m_expressionView.setTextColor(textColor);
}
}

View File

@@ -225,7 +225,7 @@ void ListController::willDisplayCellAtLocation(TableViewCell * cell, int i, int
char bufferName[5] = "*(x)";
bufferName[0] = *function->name();
myFunctionCell->setText(bufferName);
KDColor functionNameColor = function->isActive() ? function->color() : Palette::k_desactiveTextColor;
KDColor functionNameColor = function->isActive() ? function->color() : Palette::DesactiveTextColor;
myFunctionCell->setColor(functionNameColor);
myFunctionCell->setOrientation(FunctionTitleCell::Orientation::VerticalIndicator);
} else {

View File

@@ -1,6 +1,6 @@
#include "node.h"
int Node::numberOfChildren() {
int Node::numberOfChildren() const {
return m_numberOfChildren;
}
@@ -8,6 +8,6 @@ const char * Node::label() const {
return m_label;
}
bool Node::isNull() {
bool Node::isNull() const {
return (m_label == nullptr);
}

View File

@@ -10,8 +10,8 @@ public:
};
virtual const Node * children(int index) const = 0;
const char * label() const;
int numberOfChildren();
bool isNull();
int numberOfChildren() const;
bool isNull() const;
protected:
const char * m_label;
int m_numberOfChildren;

View File

@@ -3,8 +3,9 @@
#include <assert.h>
#include <string.h>
NodeListViewController::NodeListViewController(Responder * parentResponder) :
ViewController(parentResponder),
NodeListViewController::NodeListViewController(NodeNavigationController * parent) :
ViewController(parent),
m_nodeNavigationController(parent),
m_selectableTableView(SelectableTableView(this, this)),
m_nodeModel(nullptr),
m_firstSelectedRow(0)
@@ -63,9 +64,9 @@ TableViewCell * NodeListViewController::reusableCell(int index, int type) {
assert(index >= 0);
assert(index < k_maxNumberOfDisplayedRows);
if (type == 0) {
return &m_commandCells[index];
return m_nodeNavigationController->leafCellAtIndex(index);
}
return &m_menuCells[index];
return m_nodeNavigationController->nodeCellAtIndex(index);
}
int NodeListViewController::reusableCellCount(int type) {
@@ -74,8 +75,7 @@ int NodeListViewController::reusableCellCount(int type) {
}
void NodeListViewController::willDisplayCellForIndex(TableViewCell * cell, int index) {
MenuListCell * myCell = (MenuListCell *)cell;
myCell->setText(m_nodeModel->children(index)->label());
m_nodeNavigationController->willDisplayCellForIndex(cell, index);
}
KDCoordinate NodeListViewController::rowHeight(int j) {

View File

@@ -8,9 +8,11 @@
* where we are located. It enables to know which rows are leaves and which are
* subtrees. */
class NodeNavigationController;
class NodeListViewController : public ViewController, public ListViewDataSource {
public:
NodeListViewController(Responder * parentResponder);
NodeListViewController(NodeNavigationController * parent);
View * view() override;
const char * title() const override;
void didBecomeFirstResponder() override;
@@ -31,12 +33,11 @@ public:
void setVerticalScroll(KDCoordinate verticalScroll);
KDCoordinate verticalScroll();
void deselectTable();
private:
constexpr static int k_maxNumberOfDisplayedRows = 6; //240/40
private:
constexpr static KDCoordinate k_leafRowHeight = 50;
constexpr static KDCoordinate k_nodeRowHeight = 40;
MenuListCell m_commandCells[k_maxNumberOfDisplayedRows];
ChevronMenuListCell m_menuCells[k_maxNumberOfDisplayedRows];
NodeNavigationController * m_nodeNavigationController;
SelectableTableView m_selectableTableView;
Node * m_nodeModel;
int m_firstSelectedRow;

View File

@@ -65,7 +65,7 @@ void NodeNavigationController::Stack::resetStack() {
/* NodeNavigationController */
NodeNavigationController::NodeNavigationController() :
StackViewController(nullptr, &m_listViewController, true),
StackViewController(nullptr, &m_listViewController, true, KDColorWhite, Palette::BoxTitleBackgroundColor, Palette::BoxTitleBackgroundColor),
m_listViewController(NodeListViewController(this))
{
}
@@ -131,3 +131,6 @@ void NodeNavigationController::didBecomeFirstResponder() {
void NodeNavigationController::setTextFieldCaller(TextField * textField) {
m_textFieldCaller = textField;
}
void NodeNavigationController::willDisplayCellForIndex(TableViewCell * cell, int index) {
}

View File

@@ -12,6 +12,9 @@ public:
bool handleEvent(Ion::Events::Event event) override;
void didBecomeFirstResponder() override;
void setTextFieldCaller(TextField * textField);
virtual TableViewCell * leafCellAtIndex(int index) = 0;
virtual TableViewCell * nodeCellAtIndex(int index) = 0;
virtual void willDisplayCellForIndex(TableViewCell * cell, int index);
protected:
TextField * m_textFieldCaller;
NodeListViewController m_listViewController;

View File

@@ -6,16 +6,16 @@
* and the text which would be edited by clicking on the row. When the node is a
* subtree, the edited text is set at nullptr. */
const ToolboxNode calculChildren[4] = {ToolboxNode("Nombre derivee", "diff(,)"), ToolboxNode("Integrale", "Int(,,)"), ToolboxNode("Somme", "sum(,,)"), ToolboxNode("Produit", "Product(,,)")};
const ToolboxNode complexChildren[5] = {ToolboxNode("Module", "abs()"), ToolboxNode("Argument", "arg()"), ToolboxNode("Partie reelle", "re()"), ToolboxNode("Partie imaginaire", "im()"), ToolboxNode("Conjugue", "conj()")};
const ToolboxNode probabilityChildren[4] = {ToolboxNode("Combinaison", "binomial()"), ToolboxNode("Arrangement", "permute(,)"), ToolboxNode("Nombre aleatoire", "random(,)"), ToolboxNode("Fonction gamma", "gamma()")};
const ToolboxNode arithmeticChildren[4] = {ToolboxNode("PGCD", "gcd()"), ToolboxNode("PPCM","lcm()"), ToolboxNode("Reste division euclidienne", "rem()"), ToolboxNode("Quotien division euclidienne", "quo()")};
const ToolboxNode matricesChildren[5] = {ToolboxNode("Inverse", "inverse()"), ToolboxNode("Determinant", "det()"), ToolboxNode("Transposee", "transpose()"), ToolboxNode("Trace", "trace()"), ToolboxNode("Taille", "dim()")};
const ToolboxNode listesChildren[5] = {ToolboxNode("Tri croissant", "sort<()"), ToolboxNode("Tri decroissant", "sort>()"), ToolboxNode("Maximum", "max()"), ToolboxNode("Minimum", "min()"), ToolboxNode("Taille", "dim()")};
const ToolboxNode approximationChildren[4] = {ToolboxNode("Partie entiere", "floor()"), ToolboxNode("Partie fractionnaire", "frac()"), ToolboxNode("Plafond", "ceil()"), ToolboxNode("Arrondi", "round(,)")};
const ToolboxNode trigonometryChildren[6] = {ToolboxNode("cosh", "cosh()"), ToolboxNode("sinh", "sinh()"), ToolboxNode("tanh", "tanh()"), ToolboxNode("acosh", "acosh()"), ToolboxNode("asinh", "asinh()"), ToolboxNode("atanh", "atanh()")};
const ToolboxNode calculChildren[4] = {ToolboxNode("diff(,)", "Nombre derivee"), ToolboxNode("Int(,,)", "Integrale"), ToolboxNode("sum(,,)", "Somme"), ToolboxNode("Product(,,)", "Produit")};
const ToolboxNode complexChildren[5] = {ToolboxNode("abs()", "Module"), ToolboxNode("arg()", "Argument"), ToolboxNode("re()", "Partie reelle"), ToolboxNode("im()", "Partie imaginaire"), ToolboxNode("conj()", "Conjugue")};
const ToolboxNode probabilityChildren[4] = {ToolboxNode("binomial()", "Combinaison"), ToolboxNode("permute(,)", "Arrangement"), ToolboxNode("random(,)", "Nombre aleatoire"), ToolboxNode("gamma()", "Fonction gamma")};
const ToolboxNode arithmeticChildren[4] = {ToolboxNode("gcd()", "PGCD"), ToolboxNode("lcm()", "PPCM"), ToolboxNode("rem()", "Reste division euclidienne"), ToolboxNode("quo()","Quotien division euclidienne")};
const ToolboxNode matricesChildren[5] = {ToolboxNode("inverse()", "Inverse"), ToolboxNode("det()", "Determinant"), ToolboxNode("transpose()", "Transposee"), ToolboxNode("trace()", "Trace"), ToolboxNode("dim()", "Taille")};
const ToolboxNode listesChildren[5] = {ToolboxNode("sort<()", "Tri croissant"), ToolboxNode("sort>()", "Tri decroissant"), ToolboxNode("max()", "Maximum"), ToolboxNode("min()", "Minimum"), ToolboxNode("dim()", "Taille")};
const ToolboxNode approximationChildren[4] = {ToolboxNode("floor()", "Partie entiere"), ToolboxNode("frac()", "Partie fractionnaire"), ToolboxNode("ceil()", "Plafond"), ToolboxNode("round(,)", "Arrondi")};
const ToolboxNode trigonometryChildren[6] = {ToolboxNode("cosh()", "cosh"), ToolboxNode("sinh()", "sinh"), ToolboxNode("tanh()", "tanh"), ToolboxNode("acosh()", "acosh"), ToolboxNode("asinh()", "asinh"), ToolboxNode("atanh()", "atanh")};
const ToolboxNode menu[11] = {ToolboxNode("|x|", "abs()"), ToolboxNode("root(x)", "root(,)"), ToolboxNode("log(x)", "log(,)"),
const ToolboxNode menu[11] = {ToolboxNode("abs()", "Valeur absolue"), ToolboxNode("root(,)", "Nombre derivee"), ToolboxNode("log(,)", "Logarithme base a"),
ToolboxNode("Calcul", nullptr, calculChildren, 4), ToolboxNode("Nombre complexe", nullptr, complexChildren, 5),
ToolboxNode("Probabilite", nullptr, probabilityChildren, 4), ToolboxNode("Arithmetique", nullptr, arithmeticChildren, 4),
ToolboxNode("Matrice", nullptr, matricesChildren, 5), ToolboxNode("Liste", nullptr, listesChildren, 5),
@@ -26,6 +26,26 @@ const char * ToolboxController::title() const {
return "ToolboxController";
}
TableViewCell * ToolboxController::leafCellAtIndex(int index) {
return &m_leafCells[index];
}
TableViewCell * ToolboxController::nodeCellAtIndex(int index) {
return & m_nodeCells[index];
}
void ToolboxController::willDisplayCellForIndex(TableViewCell * cell, int index) {
ToolboxNode * node = (ToolboxNode *)m_listViewController.nodeModel()->children(index);
if (node->numberOfChildren() == 0) {
ToolboxLeafCell * myCell = (ToolboxLeafCell *)cell;
myCell->setLabel(node->label());
myCell->setSubtitle(node->text());
return;
}
MenuListCell * myCell = (MenuListCell *)cell;
myCell->setText(node->label());
}
Node * ToolboxController::nodeModel() {
return (Node *)&toolboxModel;
}
@@ -33,7 +53,7 @@ Node * ToolboxController::nodeModel() {
bool ToolboxController::selectLeaf(Node * selectedNode){
m_listViewController.deselectTable();
ToolboxNode * node = (ToolboxNode *)selectedNode;
const char * editedText = node->text();
const char * editedText = node->label();
m_textFieldCaller->appendText(editedText);
int cursorPosition = 0;
int editedTextLength = strlen(editedText);

View File

@@ -3,11 +3,17 @@
#include <escher.h>
#include "node_navigation_controller.h"
#include "toolbox_leaf_cell.h"
class ToolboxController : public NodeNavigationController {
public:
const char * title() const override;
TableViewCell * leafCellAtIndex(int index) override;
TableViewCell * nodeCellAtIndex(int index) override;
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
private:
ToolboxLeafCell m_leafCells[NodeListViewController::k_maxNumberOfDisplayedRows];
ChevronMenuListCell m_nodeCells[NodeListViewController::k_maxNumberOfDisplayedRows];
Node * nodeModel() override;
bool selectLeaf(Node * selectedNode) override;
};

View File

@@ -0,0 +1,53 @@
#include "toolbox_leaf_cell.h"
#include <assert.h>
ToolboxLeafCell::ToolboxLeafCell() :
TableViewCell(),
m_labelView(PointerTextView(nullptr, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor)),
m_subtitleView(PointerTextView(nullptr, 0, 0.5, Palette::DesactiveTextColor, Palette::CellBackgroundColor))
{
}
int ToolboxLeafCell::numberOfSubviews() const {
return 2;
}
View * ToolboxLeafCell::subviewAtIndex(int index) {
assert(index == 0 || index == 1);
if (index == 0) {
return &m_labelView;
}
return &m_subtitleView;
}
void ToolboxLeafCell::layoutSubviews() {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
m_labelView.setFrame(KDRect(1, 1, width-2, height/2 - 1));
m_subtitleView.setFrame(KDRect(1, height/2, width-2, height/2 - 1));
}
void ToolboxLeafCell::reloadCell() {
TableViewCell::reloadCell();
KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_labelView.setBackgroundColor(backgroundColor);
m_subtitleView.setBackgroundColor(backgroundColor);
}
void ToolboxLeafCell::setLabel(const char * text) {
m_labelView.setText(text);
}
void ToolboxLeafCell::setSubtitle(const char * text) {
m_subtitleView.setText(text);
}
void ToolboxLeafCell::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
ctx->fillRect(KDRect(1, 0, width-2, height-1), backgroundColor);
ctx->fillRect(KDRect(0, height-1, width, 1), Palette::LineColor);
ctx->fillRect(KDRect(0, 0, 1, height-1), Palette::LineColor);
ctx->fillRect(KDRect(width-1, 0, 1, height-1), Palette::LineColor);
}

21
apps/toolbox_leaf_cell.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef APPS_TOOLBOX_LEAF_CELL_H
#define APPS_TOOLBOX_LEAF_CELL_H
#include <escher.h>
class ToolboxLeafCell : public TableViewCell {
public:
ToolboxLeafCell();
void reloadCell() override;
void setLabel(const char * text);
void setSubtitle(const char * text);
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
PointerTextView m_labelView;
PointerTextView m_subtitleView;
};
#endif

View File

@@ -19,6 +19,19 @@ const char * VariableBoxController::title() const {
return "VariableBoxController";
}
TableViewCell * VariableBoxController::leafCellAtIndex(int index) {
return &m_leafCells[index];
}
TableViewCell * VariableBoxController::nodeCellAtIndex(int index) {
return &m_nodeCells[index];
}
void VariableBoxController::willDisplayCellForIndex(TableViewCell * cell, int index) {
MenuListCell * myCell = (MenuListCell *)cell;
myCell->setText(m_listViewController.nodeModel()->children(index)->label());
}
Node * VariableBoxController::nodeModel() {
return (Node *)&variableBoxModel;
}

View File

@@ -7,7 +7,12 @@
class VariableBoxController : public NodeNavigationController {
public:
const char * title() const override;
TableViewCell * leafCellAtIndex(int index) override;
TableViewCell * nodeCellAtIndex(int index) override;
void willDisplayCellForIndex(TableViewCell * cell, int index) override;
private:
MenuListCell m_leafCells[NodeListViewController::k_maxNumberOfDisplayedRows];
ChevronMenuListCell m_nodeCells[NodeListViewController::k_maxNumberOfDisplayedRows];
Node * nodeModel() override;
bool selectLeaf(Node * selectedNode) override;
};

View File

@@ -0,0 +1,70 @@
#include "variable_box_leaf_cell.h"
#include <assert.h>
VariableBoxLeafCell::VariableBoxLeafCell() :
TableViewCell(),
m_labelView(PointerTextView(nullptr, 0, 0.5, KDColorBlack, Palette::CellBackgroundColor)),
m_subtitleView(BufferTextView(0, 0.5, Palette::DesactiveTextColor, Palette::CellBackgroundColor))
{
}
int VariableBoxLeafCell::numberOfSubviews() const {
if (strlen(m_subtitleView.text()) > 0) {
return 3;
}
return 2;
}
View * VariableBoxLeafCell::subviewAtIndex(int index) {
if (index == 0) {
return &m_labelView;
}
if (index == 1) {
return &m_expressionView;
}
assert(numberOfSubviews() == 3 && index == 2);
return &m_subtitleView;
}
void VariableBoxLeafCell::layoutSubviews() {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
m_expressionView.setFrame(KDRect(width/2, 1, width/2-1, height-2));
if (numberOfSubviews() == 3) {
m_labelView.setFrame(KDRect(1, 1, width/2-1, height/2 - 1));
m_subtitleView.setFrame(KDRect(1, height/2, width/2-1, height/2 - 1));
return;
}
m_labelView.setFrame(KDRect(1, 1, width/2-1, height-2));
}
void VariableBoxLeafCell::reloadCell() {
TableViewCell::reloadCell();
KDColor backgroundColor = isHighlighted()? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
m_labelView.setBackgroundColor(backgroundColor);
m_subtitleView.setBackgroundColor(backgroundColor);
m_expressionView.setBackgroundColor(backgroundColor);
}
void VariableBoxLeafCell::setLabel(const char * text) {
m_labelView.setText(text);
}
void VariableBoxLeafCell::setSubtitle(const char * text) {
m_subtitleView.setText(text);
layoutSubviews();
}
void VariableBoxLeafCell::setExpression(ExpressionLayout * expressionLayout) {
m_expressionView.setExpression(expressionLayout);
}
void VariableBoxLeafCell::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDColor backgroundColor = isHighlighted() ? Palette::FocusCellBackgroundColor : Palette::CellBackgroundColor;
ctx->fillRect(KDRect(1, 0, width-2, height-1), backgroundColor);
ctx->fillRect(KDRect(0, height-1, width, 1), Palette::LineColor);
ctx->fillRect(KDRect(0, 0, 1, height-1), Palette::LineColor);
ctx->fillRect(KDRect(width-1, 0, 1, height-1), Palette::LineColor);
}

View File

@@ -0,0 +1,23 @@
#ifndef APPS_VARIABLE_BOX_LEAF_CELL_H
#define APPS_VARIABLE_BOX_LEAF_CELL_H
#include <escher.h>
class VariableBoxLeafCell : public TableViewCell {
public:
VariableBoxLeafCell();
void reloadCell() override;
void setLabel(const char * text);
void setSubtitle(const char * text);
void setExpression(ExpressionLayout * expressionLayout);
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
PointerTextView m_labelView;
BufferTextView m_subtitleView;
ExpressionView m_expressionView;
};
#endif

View File

@@ -9,7 +9,8 @@ public:
constexpr static KDColor BackgroundColor = KDColor(0xF0F3F5);
constexpr static KDColor CellBackgroundColor = KDColor(0xFCFCFC);
constexpr static KDColor FocusCellBackgroundColor = KDColor(0xBFD3EB);
constexpr static KDColor k_desactiveTextColor = KDColor(0x646464);
constexpr static KDColor DesactiveTextColor = KDColor(0x646464);
constexpr static KDColor BoxTitleBackgroundColor = KDColor(0x656976);
};
#endif

View File

@@ -2,19 +2,28 @@
#define ESCHER_STACK_VIEW_H
#include <escher/view.h>
#include <escher/pointer_text_view.h>
class StackView : public View {
public:
StackView();
void drawRect(KDContext * ctx, KDRect rect) const override;
void setName(const char * name);
void setTextColor(KDColor textColor);
void setBackgroundColor(KDColor backgroundColor);
void setSeparatorColor(KDColor separatorColor);
protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
void logAttributes(std::ostream &os) const override;
#endif
private:
const char * m_name;
KDColor m_backgroundColor;
KDColor m_separatorColor;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
PointerTextView m_textView;
};
#endif

View File

@@ -3,12 +3,14 @@
#include <escher/view_controller.h>
#include <escher/stack_view.h>
#include <escher/palette.h>
constexpr uint8_t kMaxNumberOfStacks = 4;
class StackViewController : public ViewController {
public:
StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader = false);
StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader = false,
KDColor textColor = Palette::DesactiveTextColor, KDColor backgroundColor = KDColorWhite, KDColor separatorColor = Palette::LineColor);
/* Push creates a new StackView and adds it */
void push(ViewController * vc);
@@ -22,7 +24,7 @@ public:
private:
class ControllerView : public View {
public:
ControllerView(bool displayFirstStackHeader);
ControllerView(bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor);
void setContentView(View * view);
void pushStack(const char * name);
void popStack();
@@ -39,6 +41,9 @@ private:
View * m_contentView;
int8_t m_numberOfStacks;
bool m_displayFirstStackHeader;
KDColor m_textColor;
KDColor m_backgroundColor;
KDColor m_separatorColor;
};
ControllerView m_view;

View File

@@ -6,7 +6,7 @@
class TextMenuListCell : public MenuListCell {
public:
TextMenuListCell(char * label);
TextMenuListCell(char * label = nullptr);
void reloadCell() override;
View * accessoryView() const override;
void setHighlighted(bool highlight);

View File

@@ -4,4 +4,5 @@ constexpr KDColor Palette::LineColor;
constexpr KDColor Palette::BackgroundColor;
constexpr KDColor Palette::CellBackgroundColor;
constexpr KDColor Palette::FocusCellBackgroundColor;
constexpr KDColor Palette::k_desactiveTextColor;
constexpr KDColor Palette::DesactiveTextColor;
constexpr KDColor Palette::BoxTitleBackgroundColor;

View File

@@ -5,18 +5,46 @@ extern "C" {
StackView::StackView() :
View(),
m_name(nullptr)
m_textView(PointerTextView(nullptr, 0.5f, 0.5f))
{
}
void StackView::setTextColor(KDColor textColor) {
m_textView.setTextColor(textColor);
}
void StackView::setBackgroundColor(KDColor backgroundColor) {
m_textView.setBackgroundColor(backgroundColor);
m_backgroundColor = backgroundColor;
}
void StackView::setSeparatorColor(KDColor separatorColor) {
m_separatorColor = separatorColor;
}
int StackView::numberOfSubviews() const {
return 1;
}
View * StackView::subviewAtIndex(int index) {
assert(index == 0);
return &m_textView;
}
void StackView::layoutSubviews() {
m_textView.setFrame(bounds());
}
void StackView::setName(const char * name) {
m_name = name;
markRectAsDirty(bounds());
m_textView.setText(name);
}
void StackView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, KDColor(0xFFCD50));
ctx->drawString(m_name, KDPointZero);
KDCoordinate height = bounds().height();
KDCoordinate width = bounds().width();
ctx->fillRect(KDRect(0, 0, width, 1), m_separatorColor);
ctx->fillRect(KDRect(0, 1, width, height-2), m_backgroundColor);
ctx->fillRect(KDRect(0, height-1, width, 1), m_separatorColor);
}
#if ESCHER_VIEW_LOGGING

View File

@@ -4,11 +4,14 @@ extern "C" {
#include <escher/stack_view_controller.h>
#include <escher/app.h>
StackViewController::ControllerView::ControllerView(bool displayFirstStackHeader) :
StackViewController::ControllerView::ControllerView(bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) :
View(),
m_contentView(nullptr),
m_numberOfStacks(0),
m_displayFirstStackHeader(displayFirstStackHeader)
m_displayFirstStackHeader(displayFirstStackHeader),
m_textColor(textColor),
m_backgroundColor(backgroundColor),
m_separatorColor(separatorColor)
{
}
@@ -20,6 +23,9 @@ void StackViewController::ControllerView::setContentView(View * view) {
void StackViewController::ControllerView::pushStack(const char * name) {
m_stackViews[m_numberOfStacks].setName(name);
m_stackViews[m_numberOfStacks].setTextColor(m_textColor);
m_stackViews[m_numberOfStacks].setBackgroundColor(m_backgroundColor);
m_stackViews[m_numberOfStacks].setSeparatorColor(m_separatorColor);
m_numberOfStacks++;
}
@@ -33,10 +39,11 @@ void StackViewController::ControllerView::layoutSubviews() {
KDCoordinate width = m_frame.width();
int indexFirstHeader = m_displayFirstStackHeader ? 0 : 1;
for (int i=indexFirstHeader; i<m_numberOfStacks; i++) {
m_stackViews[i].setFrame(KDRect(0, stackHeight*(i-indexFirstHeader), width, stackHeight));
m_stackViews[i].setFrame(KDRect(0, stackHeight*(i-indexFirstHeader), width, stackHeight + 1));
}
if (m_contentView) {
KDRect contentViewFrame = KDRect( 0, (m_numberOfStacks-indexFirstHeader)*stackHeight,
bool separatorHeight = m_displayFirstStackHeader + (m_numberOfStacks > 1);
KDRect contentViewFrame = KDRect( 0, (m_numberOfStacks-indexFirstHeader)*stackHeight + separatorHeight,
width, m_frame.height() - (m_numberOfStacks-indexFirstHeader)*stackHeight);
m_contentView->setFrame(contentViewFrame);
}
@@ -62,9 +69,9 @@ const char * StackViewController::ControllerView::className() const {
}
#endif
StackViewController::StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader) :
StackViewController::StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) :
ViewController(parentResponder),
m_view(ControllerView(displayFirstStackHeader)),
m_view(ControllerView(displayFirstStackHeader, textColor, backgroundColor, separatorColor)),
m_numberOfChildren(0),
m_rootViewController(rootViewController)
{

View File

@@ -99,7 +99,7 @@ void TextField::appendText(const char * text) {
if (m_currentTextLength + textSize > m_textBufferSize) {
return;
}
for (int k = m_currentTextLength; k > m_currentCursorPosition - 1; k--) {
for (int k = m_currentTextLength; k >= m_currentCursorPosition && k >= 0; k--) {
m_textBuffer[k+textSize] = m_textBuffer[k];
}
strlcpy(&m_textBuffer[m_currentCursorPosition], text, textSize);