[apps/code] Fix input(), that did not return the input

This commit is contained in:
Léa Saviot
2020-02-19 13:48:38 +01:00
committed by EmilieNumworks
parent f7c38979a1
commit cf37e5c45a
4 changed files with 62 additions and 14 deletions

View File

@@ -28,6 +28,8 @@ public:
void reinitDraftTextBuffer() { m_contentView.reinitDraftTextBuffer(); }
bool isEditing() const override;
char * draftTextBuffer() const { return const_cast<char *>(m_contentView.editedText()); }
void setDraftTextBufferSize(size_t size) { m_contentView.setDraftTextBufferSize(size); }
size_t draftTextBufferSize() const { return m_contentView.draftTextBufferSize(); }
size_t draftTextLength() const;
void setText(const char * text);
void setEditing(bool isEditing) override { m_contentView.setEditing(isEditing); }
@@ -42,8 +44,19 @@ public:
bool shouldFinishEditing(Ion::Events::Event event) override;
const KDFont * font() const { return m_contentView.font(); }
protected:
class ContentView : public TextInput::ContentView {
public:
/* In some app (ie Calculation), text fields record expression results whose
* lengths can reach 70 (ie
* [[1.234567e-123*e^(1.234567e-123*i), 1.234567e-123*e^(1.234567e-123*i)]]).
* In order to be able to record those output text, k_maxBufferSize must be
* over 70.
* Furthermore, we want ot be able to write an adjacency matrix of size 10
* so we need at least 2 brackets + 10 * (2 brackets + 10 digits + 9 commas)
* = 212 characters. */
constexpr static int k_maxBufferSize = 220;
ContentView(char * textBuffer, size_t textBufferSize, size_t draftTextBufferSize, const KDFont * font, float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor);
void setBackgroundColor(KDColor backgroundColor);
KDColor backgroundColor() const { return m_backgroundColor; }
@@ -56,7 +69,8 @@ protected:
void setText(const char * text);
void setEditing(bool isEditing);
void reinitDraftTextBuffer();
void setDraftTextBufferSize(size_t size) { m_draftTextBufferSize = size; }
void setDraftTextBufferSize(size_t size) { assert(size <= k_maxBufferSize); m_draftTextBufferSize = size; }
size_t draftTextBufferSize() const { return m_draftTextBufferSize; }
/* If the text to be appended is too long to be added without overflowing the
* buffer, nothing is done (not even adding few letters from the text to reach
* the maximum buffer capacity) and false is returned. */
@@ -67,15 +81,6 @@ protected:
void willModifyTextBuffer();
void didModifyTextBuffer();
size_t deleteSelection() override;
/* In some app (ie Calculation), text fields record expression results whose
* lengths can reach 70 (ie
* [[1.234567e-123*e^(1.234567e-123*i), 1.234567e-123*e^(1.234567e-123*i)]]).
* In order to be able to record those output text, k_maxBufferSize must be
* over 70.
* Furthermore, we want ot be able to write an adjacency matrix of size 10
* so we need at least 2 brackets + 10 * (2 brackets + 10 digits + 9 commas)
* = 212 characters. */
constexpr static int k_maxBufferSize = 220;
private:
void layoutSubviews(bool force = false) override;
KDRect glyphFrameAtPosition(const char * buffer, const char * position) const override;
@@ -87,8 +92,10 @@ protected:
KDColor m_textColor;
KDColor m_backgroundColor;
};
const ContentView * nonEditableContentView() const override { return &m_contentView; }
ContentView m_contentView;
private:
bool privateHandleEvent(Ion::Events::Event event);
bool privateHandleMoveEvent(Ion::Events::Event event);