[escher] In text field, change background color when editing

Change-Id: I054ce60bb8c7e96076a8f8cafe773d6506d2766a
This commit is contained in:
Émilie Feral
2017-03-28 14:15:42 +02:00
parent 2c8383c95d
commit 21019d24e2
2 changed files with 7 additions and 6 deletions

View File

@@ -39,10 +39,7 @@ View * EditableTextCell::subviewAtIndex(int index) {
}
void EditableTextCell::layoutSubviews() {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
KDCoordinate textHeight = m_textField.minimalSizeForOptimalDisplay().height();
m_textField.setFrame(KDRect(k_separatorThickness, (height - textHeight)/2, width - k_separatorThickness, textHeight));
m_textField.setFrame(bounds());
}
void EditableTextCell::didBecomeFirstResponder() {

View File

@@ -21,11 +21,15 @@ TextField::ContentView::ContentView(char * textBuffer, char * draftTextBuffer, s
}
void TextField::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, m_backgroundColor);
KDColor bckCol = m_backgroundColor;
if (m_isEditing) {
bckCol = KDColorWhite;
}
ctx->fillRect(rect, bckCol);
KDSize textSize = KDText::stringSize(text(), m_fontSize);
KDPoint origin(m_horizontalAlignment*(m_frame.width() - textSize.width()-m_cursorView.minimalSizeForOptimalDisplay().width()),
m_verticalAlignment*(m_frame.height() - textSize.height()));
ctx->drawString(text(), origin, m_fontSize, m_textColor, m_backgroundColor);
ctx->drawString(text(), origin, m_fontSize, m_textColor, bckCol);
}
void TextField::ContentView::reload() {