GUI: Keep caret visible in editable widgets while moving it

This was actually the intention all along. But if a redraw of the widget
itself was triggered at the same time, it would draw over the caret,
effectively erasing it. To get around this, the caret is now also drawn
as part of the widget, when necessary.
This commit is contained in:
Torbjörn Andersson 2024-04-16 07:24:13 +02:00 committed by Eugene Sandulenko
parent 298f62102a
commit a46913545f
4 changed files with 28 additions and 5 deletions

View file

@ -69,6 +69,12 @@ void EditableWidget::init() {
EditableWidget::~EditableWidget() {
}
void EditableWidget::drawWidget() {
if (_caretVisible) {
drawCaret(false, true);
}
}
void EditableWidget::reflowLayout() {
Widget::reflowLayout();
@ -526,13 +532,24 @@ int EditableWidget::getSelectionCarretOffset() const {
return g_gui.getStringWidth(substr, _font) - _editScrollOffset;
}
void EditableWidget::drawCaret(bool erase) {
void EditableWidget::drawCaret(bool erase, bool useRelativeCoordinates) {
// Only draw if item is visible
if (!isVisible() || !_boss->isVisible())
return;
Common::Rect editRect = getEditRect();
int xOff;
int yOff;
if (useRelativeCoordinates) {
xOff = getRelX();
yOff = getRelY();
} else {
xOff = getAbsX();
yOff = getAbsY();
}
int x = editRect.left;
int y = editRect.top;
@ -554,10 +571,10 @@ void EditableWidget::drawCaret(bool erase) {
return;
if (g_gui.useRTL())
x += g_system->getOverlayWidth() - _w - getAbsX() + g_gui.getOverlayOffset();
x += g_system->getOverlayWidth() - _w - xOff + g_gui.getOverlayOffset();
else
x += getAbsX();
y += getAbsY();
x += xOff;
y += yOff;
g_gui.theme()->drawCaret(Common::Rect(x, y, x + 1, y + editRect.height()), erase);

View file

@ -91,6 +91,8 @@ public:
void setSelectionOffset(int newOffset);
protected:
void drawWidget() override;
virtual void startEditMode() = 0;
virtual void endEditMode() = 0;
virtual void abortEditMode() = 0;
@ -102,7 +104,7 @@ protected:
virtual Common::Rect getEditRect() const = 0;
virtual int getCaretOffset() const;
virtual int getSelectionCarretOffset() const;
void drawCaret(bool erase);
void drawCaret(bool erase, bool useRelativeCoordinates = false);
bool adjustOffset();
void makeCaretVisible();

View file

@ -122,6 +122,8 @@ void EditTextWidget::drawWidget() {
-_editScrollOffset, false, _font, ThemeEngine::kFontColorNormal, true,
_textDrawableArea);
}
EditableWidget::drawWidget();
}
Common::Rect EditTextWidget::getEditRect() const {

View file

@ -613,6 +613,8 @@ void ListWidget::drawWidget() {
g_gui.theme()->drawText(r2, buffer, _state, _drawAlign, inverted, _leftPadding, true);
}
}
EditableWidget::drawWidget();
}
Common::Rect ListWidget::getEditRect() const {