mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
@@ -1,6 +1,9 @@
|
||||
#include "expression_field.h"
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/horizontal_layout.h>
|
||||
#include <poincare/code_point_layout.h>
|
||||
|
||||
using namespace Poincare;
|
||||
namespace Calculation {
|
||||
|
||||
bool ExpressionField::handleEvent(Ion::Events::Event event) {
|
||||
@@ -21,7 +24,30 @@ bool ExpressionField::handleEvent(Ion::Events::Event event) {
|
||||
event == Ion::Events::EE)) {
|
||||
handleEventWithText(Poincare::Symbol::k_ans);
|
||||
}
|
||||
return(::ExpressionField::handleEvent(event));
|
||||
if (event == Ion::Events::Minus
|
||||
&& isEditing()
|
||||
&& fieldHasOnlyAMinus()) {
|
||||
setText(Poincare::Symbol::k_ans);
|
||||
}
|
||||
return (::ExpressionField::handleEvent(event));
|
||||
}
|
||||
|
||||
bool ExpressionField::fieldHasOnlyAMinus() const {
|
||||
if (editionIsInTextField()) {
|
||||
const char *inputBuffer = m_textField.draftTextBuffer();
|
||||
return (inputBuffer[0] == '-' && inputBuffer[1] == '\0');
|
||||
}
|
||||
Layout layout = m_layoutField.layout();
|
||||
if (layout.type() == LayoutNode::Type::HorizontalLayout && layout.numberOfChildren() == 1) {
|
||||
Layout child = layout.childAtIndex(0);
|
||||
if (child.type() == LayoutNode::Type::CodePointLayout) {
|
||||
CodePointLayout &codePointLayout = static_cast<CodePointLayout &>(child);
|
||||
if (codePointLayout.codePoint() == '-'){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ public:
|
||||
}
|
||||
protected:
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
private:
|
||||
bool fieldHasOnlyAMinus() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ public:
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void didBecomeFirstResponder() override;
|
||||
|
||||
protected:
|
||||
TextField m_textField;
|
||||
LayoutField m_layoutField;
|
||||
|
||||
private:
|
||||
static constexpr int k_textFieldBufferSize = TextField::maxBufferSize();
|
||||
static constexpr KDCoordinate k_minimalHeight = 37;
|
||||
@@ -49,8 +53,6 @@ private:
|
||||
constexpr static KDCoordinate k_separatorThickness = Metric::CellSeparatorThickness;
|
||||
KDCoordinate inputViewHeight() const;
|
||||
KDCoordinate m_inputViewMemoizedHeight;
|
||||
TextField m_textField;
|
||||
LayoutField m_layoutField;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user