mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 19:49:58 +02:00
[escher] Correct text field
Change-Id: I3f7c7b26a2ff51366cfc241bc50f90fa5c050a72
This commit is contained in:
committed by
Romain Goyet
parent
a911bafa9c
commit
4a73a7ab0f
@@ -69,6 +69,7 @@ protected:
|
||||
};
|
||||
ContentView m_contentView;
|
||||
private:
|
||||
void deleteCharPrecedingCursor();
|
||||
bool cursorIsBeforeScrollingFrame();
|
||||
bool cursorIsAfterScrollingFrame();
|
||||
void scrollToCursor();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user