* Reposition edit text box rect based on textbuf length can caret position. * @param r Initial rect of edit text box. * @param tb The Textbuf being processed. * @return Updated rect. */
| 721 | * @return Updated rect. |
| 722 | */ |
| 723 | static Rect ScrollEditBoxTextRect(Rect r, const Textbuf &tb) |
| 724 | { |
| 725 | const int linewidth = tb.pixels + GetCaretWidth(); |
| 726 | const int boxwidth = r.Width(); |
| 727 | if (linewidth <= boxwidth) return r; |
| 728 | |
| 729 | /* Extend to cover whole string. This is left-aligned, adjusted by caret position. */ |
| 730 | r = r.WithWidth(linewidth, false); |
| 731 | |
| 732 | /* Slide so that the caret is at the centre unless limited by bounds of the line, i.e. near either end. */ |
| 733 | return r.Translate(-std::clamp(tb.caretxoffs - (boxwidth / 2), 0, linewidth - boxwidth), 0); |
| 734 | } |
| 735 | |
| 736 | void QueryString::DrawEditBox(const Window *w, WidgetID wid) const |
| 737 | { |
no test coverage detected