Fix #8971: Resize QueryStrings with interface scale change. (#10281)

* Fix: Use width of caret symbol '_' for text entry.

This replaces an arbitrary pixel width with the space actually required.

* Fix #8971: Update QueryString sizes with interface scale change.
This commit is contained in:
PeterN
2022-12-25 00:40:55 +00:00
committed by GitHub
parent 3451c0a82c
commit 23eec0b7b3
3 changed files with 25 additions and 5 deletions

View File

@@ -789,6 +789,11 @@ void QueryString::HandleEditBox(Window *w, int wid)
}
}
static int GetCaretWidth()
{
return GetCharacterWidth(FS_NORMAL, '_');
}
void QueryString::DrawEditBox(const Window *w, int wid) const
{
const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
@@ -821,7 +826,7 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
/* We will take the current widget length as maximum width, with a small
* space reserved at the end for the caret to show */
const Textbuf *tb = &this->text;
int delta = std::min(0, (fr.right - fr.left) - tb->pixels - 10);
int delta = std::min(0, (fr.right - fr.left) - tb->pixels - GetCaretWidth());
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
@@ -858,7 +863,7 @@ Point QueryString::GetCaretPosition(const Window *w, int wid) const
/* Clamp caret position to be inside out current width. */
const Textbuf *tb = &this->text;
int delta = std::min(0, (r.right - r.left) - tb->pixels - 10);
int delta = std::min(0, (r.right - r.left) - tb->pixels - GetCaretWidth());
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
Point pt = {r.left + tb->caretxoffs + delta, r.top};
@@ -887,7 +892,7 @@ Rect QueryString::GetBoundingRect(const Window *w, int wid, const char *from, co
/* Clamp caret position to be inside our current width. */
const Textbuf *tb = &this->text;
int delta = std::min(0, r.Width() - tb->pixels - 10);
int delta = std::min(0, r.Width() - tb->pixels - GetCaretWidth());
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
/* Get location of first and last character. */
@@ -920,7 +925,7 @@ const char *QueryString::GetCharAtPosition(const Window *w, int wid, const Point
/* Clamp caret position to be inside our current width. */
const Textbuf *tb = &this->text;
int delta = std::min(0, r.Width() - tb->pixels - 10);
int delta = std::min(0, r.Width() - tb->pixels - GetCaretWidth());
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
return ::GetCharAtPosition(tb->buf, pt.x - delta - r.left);