From 4a73a7ab0fe0aed74ffb36ef0d4843ba0646274f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 28 Feb 2017 15:02:02 +0100 Subject: [PATCH] [escher] Correct text field Change-Id: I3f7c7b26a2ff51366cfc241bc50f90fa5c050a72 --- escher/include/escher/text_field.h | 1 + escher/src/scrollable_view.cpp | 4 ++-- escher/src/text_field.cpp | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/escher/include/escher/text_field.h b/escher/include/escher/text_field.h index 75ec268f3..cf6727d64 100644 --- a/escher/include/escher/text_field.h +++ b/escher/include/escher/text_field.h @@ -69,6 +69,7 @@ protected: }; ContentView m_contentView; private: + void deleteCharPrecedingCursor(); bool cursorIsBeforeScrollingFrame(); bool cursorIsAfterScrollingFrame(); void scrollToCursor(); diff --git a/escher/src/scrollable_view.cpp b/escher/src/scrollable_view.cpp index 180105b51..6b5b362fa 100644 --- a/escher/src/scrollable_view.cpp +++ b/escher/src/scrollable_view.cpp @@ -34,8 +34,8 @@ void ScrollableView::reloadScroll() { void ScrollableView::layoutSubviews() { KDSize viewSize = view()->minimalSizeForOptimalDisplay(); - KDCoordinate viewWidth = viewSize.width() == 0 ? bounds().width() : viewSize.width(); - KDCoordinate viewHeight = viewSize.height() == 0 ? bounds().height() : viewSize.height(); + KDCoordinate viewWidth = viewSize.width() < bounds().width() ? bounds().width() : viewSize.width(); + KDCoordinate viewHeight = viewSize.height() < bounds().height() ? bounds().height() : viewSize.height(); view()->setSize(KDSize(viewWidth, viewHeight)); ScrollView::layoutSubviews(); } diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index abbb27f93..7f98266b2 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -198,7 +198,9 @@ int TextField::cursorLocation() const{ } void TextField::setText(const char * text) { + reloadScroll(); m_contentView.setText(text); + scrollToCursor(); layoutSubviews(); } @@ -248,8 +250,8 @@ bool TextField::handleEvent(Ion::Events::Event event) { if (isEditing()) { strlcpy(m_contentView.textBuffer(), m_contentView.draftTextBuffer(), m_contentView.bufferSize()); setEditing(false); - reloadScroll(); m_delegate->textFieldDidFinishEditing(this, text()); + reloadScroll(); return true; } setEditing(true); @@ -270,8 +272,7 @@ bool TextField::handleEvent(Ion::Events::Event event) { return true; } if (event == Ion::Events::Backspace && isEditing()) { - m_contentView.deleteCharPrecedingCursor(); - scrollToAvoidWhiteSpace(); + deleteCharPrecedingCursor(); return true; } if (event.hasText()) { @@ -294,6 +295,11 @@ bool TextField::handleEvent(Ion::Events::Event event) { return false; } +void TextField::deleteCharPrecedingCursor() { + m_contentView.deleteCharPrecedingCursor(); + scrollToAvoidWhiteSpace(); +} + bool TextField::cursorIsBeforeScrollingFrame() { return cursorLocation() * m_contentView.charWidth() < m_manualScrolling; } @@ -304,6 +310,9 @@ bool TextField::cursorIsAfterScrollingFrame() { void TextField::scrollToCursor() { + if (!isEditing()) { + return; + } if (cursorIsBeforeScrollingFrame()) { m_manualScrolling = cursorLocation() * m_contentView.charWidth(); setContentOffset(KDPoint(m_manualScrolling, 0));