Merge pull request #1094 from LeaNumworks/FixXNT

Fix xnt
This commit is contained in:
RubenNumworks
2019-09-20 16:18:57 +02:00
committed by GitHub
8 changed files with 26 additions and 9 deletions

View File

@@ -42,6 +42,7 @@ public:
Snapshot * snapshot() const {
return static_cast<Snapshot *>(::App::snapshot());
}
bool XNTCanBeOverriden() const override { return false; }
CodePoint XNT() override;
NestedMenuController * variableBoxForInputEventHandler(InputEventHandler * textInput) override;
CartesianFunctionStore * functionStore() override { return static_cast<CartesianFunctionStore *>(Shared::FunctionApp::functionStore()); }

View File

@@ -68,7 +68,11 @@ bool TextFieldDelegateApp::fieldDidReceiveEvent(EditableField * field, Responder
/* TODO decode here to encode again in handleEventWithText? */
constexpr int bufferSize = CodePoint::MaxCodePointCharLength+1;
char buffer[bufferSize];
size_t length = UTF8Decoder::CodePointToChars(field->XNTCodePoint(XNT()), buffer, bufferSize);
CodePoint xnt = XNT();
if (XNTCanBeOverriden()) {
xnt = field->XNTCodePoint(xnt);
}
size_t length = UTF8Decoder::CodePointToChars(xnt, buffer, bufferSize);
assert(length < bufferSize - 1);
buffer[length] = 0;
return field->handleEventWithText(buffer);

View File

@@ -14,6 +14,7 @@ class TextFieldDelegateApp : public InputEventHandlerDelegateApp, public TextFie
public:
virtual ~TextFieldDelegateApp() = default;
virtual Poincare::Context * localContext();
virtual bool XNTCanBeOverriden() const { return true; }
virtual CodePoint XNT() { return 'x'; }
bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override;
virtual bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override;

View File

@@ -25,7 +25,7 @@ public:
void deleteBeforeCursor(LayoutCursor * cursor) override;
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression) override { return lowerBoundLayout(); }
CodePoint XNTCodePoint() const override { return 'x'; }
CodePoint XNTCodePoint(int childIndex = -1) const override;
// TreeNode
size_t size() const override { return sizeof(IntegralLayoutNode); }
@@ -42,6 +42,8 @@ protected:
KDCoordinate computeBaseline() override;
KDPoint positionOfChild(LayoutNode * child) override;
private:
constexpr static int k_integrandLayoutIndex = 0;
constexpr static int k_differentialLayoutIndex = 1;
constexpr static const KDFont * k_font = KDFont::LargeFont;
constexpr static KDCoordinate k_boundHeightMargin = 8;
constexpr static KDCoordinate k_boundWidthMargin = 5;
@@ -50,8 +52,8 @@ private:
constexpr static KDCoordinate k_integrandHeigthMargin = 2;
constexpr static KDCoordinate k_lineThickness = 1;
// int(f(x), x, a, b)
LayoutNode * integrandLayout() { return childAtIndex(0); } // f(x)
LayoutNode * differentialLayout() { return childAtIndex(1); } // dx
LayoutNode * integrandLayout() { return childAtIndex(k_integrandLayoutIndex); } // f(x)
LayoutNode * differentialLayout() { return childAtIndex(k_differentialLayoutIndex); } // dx
LayoutNode * lowerBoundLayout() { return childAtIndex(2); } // a
LayoutNode * upperBoundLayout() { return childAtIndex(3); } // b
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;

View File

@@ -126,9 +126,9 @@ public:
* is clearer with different names. */
virtual bool isEmpty() const { return false; }
virtual bool hasUpperLeftIndex() const { return false; }
virtual CodePoint XNTCodePoint() const {
virtual CodePoint XNTCodePoint(int childIndex = -1) const {
LayoutNode * p = parent();
return p == nullptr ? UCodePointNull : p->XNTCodePoint();
return p == nullptr ? UCodePointNull : p->XNTCodePoint(p->indexOfChild(this));
}
virtual bool willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) { return true; }

View File

@@ -20,7 +20,7 @@ public:
void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override;
void deleteBeforeCursor(LayoutCursor * cursor) override;
LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression) override { return lowerBoundLayout(); }
CodePoint XNTCodePoint() const override { return 'n'; }
CodePoint XNTCodePoint(int childIndex = -1) const override;
// TreeNode
int numberOfChildren() const override { return 4; }
@@ -39,12 +39,14 @@ protected:
KDPoint positionOfChild(LayoutNode * child) override;
int writeDerivedClassInBuffer(const char * operatorName, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const;
LayoutNode * argumentLayout() { return childAtIndex(0); }
LayoutNode * variableLayout() { return childAtIndex(1); }
LayoutNode * argumentLayout() { return childAtIndex(k_argumentLayoutIndex); }
LayoutNode * variableLayout() { return childAtIndex(k_variableLayoutIndex); }
LayoutNode * lowerBoundLayout() { return childAtIndex(2); }
LayoutNode * upperBoundLayout() { return childAtIndex(3); }
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
private:
static constexpr int k_argumentLayoutIndex = 0;
static constexpr int k_variableLayoutIndex = 1;
KDCoordinate completeLowerBoundX();
KDCoordinate subscriptBaseline();
};

View File

@@ -205,6 +205,10 @@ int IntegralLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pr
return numberOfChar;
}
CodePoint IntegralLayoutNode::XNTCodePoint(int childIndex) const {
return (childIndex == k_integrandLayoutIndex || childIndex == k_differentialLayoutIndex) ? CodePoint('x') : UCodePointNull;
}
KDSize IntegralLayoutNode::computeSize() {
KDSize dSize = k_font->stringSize("d");
KDSize integrandSize = integrandLayout()->layoutSize();

View File

@@ -148,6 +148,9 @@ void SequenceLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) {
LayoutNode::deleteBeforeCursor(cursor);
}
CodePoint SequenceLayoutNode::XNTCodePoint(int childIndex) const {
return (childIndex == k_argumentLayoutIndex || childIndex == k_variableLayoutIndex) ? CodePoint('n') : UCodePointNull;
}
// Protected