[escher] Fix buffer choice in TextField::glyphFrameAtPosition

This commit is contained in:
Léa Saviot
2019-01-31 10:56:17 +01:00
committed by Émilie Feral
parent 06269d5349
commit b1d18416e8
7 changed files with 14 additions and 12 deletions

View File

@@ -119,7 +119,7 @@ protected:
bool removeEndOfLine() override;
bool removeStartOfLine();
protected:
KDRect glyphFrameAtPosition(const char * position) const override;
KDRect glyphFrameAtPosition(const char * text, const char * position) const override;
Text m_text;
};

View File

@@ -67,7 +67,7 @@ protected:
constexpr static int k_maxBufferSize = 152;
private:
void layoutSubviews() override;
KDRect glyphFrameAtPosition(const char * position) const override;
KDRect glyphFrameAtPosition(const char * buffer, const char * position) const override;
bool m_isEditing;
char * m_textBuffer;
char * m_draftTextBuffer;

View File

@@ -36,7 +36,7 @@ protected:
protected:
virtual void layoutSubviews() override;
void reloadRectFromPosition(const char * position, bool lineBreak = false);
virtual KDRect glyphFrameAtPosition(const char * position) const = 0;
virtual KDRect glyphFrameAtPosition(const char * buffer, const char * position) const = 0;
TextCursorView m_cursorView;
const KDFont * m_font;
const char * m_cursorLocation;

View File

@@ -426,7 +426,8 @@ bool TextArea::ContentView::removeStartOfLine() {
return false;
}
KDRect TextArea::ContentView::glyphFrameAtPosition(const char * position) const {
KDRect TextArea::ContentView::glyphFrameAtPosition(const char * text, const char * position) const {
assert(text == m_text.text());
KDSize glyphSize = m_font->glyphSize();
Text::Position p = m_text.positionAtPointer(position);

View File

@@ -45,7 +45,7 @@ void TextField::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
backgroundColor = KDColorWhite;
}
ctx->fillRect(bounds(), backgroundColor);
ctx->drawString(text(), glyphFrameAtPosition(text()).origin(), m_font, m_textColor, backgroundColor);
ctx->drawString(text(), glyphFrameAtPosition(text(), text()).origin(), m_font, m_textColor, backgroundColor);
}
const char * TextField::ContentView::text() const {
@@ -207,14 +207,15 @@ void TextField::ContentView::layoutSubviews() {
TextInput::ContentView::layoutSubviews();
}
KDRect TextField::ContentView::glyphFrameAtPosition(const char * position) const {
assert(position != nullptr);
KDRect TextField::ContentView::glyphFrameAtPosition(const char * buffer, const char * position) const {
assert(buffer != nullptr && position != nullptr);
assert(position >= buffer);
KDSize glyphSize = m_font->glyphSize();
KDCoordinate cursorWidth = m_cursorView.minimalSizeForOptimalDisplay().width();
KDCoordinate horizontalOffset = m_horizontalAlignment == 0.0f ? 0.0f :
m_horizontalAlignment * (m_frame.width() - m_font->stringSize(text()).width() - cursorWidth);
m_horizontalAlignment * (m_frame.width() - m_font->stringSize(buffer).width() - cursorWidth);
return KDRect(
horizontalOffset + m_font->stringSizeUntil(text(), position).width(),
horizontalOffset + m_font->stringSizeUntil(buffer, position).width(),
m_verticalAlignment * (m_frame.height() - glyphSize.height()),
glyphSize);
}

View File

@@ -20,7 +20,7 @@ void TextInput::ContentView::setFont(const KDFont * font) {
}
KDRect TextInput::ContentView::cursorRect() {
return glyphFrameAtPosition(m_cursorLocation);
return glyphFrameAtPosition(editedText(), m_cursorLocation);
}
void TextInput::ContentView::layoutSubviews() {
@@ -32,7 +32,7 @@ void TextInput::ContentView::reloadRectFromPosition(const char * position, bool
}
KDRect TextInput::ContentView::dirtyRectFromPosition(const char * position, bool lineBreak) const {
KDRect glyphRect = glyphFrameAtPosition(position);
KDRect glyphRect = glyphFrameAtPosition(text(), position);
KDRect dirtyRect = KDRect(
glyphRect.x(),
glyphRect.y(),

View File

@@ -6,7 +6,7 @@
constexpr static int k_tabCharacterWidth = 4;
KDSize KDFont::stringSizeUntil(const char * text, const char * limit) const {
if (text == nullptr) {
if (text == nullptr || (limit != nullptr && text >= limit)) {
return KDSizeZero;
}
KDSize stringSize = KDSize(0, m_glyphSize.height());