mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[code] Add parentheses after function names in Var.
Change-Id: I7e3e993d07139c40c6bd59fd5879b3ee091f5127
This commit is contained in:
@@ -8,13 +8,13 @@ app_objs += $(addprefix apps/code/,\
|
||||
console_edit_cell.o\
|
||||
console_line_cell.o\
|
||||
console_store.o\
|
||||
double_buffer_text_cell.o\
|
||||
editor_controller.o\
|
||||
helpers.o\
|
||||
menu_controller.o\
|
||||
python_toolbox.o\
|
||||
sandbox_controller.o\
|
||||
script.o\
|
||||
script_node_cell.o\
|
||||
script_parameter_controller.o\
|
||||
script_store.o\
|
||||
script_template.o\
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#include "double_buffer_text_cell.h"
|
||||
#include <escher/palette.h>
|
||||
#include <assert.h>
|
||||
|
||||
DoubleBufferTextCell::DoubleBufferTextCell(KDText::FontSize size, float horizontalAlignment, float verticalAlignment) :
|
||||
TableCell(TableCell::Layout::Vertical),
|
||||
m_firstBufferTextView(size, horizontalAlignment, verticalAlignment),
|
||||
m_secondBufferTextView(size, horizontalAlignment, verticalAlignment)
|
||||
{
|
||||
}
|
||||
|
||||
const char * DoubleBufferTextCell::firstText() {
|
||||
return m_firstBufferTextView.text();
|
||||
}
|
||||
|
||||
const char * DoubleBufferTextCell::secondText() {
|
||||
return m_secondBufferTextView.text();
|
||||
}
|
||||
|
||||
void DoubleBufferTextCell::setFirstText(const char * textContent) {
|
||||
m_firstBufferTextView.setText(textContent);
|
||||
}
|
||||
|
||||
void DoubleBufferTextCell::setSecondText(const char * textContent) {
|
||||
m_secondBufferTextView.setText(textContent);
|
||||
}
|
||||
|
||||
void DoubleBufferTextCell::setFirstTextColor(KDColor textColor) {
|
||||
m_firstBufferTextView.setTextColor(textColor);
|
||||
}
|
||||
|
||||
void DoubleBufferTextCell::setSecondTextColor(KDColor textColor) {
|
||||
m_secondBufferTextView.setTextColor(textColor);
|
||||
}
|
||||
|
||||
void DoubleBufferTextCell::setHighlighted(bool highlight) {
|
||||
HighlightCell::setHighlighted(highlight);
|
||||
KDColor background = isHighlighted() ? Palette::Select : KDColorWhite;
|
||||
m_firstBufferTextView.setBackgroundColor(background);
|
||||
m_secondBufferTextView.setBackgroundColor(background);
|
||||
}
|
||||
|
||||
View * DoubleBufferTextCell::subviewAtIndex(int index) {
|
||||
assert(index >= 0 && index <= 1);
|
||||
if (index == 0) {
|
||||
return &m_firstBufferTextView;
|
||||
}
|
||||
return &m_secondBufferTextView;
|
||||
}
|
||||
|
||||
void DoubleBufferTextCell::layoutSubviews() {
|
||||
TableCell::layoutSubviews();
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef CODE_DOUBLE_BUFFER_TEXT_CELL_H
|
||||
#define CODE_DOUBLE_BUFFER_TEXT_CELL_H
|
||||
|
||||
#include <escher/table_cell.h>
|
||||
#include <escher/buffer_text_view.h>
|
||||
|
||||
class DoubleBufferTextCell : public TableCell {
|
||||
public:
|
||||
DoubleBufferTextCell(KDText::FontSize size = KDText::FontSize::Small, float horizontalAlignment = 0.0f, float verticalAlignment = 0.5f);
|
||||
const char * firstText();
|
||||
const char * secondText();
|
||||
void setFirstText(const char * textContent);
|
||||
void setSecondText(const char * textContent);
|
||||
void setFirstTextColor(KDColor textColor);
|
||||
void setSecondTextColor(KDColor textColor);
|
||||
|
||||
/* TableCell */
|
||||
View * labelView() const override { return const_cast<View *>(static_cast<const View *>(&m_firstBufferTextView)); }
|
||||
View * accessoryView() const override { return const_cast<View *>(static_cast<const View *>(&m_secondBufferTextView)); }
|
||||
|
||||
/* HighlightCell */
|
||||
void setHighlighted(bool highlight) override;
|
||||
|
||||
/* View */
|
||||
int numberOfSubviews() const override { return 2; }
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
protected:
|
||||
BufferTextView m_firstBufferTextView;
|
||||
BufferTextView m_secondBufferTextView;
|
||||
};
|
||||
|
||||
#endif
|
||||
35
apps/code/script_node.h
Normal file
35
apps/code/script_node.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef CODE_SCRIPT_NODE_H
|
||||
#define CODE_SCRIPT_NODE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Code {
|
||||
|
||||
class ScriptNode {
|
||||
public:
|
||||
enum class Type {
|
||||
Function = 0,
|
||||
Variable = 1
|
||||
};
|
||||
ScriptNode() :
|
||||
m_type(Type::Function), m_name(nullptr), m_scriptIndex(0) {}
|
||||
static ScriptNode FunctionNode(const char * name, uint16_t scriptIndex) {
|
||||
return ScriptNode(Type::Function, name, scriptIndex);
|
||||
}
|
||||
static ScriptNode VariableNode(const char * name, uint16_t scriptIndex) {
|
||||
return ScriptNode(Type::Variable, name, scriptIndex);
|
||||
}
|
||||
Type type() const { return m_type; }
|
||||
const char * name() const { return m_name; }
|
||||
uint16_t scriptIndex() const { return m_scriptIndex; }
|
||||
private:
|
||||
ScriptNode(Type type, const char * name, uint16_t scriptIndex) :
|
||||
m_type(type), m_name(name), m_scriptIndex(scriptIndex) {}
|
||||
Type m_type;
|
||||
const char * m_name;
|
||||
uint16_t m_scriptIndex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
69
apps/code/script_node_cell.cpp
Normal file
69
apps/code/script_node_cell.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "script_node_cell.h"
|
||||
#include <kandinsky/point.h>
|
||||
#include <escher/metric.h>
|
||||
|
||||
namespace Code {
|
||||
|
||||
constexpr char ScriptNodeCell::k_parentheses[];
|
||||
|
||||
ScriptNodeCell::ScriptNodeView::ScriptNodeView() :
|
||||
HighlightCell(),
|
||||
m_scriptNode(nullptr),
|
||||
m_scriptStore(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void ScriptNodeCell::ScriptNodeView::setScriptNode(ScriptNode * scriptNode) {
|
||||
m_scriptNode = scriptNode;
|
||||
}
|
||||
|
||||
void ScriptNodeCell::ScriptNodeView::setScriptStore(ScriptStore * scriptStore) {
|
||||
m_scriptStore = scriptStore;
|
||||
}
|
||||
|
||||
void ScriptNodeCell::ScriptNodeView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->drawString(m_scriptNode->name(), KDPoint(0, Metric::TableCellLabelTopMargin), k_fontSize, KDColorBlack, isHighlighted()? Palette::Select : KDColorWhite);
|
||||
KDSize nameSize = KDText::stringSize(m_scriptNode->name(), k_fontSize);
|
||||
if (m_scriptNode->type() == ScriptNode::Type::Function) {
|
||||
ctx->drawString(ScriptNodeCell::k_parentheses, KDPoint(nameSize.width(), Metric::TableCellLabelTopMargin), k_fontSize, KDColorBlack, isHighlighted()? Palette::Select : KDColorWhite);
|
||||
}
|
||||
ctx->drawString(m_scriptStore->scriptAtIndex(m_scriptNode->scriptIndex()).name(), KDPoint(0, Metric::TableCellLabelTopMargin + nameSize.height() + k_verticalMargin), k_fontSize, Palette::GreyDark, isHighlighted()? Palette::Select : KDColorWhite);
|
||||
}
|
||||
|
||||
KDSize ScriptNodeCell::ScriptNodeView::minimalSizeForOptimalDisplay() const {
|
||||
KDSize size1 = KDText::stringSize(m_scriptNode->name(), k_fontSize);
|
||||
KDSize size2 = KDText::stringSize(m_scriptStore->scriptAtIndex(m_scriptNode->scriptIndex()).name(), k_fontSize);
|
||||
KDSize size3 = KDSizeZero;
|
||||
if (m_scriptNode->type() == ScriptNode::Type::Function) {
|
||||
size3 = KDText::stringSize(ScriptNodeCell::k_parentheses, k_fontSize);
|
||||
}
|
||||
return KDSize(size1.width() + size3.width() > size2.width() ? size1.width() + size3.width() : size2.width(), Metric::TableCellLabelTopMargin + size1.width() + k_verticalMargin + size2.width());
|
||||
}
|
||||
|
||||
ScriptNodeCell::ScriptNodeCell() :
|
||||
TableCell(),
|
||||
m_scriptNodeView()
|
||||
{
|
||||
}
|
||||
|
||||
void ScriptNodeCell::setScriptNode(ScriptNode * scriptNode) {
|
||||
m_scriptNodeView.setScriptNode(scriptNode);
|
||||
reloadCell();
|
||||
}
|
||||
|
||||
void ScriptNodeCell::setScriptStore(ScriptStore * scriptStore) {
|
||||
m_scriptNodeView.setScriptStore(scriptStore);
|
||||
reloadCell();
|
||||
}
|
||||
|
||||
void ScriptNodeCell::setHighlighted(bool highlight) {
|
||||
TableCell::setHighlighted(highlight);
|
||||
m_scriptNodeView.setHighlighted(highlight);
|
||||
}
|
||||
|
||||
void ScriptNodeCell::reloadCell() {
|
||||
layoutSubviews();
|
||||
HighlightCell::reloadCell();
|
||||
}
|
||||
|
||||
}
|
||||
44
apps/code/script_node_cell.h
Normal file
44
apps/code/script_node_cell.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef CODE_SCRIPT_NODE_CELL_H
|
||||
#define CODE_SCRIPT_NODE_CELL_H
|
||||
|
||||
#include "script_node.h"
|
||||
#include "script_store.h"
|
||||
#include <escher/table_cell.h>
|
||||
#include <kandinsky/coordinate.h>
|
||||
|
||||
namespace Code {
|
||||
|
||||
class ScriptNodeCell : public TableCell {
|
||||
public:
|
||||
ScriptNodeCell();
|
||||
void setScriptNode(ScriptNode * node);
|
||||
void setScriptStore(ScriptStore * scriptStore);
|
||||
|
||||
/* TableCell */
|
||||
View * labelView() const override { return const_cast<View *>(static_cast<const View *>(&m_scriptNodeView)); }
|
||||
|
||||
/* HighlightCell */
|
||||
void setHighlighted(bool highlight) override;
|
||||
void reloadCell() override;
|
||||
|
||||
constexpr static char k_parentheses[] = "()";
|
||||
protected:
|
||||
class ScriptNodeView : public HighlightCell {
|
||||
public:
|
||||
ScriptNodeView();
|
||||
void setScriptNode(ScriptNode * scriptNode);
|
||||
void setScriptStore(ScriptStore * scriptStore);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
virtual KDSize minimalSizeForOptimalDisplay() const override;
|
||||
private:
|
||||
constexpr static KDText::FontSize k_fontSize = KDText::FontSize::Small;
|
||||
constexpr static KDCoordinate k_verticalMargin = 7;
|
||||
ScriptNode * m_scriptNode;
|
||||
ScriptStore * m_scriptStore;
|
||||
};
|
||||
ScriptNodeView m_scriptNodeView;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -20,8 +20,7 @@ VariableBoxController::ContentViewController::ContentViewController(Responder *
|
||||
m_selectableTableView(this, this, 0, 1, 0, 0, 0, 0, this, nullptr, false)
|
||||
{
|
||||
for (int i = 0; i < k_maxNumberOfDisplayedRows; i++) {
|
||||
m_leafCells[i].setFirstTextColor(KDColorBlack);
|
||||
m_leafCells[i].setSecondTextColor(Palette::GreyDark);
|
||||
m_leafCells[i].setScriptStore(scriptStore);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +86,11 @@ bool VariableBoxController::ContentViewController::handleEvent(Ion::Events::Even
|
||||
return true;
|
||||
}
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
|
||||
DoubleBufferTextCell * selectedTextCell = static_cast<DoubleBufferTextCell *>(m_selectableTableView.selectedCell());
|
||||
insertTextInCaller(selectedTextCell->firstText());
|
||||
ScriptNode selectedScriptNode = m_scriptNodes[m_selectableTableView.selectedRow()];
|
||||
insertTextInCaller(selectedScriptNode.name());
|
||||
if (selectedScriptNode.type() == ScriptNode::Type::Function) {
|
||||
insertTextInCaller(ScriptNodeCell::k_parentheses);
|
||||
}
|
||||
m_selectableTableView.deselectTable();
|
||||
app()->dismissModalViewController();
|
||||
return true;
|
||||
@@ -112,9 +114,8 @@ int VariableBoxController::ContentViewController::reusableCellCount(int type) {
|
||||
}
|
||||
|
||||
void VariableBoxController::ContentViewController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
DoubleBufferTextCell * myCell = static_cast<DoubleBufferTextCell *>(cell);
|
||||
myCell->setFirstText(m_scriptNodes[index].name());
|
||||
myCell->setSecondText(m_scriptStore->scriptAtIndex(m_scriptNodes[index].scriptIndex()).name());
|
||||
ScriptNodeCell * myCell = static_cast<ScriptNodeCell *>(cell);
|
||||
myCell->setScriptNode(&m_scriptNodes[index]);
|
||||
}
|
||||
|
||||
KDCoordinate VariableBoxController::ContentViewController::rowHeight(int index) {
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
#define CODE_VARIABLE_BOX_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "double_buffer_text_cell.h"
|
||||
#include "menu_controller.h"
|
||||
#include "script_node.h"
|
||||
#include "script_node_cell.h"
|
||||
#include "script_store.h"
|
||||
|
||||
namespace Code {
|
||||
@@ -47,31 +48,6 @@ private:
|
||||
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
|
||||
int typeAtLocation(int i, int j) override;
|
||||
private:
|
||||
class ScriptNode {
|
||||
public:
|
||||
enum class Type {
|
||||
Function = 0,
|
||||
Variable = 1
|
||||
};
|
||||
ScriptNode() :
|
||||
m_type(Type::Function), m_name(nullptr), m_scriptIndex(0) {}
|
||||
static ScriptNode FunctionNode(const char * name, uint16_t scriptIndex) {
|
||||
return ScriptNode(Type::Function, name, scriptIndex);
|
||||
}
|
||||
static ScriptNode VariableNode(const char * name, uint16_t scriptIndex) {
|
||||
return ScriptNode(Type::Variable, name, scriptIndex);
|
||||
}
|
||||
Type type() const { return m_type; }
|
||||
const char * name() const { return m_name; }
|
||||
uint16_t scriptIndex() const { return m_scriptIndex; }
|
||||
private:
|
||||
ScriptNode(Type type, const char * name, uint16_t scriptIndex) :
|
||||
m_type(type), m_name(name), m_scriptIndex(scriptIndex) {}
|
||||
Type m_type;
|
||||
const char * m_name;
|
||||
uint16_t m_scriptIndex;
|
||||
};
|
||||
|
||||
constexpr static int k_maxNumberOfDisplayedRows = 6; //240/40
|
||||
constexpr static int k_leafType = 0;
|
||||
constexpr static int k_maxScriptNodesCount = 32;
|
||||
@@ -82,7 +58,7 @@ private:
|
||||
ScriptStore * m_scriptStore;
|
||||
TextField * m_textFieldCaller;
|
||||
TextArea * m_textAreaCaller;
|
||||
DoubleBufferTextCell m_leafCells[k_maxNumberOfDisplayedRows];
|
||||
ScriptNodeCell m_leafCells[k_maxNumberOfDisplayedRows];
|
||||
SelectableTableView m_selectableTableView;
|
||||
};
|
||||
ContentViewController m_contentViewController;
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite);
|
||||
void setText(const char * text) override;
|
||||
const char * text() const override;
|
||||
void appendText(const char * text);
|
||||
static int maxNumberOfCharsInBuffer() { return k_maxNumberOfChar; }
|
||||
private:
|
||||
static constexpr int k_maxNumberOfChar = 256;
|
||||
|
||||
@@ -18,3 +18,11 @@ void BufferTextView::setText(const char * text) {
|
||||
strlcpy(m_buffer, text, sizeof(m_buffer));
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void BufferTextView::appendText(const char * text) {
|
||||
size_t previousTextLength = strlen(m_buffer);
|
||||
size_t argTextLength = strlen(text);
|
||||
if (previousTextLength + argTextLength + 1 < k_maxNumberOfChar) {
|
||||
strlcpy(&m_buffer[previousTextLength], text, argTextLength + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user