* Find the dropdown item under the cursor. * @param[out] result Selected item, if function returns \c true. * @param[out] click_result Click result from OnClick of Selected item, if function returns \c true. * @return Cursor points to a dropdown item. */
| 231 | * @return Cursor points to a dropdown item. |
| 232 | */ |
| 233 | bool GetDropDownItem(int &result, int &click_result) |
| 234 | { |
| 235 | if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false; |
| 236 | |
| 237 | const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.dropdownlist).Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero); |
| 238 | int click_y = _cursor.pos.y - this->top - r.top; |
| 239 | int y = -this->vscroll->GetPosition(); |
| 240 | int y_end = r.Height(); |
| 241 | |
| 242 | for (const auto &item : this->list) { |
| 243 | int item_height = item->Height(); |
| 244 | |
| 245 | /* Skip items that are scrolled up */ |
| 246 | if (y > y_end) break; |
| 247 | if (click_y >= y && click_y < y + item_height) { |
| 248 | if (item->masked || !item->Selectable()) return false; |
| 249 | result = item->result; |
| 250 | click_result = item->OnClick(r.WithY(0, item_height - 1), {_cursor.pos.x - this->left, click_y - y}); |
| 251 | return true; |
| 252 | } |
| 253 | y += item_height; |
| 254 | } |
| 255 | |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | void DrawWidget(const Rect &r, WidgetID widget) const override |
| 260 | { |
no test coverage detected