From 97f8a4e42e2fad250ea296b503083d9e886be231 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Thu, 22 Apr 2021 01:31:11 +0100 Subject: [PATCH] GUI: Fix getEditRect and implify rect handling in EditTextWidget The same rect was hardcoded in three different places. Now it is only in getEditRect and the other places use getEditRect. There were actually differences between the rect width, but I put that down to a bug in getEditRect. I see no reason to define the right position of the rect as w - 2 - right_padding - left_padding. Substracting the left padding would make sense if we were specifying the rect width, but the Common:Rect constructor takes the rect right location and not the width. There might have been a confusion on that point by the developer who wrote that code years ago. Also has the bottom right point is excluded, we should only remove 1 and not 2. This width that was smaller than it should be might have been the reason why 6 additional pixels were arbitrarily added to the rect passed to setTextDrawableArea later on. There were actually --- gui/widgets/edittext.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gui/widgets/edittext.cpp b/gui/widgets/edittext.cpp index fb990268e38..0b4bd0b119b 100644 --- a/gui/widgets/edittext.cpp +++ b/gui/widgets/edittext.cpp @@ -102,18 +102,18 @@ void EditTextWidget::drawWidget() { // Draw the text adjustOffset(); - - const Common::Rect &r = Common::Rect(_x + 2 + _leftPadding, _y + 1, _x + _leftPadding + getEditRect().width() + 8, _y + _h); - setTextDrawableArea(r); + Common::Rect drawRect = getEditRect(); + drawRect.translate(_x, _y); + setTextDrawableArea(drawRect); g_gui.theme()->drawText( - Common::Rect(_x + 2 + _leftPadding, _y + 1, _x + _leftPadding + getEditRect().width() + 2, _y + _h), + drawRect, _editString, _state, _drawAlign, ThemeEngine::kTextInversionNone, -_editScrollOffset, false, _font, ThemeEngine::kFontColorNormal, true, _textDrawableArea); } Common::Rect EditTextWidget::getEditRect() const { - Common::Rect r(2 + _leftPadding, 1, _w - 2 - _leftPadding - _rightPadding, _h); + Common::Rect r(2 + _leftPadding, 1, _w - 1 - _rightPadding, _h); return r; }