mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] "New Matrix" item in math toolbox.
Change-Id: Iec01ffa96ec64f42d2cbc4b15b14eea7cfe4eaa4
This commit is contained in:
@@ -289,8 +289,9 @@ bool PythonToolbox::selectLeaf(ToolboxMessageTree * selectedMessageTree) {
|
||||
m_selectableTableView.deselectTable();
|
||||
ToolboxMessageTree * node = selectedMessageTree;
|
||||
const char * editedText = I18n::translate(node->insertedText());
|
||||
char strippedEditedText[strlen(editedText)+1];
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandMessage(node->insertedText(), strippedEditedText);
|
||||
int strippedEditedTextMaxLength = strlen(editedText)+1;
|
||||
char strippedEditedText[strippedEditedTextMaxLength];
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandMessage(node->insertedText(), strippedEditedText, strippedEditedTextMaxLength);
|
||||
m_action(sender(), const_cast<const char *>(strippedEditedText));
|
||||
app()->dismissModalViewController();
|
||||
return true;
|
||||
|
||||
@@ -119,8 +119,9 @@ void VariableBoxController::ContentViewController::willDisplayCellForIndex(Highl
|
||||
}
|
||||
|
||||
void VariableBoxController::ContentViewController::insertTextInCaller(const char * text) {
|
||||
char commandBuffer[strlen(text)+1];
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandText(text, commandBuffer);
|
||||
int commandBufferMaxSize = strlen(text)+1;
|
||||
char commandBuffer[commandBufferMaxSize];
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandText(text, commandBuffer, commandBufferMaxSize);
|
||||
if (m_textFieldCaller != nullptr) {
|
||||
if (!m_textFieldCaller->isEditing()) {
|
||||
m_textFieldCaller->setEditing(true);
|
||||
|
||||
@@ -36,7 +36,8 @@ const ToolboxMessageTree arithmeticChildren[4] = {
|
||||
ToolboxMessageTree(I18n::Message::QuoCommandWithArg, I18n::Message::Quotient, I18n::Message::QuoCommandWithArg)};
|
||||
|
||||
#if MATRICES_ARE_DEFINED
|
||||
const ToolboxMessageTree matricesChildren[5] = {
|
||||
const ToolboxMessageTree matricesChildren[6] = {
|
||||
ToolboxMessageTree(I18n::Message::MatrixCommandWithArg, I18n::Message::NewMatrix, I18n::Message::MatrixCommandWithArg),
|
||||
ToolboxMessageTree(I18n::Message::InverseCommandWithArg, I18n::Message::Inverse, I18n::Message::InverseCommandWithArg),
|
||||
ToolboxMessageTree(I18n::Message::DeterminantCommandWithArg, I18n::Message::Determinant, I18n::Message::DeterminantCommandWithArg),
|
||||
ToolboxMessageTree(I18n::Message::TransposeCommandWithArg, I18n::Message::Transpose, I18n::Message::TransposeCommandWithArg),
|
||||
@@ -88,7 +89,7 @@ const ToolboxMessageTree menu[10] = {
|
||||
ToolboxMessageTree(I18n::Message::Probability, I18n::Message::Default, I18n::Message::Default, probabilityChildren, 2),
|
||||
ToolboxMessageTree(I18n::Message::Arithmetic, I18n::Message::Default, I18n::Message::Default, arithmeticChildren, 4),
|
||||
#if MATRICES_ARE_DEFINED
|
||||
ToolboxMessageTree(I18n::Message::Matrices, I18n::Message::Default, I18n::Message::Default, matricesChildren, 5),
|
||||
ToolboxMessageTree(I18n::Message::Matrices, I18n::Message::Default, I18n::Message::Default, matricesChildren, 6),
|
||||
#endif
|
||||
#if LIST_ARE_DEFINED
|
||||
ToolboxMessageTree(I18n::Message::Lists, I18n::Message::Default, I18n::Message::Default, listesChildren, 5),
|
||||
@@ -119,8 +120,9 @@ void MathToolbox::actionForEditableExpressionView(void * sender, ToolboxMessageT
|
||||
EditableExpressionView * expressionLayoutEditorSender = static_cast<EditableExpressionView *>(sender);
|
||||
// Translate the message and replace the arguments with Empty chars.
|
||||
const char * textToInsert = I18n::translate(messageTree->insertedText());
|
||||
int strippedTextToInsertMaxLength = strlen(textToInsert);
|
||||
char strippedTextToInsert[strlen(textToInsert)];
|
||||
Shared::ToolboxHelpers::TextToParseIntoLayoutForCommandMessage(messageTree->insertedText(), strippedTextToInsert);
|
||||
Shared::ToolboxHelpers::TextToParseIntoLayoutForCommandMessage(messageTree->insertedText(), strippedTextToInsert, strippedTextToInsertMaxLength);
|
||||
// Create the layout
|
||||
Expression * resultExpression = Expression::parse(strippedTextToInsert);
|
||||
if (resultExpression == nullptr) {
|
||||
@@ -156,9 +158,10 @@ void MathToolbox::actionForTextfield(void * sender, ToolboxMessageTree * message
|
||||
textFieldSender->setEditing(true);
|
||||
}
|
||||
const char * textToInsert = I18n::translate(messageTree->insertedText());
|
||||
char strippedTextToInsert[strlen(textToInsert)];
|
||||
int textToInsertLength = strlen(textToInsert);
|
||||
char strippedTextToInsert[textToInsertLength];
|
||||
// Translate the message and remove the arguments.
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandMessage(messageTree->insertedText(), strippedTextToInsert);
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandMessage(messageTree->insertedText(), strippedTextToInsert, textToInsertLength);
|
||||
textFieldSender->insertTextAtLocation(strippedTextToInsert, textFieldSender->cursorLocation());
|
||||
int newCursorLocation = textFieldSender->cursorLocation() + Shared::ToolboxHelpers::CursorIndexInCommand(strippedTextToInsert);
|
||||
textFieldSender->setCursorLocation(newCursorLocation);
|
||||
|
||||
@@ -32,6 +32,7 @@ LcmCommandWithArg = "lcm(p,q)"
|
||||
LeftIntegralFirstLegend = "P(X≤"
|
||||
LeftIntegralSecondLegend = ")="
|
||||
LogCommandWithArg = "log(x,a)"
|
||||
MatrixCommandWithArg = "[[1,2][3,4]]"
|
||||
MaxCommandWithArg = "max(L)"
|
||||
MinCommandWithArg = "min(L)"
|
||||
Mu = "μ"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "toolbox_helpers.h"
|
||||
#include <ion/charset.h>
|
||||
#include <apps/i18n.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Shared {
|
||||
namespace ToolboxHelpers {
|
||||
@@ -10,28 +12,42 @@ int CursorIndexInCommand(const char * text) {
|
||||
if (text[i] == '(' || text[i] == '\'') {
|
||||
return i + 1;
|
||||
}
|
||||
if (text[i] == ']') {
|
||||
return (i - 1) > 0 ? i - 1 : 0;
|
||||
}
|
||||
}
|
||||
return strlen(text);
|
||||
}
|
||||
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer) {
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer, int bufferSize) {
|
||||
const char * messageText = I18n::translate(message);
|
||||
TextToInsertForCommandText(messageText, buffer);
|
||||
TextToInsertForCommandText(messageText, buffer, bufferSize);
|
||||
}
|
||||
|
||||
void TextToInsertForCommandText(const char * command, char * buffer) {
|
||||
void TextToInsertForCommandText(const char * command, char * buffer, int bufferSize) {
|
||||
int currentNewTextIndex = 0;
|
||||
int numberOfOpenParentheses = 0;
|
||||
int numberOfOpenBrackets = 0;
|
||||
bool insideQuote = false;
|
||||
size_t commandLength = strlen(command);
|
||||
for (size_t i = 0; i < commandLength; i++) {
|
||||
if (command[i] == ')') {
|
||||
numberOfOpenParentheses--;
|
||||
}
|
||||
if (command[i] == ']') {
|
||||
numberOfOpenBrackets--;
|
||||
}
|
||||
if ((numberOfOpenBrackets == 0 || command[i] == ',') && (!insideQuote || command[i] == '\'')) {
|
||||
if (((numberOfOpenParentheses == 0 && numberOfOpenBrackets == 0)
|
||||
|| command[i] == ','
|
||||
|| (numberOfOpenBrackets > 0 && (command[i] == ',' || command[i] == '[' || command[i] == ']')))
|
||||
&& (!insideQuote || command[i] == '\'')) {
|
||||
assert(currentNewTextIndex < bufferSize);
|
||||
buffer[currentNewTextIndex++] = command[i];
|
||||
}
|
||||
if (command[i] == '(') {
|
||||
numberOfOpenParentheses++;
|
||||
}
|
||||
if (command[i] == '[') {
|
||||
numberOfOpenBrackets++;
|
||||
}
|
||||
if (command[i] == '\'') {
|
||||
@@ -41,12 +57,23 @@ void TextToInsertForCommandText(const char * command, char * buffer) {
|
||||
buffer[currentNewTextIndex] = 0;
|
||||
}
|
||||
|
||||
void TextToParseIntoLayoutForCommandMessage(I18n::Message message, char * buffer) {
|
||||
void TextToParseIntoLayoutForCommandMessage(I18n::Message message, char * buffer, int bufferSize) {
|
||||
if (message == I18n::Message::MatrixCommandWithArg) {
|
||||
assert(bufferSize >= 6);
|
||||
// Handle a new matrix command.
|
||||
buffer[0] = '[';
|
||||
buffer[1] = '[';
|
||||
buffer[2] = Ion::Charset::Empty;
|
||||
buffer[3] = ']';
|
||||
buffer[4] = ']';
|
||||
buffer[5] = 0;
|
||||
return;
|
||||
}
|
||||
const char * messageText = I18n::translate(message);
|
||||
TextToInsertForCommandText(messageText, buffer);
|
||||
TextToInsertForCommandText(messageText, buffer, bufferSize);
|
||||
size_t bufferLength = strlen(buffer);
|
||||
for (size_t i = 0; i < bufferLength; i++) {
|
||||
if (buffer[i] == '(' || buffer[i] == ',') {
|
||||
if (buffer[i] == '(' || buffer[i] == '[' || buffer[i] == ',') {
|
||||
// Shift the buffer to make room for the new char. Use memmove to avoid
|
||||
// overwritting.
|
||||
memmove(&buffer[i+2], &buffer[i+1], bufferLength - (i+1) + 1);
|
||||
|
||||
@@ -13,11 +13,11 @@ int CursorIndexInCommand(const char * text);
|
||||
* - The end of the text */
|
||||
|
||||
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer);
|
||||
void TextToInsertForCommandText(const char * command, char * buffer);
|
||||
void TextToInsertForCommandMessage(I18n::Message message, char * buffer, int bufferSize);
|
||||
void TextToInsertForCommandText(const char * command, char * buffer, int bufferSize);
|
||||
/* Removes the arguments from a command:
|
||||
* - Removes text between parentheses, except commas */
|
||||
void TextToParseIntoLayoutForCommandMessage(I18n::Message message, char * buffer);
|
||||
* - Removes text between parentheses or brackets, except commas */
|
||||
void TextToParseIntoLayoutForCommandMessage(I18n::Message message, char * buffer, int bufferSize);
|
||||
/* Removes the arguments from a command and replaces them with empty chars. */
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ ComplexNumber = "Komplexen Zahlen"
|
||||
Probability = "Kombinatorik"
|
||||
Arithmetic = "Arithmetisch"
|
||||
Matrices = "Matrizen"
|
||||
NewMatrix = "Neue Matrix"
|
||||
Lists = "Listen"
|
||||
Approximation = "Approximation"
|
||||
HyperbolicTrigonometry = "Hyperbelfunktionen"
|
||||
|
||||
@@ -7,6 +7,7 @@ ComplexNumber = "Complex numbers"
|
||||
Probability = "Combinatorics"
|
||||
Arithmetic = "Arithmetic"
|
||||
Matrices = "Matrix"
|
||||
NewMatrix = "New matrix"
|
||||
Lists = "List"
|
||||
Approximation = "Approximation"
|
||||
HyperbolicTrigonometry = "Hyperbolic trigonometry"
|
||||
|
||||
@@ -7,6 +7,7 @@ ComplexNumber = "Numeros complejos"
|
||||
Probability = "Combinatoria"
|
||||
Arithmetic = "Aritmetica"
|
||||
Matrices = "Matriz"
|
||||
NewMatrix = "Nueva matriz"
|
||||
Lists = "Listas"
|
||||
Approximation = "Aproximacion"
|
||||
HyperbolicTrigonometry = "Trigonometria hiperbolica"
|
||||
|
||||
@@ -7,6 +7,7 @@ ComplexNumber = "Nombres complexes"
|
||||
Probability = "Denombrement"
|
||||
Arithmetic = "Arithmetique"
|
||||
Matrices = "Matrices"
|
||||
NewMatrix = "Nouvelle matrice"
|
||||
Lists = "Listes"
|
||||
Approximation = "Approximation"
|
||||
HyperbolicTrigonometry = "Trigonometrie hyperbolique"
|
||||
|
||||
@@ -7,6 +7,7 @@ ComplexNumber = "Numeros complexos"
|
||||
Probability = "Combinatoria"
|
||||
Arithmetic = "Aritmetica"
|
||||
Matrices = "Matrizes"
|
||||
NewMatrix = "Nova matriz"
|
||||
Lists = "Listas"
|
||||
Approximation = "Aproximacao"
|
||||
HyperbolicTrigonometry = "Funcoes hiperbolicas"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <escher/editable_expression_view.h>
|
||||
#include <escher/text_field.h>
|
||||
#include <poincare/src/layout/matrix_layout.h>
|
||||
#include <assert.h>
|
||||
|
||||
EditableExpressionView::EditableExpressionView(Responder * parentResponder, Poincare::ExpressionLayout * expressionLayout, EditableExpressionViewDelegate * delegate) :
|
||||
@@ -150,6 +151,9 @@ void EditableExpressionView::insertLayoutAtCursor(Poincare::ExpressionLayout * l
|
||||
}
|
||||
KDSize previousSize = minimalSizeForOptimalDisplay();
|
||||
m_expressionViewWithCursor.cursor()->addLayout(layout);
|
||||
if (layout->isMatrix() && pointedLayout->hasAncestor(layout)) {
|
||||
static_cast<Poincare::MatrixLayout *>(layout)->addGreySquares();
|
||||
}
|
||||
m_expressionViewWithCursor.cursor()->setPointedExpressionLayout(pointedLayout);
|
||||
m_expressionViewWithCursor.cursor()->setPosition(Poincare::ExpressionLayoutCursor::Position::Right);
|
||||
reload();
|
||||
|
||||
@@ -29,6 +29,8 @@ public:
|
||||
|
||||
/* Special matrix method */
|
||||
void newRowOrColumnAtIndex(int index);
|
||||
void addGreySquares();
|
||||
|
||||
protected:
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
|
||||
KDSize computeSize() override;
|
||||
@@ -37,7 +39,6 @@ private:
|
||||
void childWasReplacedAtIndex(int index);
|
||||
bool isRowEmpty(int index) const;
|
||||
bool isColumnEmpty(int index) const;
|
||||
void addGreySquares();
|
||||
void removeGreySquares();
|
||||
bool hasGreySquares() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user