* Get the bounding rectangle for a range of the query string. * @param w Window the edit box is in. * @param wid Widget index. * @param from Start of the string range. * @param to End of the string range. * @return Rectangle encompassing the string range, relative to the window. */
| 819 | * @return Rectangle encompassing the string range, relative to the window. |
| 820 | */ |
| 821 | Rect QueryString::GetBoundingRect(const Window *w, WidgetID wid, size_t from, size_t to) const |
| 822 | { |
| 823 | const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid); |
| 824 | |
| 825 | assert((wi->type & WWT_MASK) == WWT_EDITBOX); |
| 826 | |
| 827 | bool rtl = _current_text_dir == TD_RTL; |
| 828 | Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT); |
| 829 | int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal(); |
| 830 | |
| 831 | Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect); |
| 832 | |
| 833 | /* Clamp caret position to be inside our current width. */ |
| 834 | const Textbuf *tb = &this->text; |
| 835 | r = ScrollEditBoxTextRect(r, *tb); |
| 836 | |
| 837 | /* Get location of first and last character. */ |
| 838 | const auto p1 = GetCharPosInString(tb->GetText(), from, FS_NORMAL); |
| 839 | const auto p2 = from != to ? GetCharPosInString(tb->GetText(), to, FS_NORMAL) : p1; |
| 840 | |
| 841 | return r.WithX(Clamp(r.left + p1.left, r.left, r.right), Clamp(r.left + p2.right, r.left, r.right)); |
| 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Get the character that is rendered at a position. |
no test coverage detected