mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[apps/graph] Add equal after function name
This commit is contained in:
@@ -42,14 +42,16 @@ void StorageListController::renameSelectedFunction() {
|
||||
bool StorageListController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
// Compute the new name
|
||||
size_t textLength = strlen(text);
|
||||
size_t argumentLength = StorageFunction::k_parenthesedArgumentLength;
|
||||
constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentSize;
|
||||
size_t argumentLength = StorageFunction::k_parenthesedArgumentWithEqualLength;
|
||||
constexpr int maxBaseNameSize = StorageFunction::k_maxNameWithArgumentAndEqualSize;
|
||||
char baseName[maxBaseNameSize];
|
||||
if (textLength <= argumentLength) {
|
||||
// The user entered an empty name. Use a default function name.
|
||||
StorageCartesianFunction::DefaultName(baseName, maxBaseNameSize);
|
||||
size_t defaultNameLength = strlen(baseName);
|
||||
assert(defaultNameLength + Shared::StorageCartesianFunction::k_maxNameWithArgumentAndEqualSize < maxBaseNameSize);
|
||||
strlcpy(baseName + defaultNameLength, StorageFunction::k_parenthesedArgument, maxBaseNameSize - defaultNameLength);
|
||||
strlcpy(baseName + defaultNameLength + StorageFunction::k_parenthesedArgumentLength, StorageFunction::k_equal, maxBaseNameSize - defaultNameLength - StorageFunction::k_parenthesedArgumentLength);
|
||||
textField->setText(baseName);
|
||||
baseName[defaultNameLength] = 0;
|
||||
} else {
|
||||
@@ -164,7 +166,7 @@ void StorageListController::willDisplayExpressionCellAtIndex(HighlightCell * cel
|
||||
|
||||
void StorageListController::setFunctionNameInTextField(ExpiringPointer<StorageFunction> function, TextField * textField) {
|
||||
char bufferName[BufferTextView::k_maxNumberOfChar];
|
||||
function->nameWithArgument(bufferName, BufferTextView::k_maxNumberOfChar, modelStore()->symbol());
|
||||
function->nameWithArgumentAndEqual(bufferName, BufferTextView::k_maxNumberOfChar, modelStore()->symbol());
|
||||
textField->setText(bufferName);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Graph {
|
||||
TextFieldFunctionTitleCell::TextFieldFunctionTitleCell(StorageListController * listController, Orientation orientation, const KDFont * font) :
|
||||
Shared::FunctionTitleCell(orientation),
|
||||
Responder(listController),
|
||||
m_textField(Shared::StorageFunction::k_parenthesedArgumentLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, 0.5f, 0.5f)
|
||||
m_textField(Shared::StorageFunction::k_parenthesedArgumentWithEqualLength, this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, nullptr, listController, false, font, 0.5f, 0.5f)
|
||||
{}
|
||||
|
||||
void TextFieldFunctionTitleCell::setHighlighted(bool highlight) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
protected:
|
||||
KDRect textFieldFrame() const;
|
||||
private:
|
||||
constexpr static int k_textFieldBufferSize = Shared::StorageFunction::k_maxNameWithArgumentSize;
|
||||
constexpr static int k_textFieldBufferSize = Shared::StorageFunction::k_maxNameWithArgumentAndEqualSize;
|
||||
Shared::TextFieldWithExtension m_textField;
|
||||
char m_textFieldBuffer[k_textFieldBufferSize];
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ using namespace Poincare;
|
||||
namespace Shared {
|
||||
|
||||
constexpr char StorageFunction::k_parenthesedArgument[];
|
||||
constexpr char StorageFunction::k_equal[];
|
||||
|
||||
bool StorageFunction::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) {
|
||||
assert(baseName[0] != 0);
|
||||
@@ -63,11 +64,17 @@ void StorageFunction::setActive(bool active) {
|
||||
int StorageFunction::nameWithArgument(char * buffer, size_t bufferSize, char arg) {
|
||||
const char * functionName = fullName();
|
||||
size_t baseNameLength = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize - k_parenthesedArgumentLength);
|
||||
int result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength);
|
||||
strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength);
|
||||
if (baseNameLength+1 < bufferSize - 1) {
|
||||
buffer[baseNameLength+1] = arg;
|
||||
}
|
||||
return result;
|
||||
return strlen(buffer);
|
||||
}
|
||||
|
||||
int StorageFunction::nameWithArgumentAndEqual(char * buffer, size_t bufferSize, char arg) {
|
||||
int numberOfChars = nameWithArgument(buffer, bufferSize, arg);
|
||||
strlcpy(&buffer[numberOfChars], k_equal, bufferSize-numberOfChars);
|
||||
return strlen(buffer);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -17,6 +17,9 @@ public:
|
||||
constexpr static int k_parenthesedArgumentLength = 3;
|
||||
static constexpr char k_parenthesedArgument[k_parenthesedArgumentLength+1] = "(x)";
|
||||
constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedArgumentLength; /* Function name and null-terminating char + "(x)" */;
|
||||
constexpr static int k_parenthesedArgumentWithEqualLength = k_parenthesedArgumentLength + 1;
|
||||
static constexpr char k_equal[] = "=";
|
||||
constexpr static int k_maxNameWithArgumentAndEqualSize = k_maxNameWithArgumentSize + 1;
|
||||
static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr);
|
||||
|
||||
// Constructors
|
||||
@@ -29,6 +32,7 @@ public:
|
||||
|
||||
// Name
|
||||
int nameWithArgument(char * buffer, size_t bufferSize, char arg);
|
||||
int nameWithArgumentAndEqual(char * buffer, size_t bufferSize, char arg);
|
||||
|
||||
// Evaluation
|
||||
virtual float evaluateAtAbscissa(float x, Poincare::Context * context) const {
|
||||
|
||||
Reference in New Issue
Block a user