MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ScrollEditBoxTextRect

Function ScrollEditBoxTextRect

src/misc_gui.cpp:723–734  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

721 * @return Updated rect.
722 */
723static 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
736void QueryString::DrawEditBox(const Window *w, WidgetID wid) const
737{

Callers 4

DrawEditBoxMethod · 0.85
GetCaretPositionMethod · 0.85
GetBoundingRectMethod · 0.85
GetCharAtPositionMethod · 0.85

Calls 4

GetCaretWidthFunction · 0.85
WithWidthMethod · 0.80
TranslateMethod · 0.80
WidthMethod · 0.45

Tested by

no test coverage detected