diff --git a/escher/include/escher/text_field.h b/escher/include/escher/text_field.h index a83aa9b05..27eb28114 100644 --- a/escher/include/escher/text_field.h +++ b/escher/include/escher/text_field.h @@ -28,7 +28,6 @@ public: char * draftTextBuffer() const { return const_cast(m_contentView.editedText()); } size_t draftTextLength() const; void setText(const char * text); - void setAlignment(float horizontalAlignment, float verticalAlignment); void setEditing(bool isEditing) override { m_contentView.setEditing(isEditing); } CodePoint XNTCodePoint(CodePoint defaultXNTCodePoint) override; bool handleEventWithText(const char * text, bool indentation = false, bool forceCursorRightOfText = false) override; @@ -42,7 +41,7 @@ public: protected: class ContentView : public TextInput::ContentView { public: - ContentView(char * textBuffer, size_t textBufferSize, size_t draftTextBufferSize, const KDFont * font, float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor); + 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; } void setTextColor(KDColor textColor); @@ -52,7 +51,6 @@ protected: const char * editedText() const override; size_t editedTextLength() const override { return m_currentDraftTextLength; } void setText(const char * text); - void setAlignment(float horizontalAlignment, float verticalAlignment); void setEditing(bool isEditing); void reinitDraftTextBuffer(); void setDraftTextBufferSize(size_t size) { m_draftTextBufferSize = size; } @@ -83,8 +81,6 @@ protected: size_t m_textBufferSize; size_t m_draftTextBufferSize; size_t m_currentDraftTextLength; - float m_horizontalAlignment; - float m_verticalAlignment; KDColor m_textColor; KDColor m_backgroundColor; }; diff --git a/escher/include/escher/text_input.h b/escher/include/escher/text_input.h index 5da71452a..da5854908 100644 --- a/escher/include/escher/text_input.h +++ b/escher/include/escher/text_input.h @@ -15,18 +15,24 @@ public: const char * cursorLocation() const { return nonEditableContentView()->cursorLocation(); } bool setCursorLocation(const char * location); virtual void scrollToCursor(); + // Selection void resetSelection() { contentView()->resetSelection(); } void deleteSelection(); + // Alignment + void setAlignment(float horizontalAlignment, float verticalAlignment); protected: + class ContentView : public View { public: - ContentView(const KDFont * font) : + ContentView(const KDFont * font, float horizontalAlignment = 0.0f, float verticalAlignment = 0.5f) : View(), m_cursorView(), m_font(font), m_selectionStart(nullptr), m_selectionEnd(nullptr), - m_cursorLocation(nullptr) + m_cursorLocation(nullptr), + m_horizontalAlignment(horizontalAlignment), + m_verticalAlignment(verticalAlignment) {} // Font @@ -52,6 +58,9 @@ protected: bool selectionIsEmpty() const; virtual size_t deleteSelection() = 0; + // Alignment + void setAlignment(float horizontalAlignment, float verticalAlignment); + // Reload void reloadRectFromPosition(const char * position, bool includeFollowingLines = false); protected: @@ -64,6 +73,8 @@ protected: const char * m_selectionStart; const char * m_selectionEnd; const char * m_cursorLocation; + float m_horizontalAlignment; + float m_verticalAlignment; private: int numberOfSubviews() const override { return 1; } View * subviewAtIndex(int index) override { diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 51a250559..28c6ce207 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -12,14 +12,12 @@ static char s_draftTextBuffer[TextField::maxBufferSize()]; /* TextField::ContentView */ TextField::ContentView::ContentView(char * textBuffer, size_t textBufferSize, size_t draftTextBufferSize, const KDFont * font, float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor) : - TextInput::ContentView(font), + TextInput::ContentView(font, horizontalAlignment, verticalAlignment), m_isEditing(false), m_textBuffer(textBuffer), m_textBufferSize(textBufferSize), m_draftTextBufferSize(draftTextBufferSize), m_currentDraftTextLength(0), - m_horizontalAlignment(horizontalAlignment), - m_verticalAlignment(verticalAlignment), m_textColor(textColor), m_backgroundColor(backgroundColor) { @@ -90,12 +88,6 @@ void TextField::ContentView::setText(const char * text) { markRectAsDirty(bounds()); } -void TextField::ContentView::setAlignment(float horizontalAlignment, float verticalAlignment) { - m_horizontalAlignment = horizontalAlignment; - m_verticalAlignment = verticalAlignment; - markRectAsDirty(bounds()); -} - void TextField::ContentView::setEditing(bool isEditing) { if (m_isEditing == isEditing) { return; @@ -297,10 +289,6 @@ void TextField::setText(const char * text) { setCursorLocation(m_contentView.editedText()+strlen(text)); } -void TextField::setAlignment(float horizontalAlignment, float verticalAlignment) { - m_contentView.setAlignment(horizontalAlignment, verticalAlignment); -} - bool TextField::privateHandleEvent(Ion::Events::Event event) { // Handle Toolbox or Var event if (handleBoxEvent(event)) { diff --git a/escher/src/text_input.cpp b/escher/src/text_input.cpp index a3e483aec..cb7d89a0a 100644 --- a/escher/src/text_input.cpp +++ b/escher/src/text_input.cpp @@ -75,6 +75,12 @@ bool TextInput::ContentView::selectionIsEmpty() const { return m_selectionStart == nullptr; } +void TextInput::ContentView::setAlignment(float horizontalAlignment, float verticalAlignment) { + m_horizontalAlignment = horizontalAlignment; + m_verticalAlignment = verticalAlignment; + markRectAsDirty(bounds()); +} + void TextInput::ContentView::reloadRectFromPosition(const char * position, bool includeFollowingLines) { markRectAsDirty(dirtyRectFromPosition(position, includeFollowingLines)); } @@ -156,6 +162,10 @@ void TextInput::deleteSelection() { contentView()->reloadRectFromPosition(previousSelectionStart, true); } +void TextInput::setAlignment(float horizontalAlignment, float verticalAlignment) { + contentView()->setAlignment(horizontalAlignment, verticalAlignment); +} + bool TextInput::insertTextAtLocation(const char * text, const char * location) { if (contentView()->insertTextAtLocation(text, location)) { /* We layout the scrollable view before scrolling to cursor because the