mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Simplify GetScrolledItemFromWidget() (#12556)
Return `auto`, which allows working with const containers, and use std::next instead of std::advance.
This commit is contained in:
parent
c82a2575d7
commit
3814adaba8
|
@ -875,15 +875,13 @@ public:
|
||||||
* @return Iterator to the element clicked at. If clicked at a wrong position, returns as interator to the end of the container.
|
* @return Iterator to the element clicked at. If clicked at a wrong position, returns as interator to the end of the container.
|
||||||
*/
|
*/
|
||||||
template <typename Tcontainer>
|
template <typename Tcontainer>
|
||||||
typename Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
|
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
|
||||||
{
|
{
|
||||||
assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
|
assert(static_cast<size_t>(this->GetCount()) == container.size()); // Scrollbar and container size must match.
|
||||||
size_type row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
|
size_type row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
|
||||||
if (row == Scrollbar::npos) return std::end(container);
|
if (row == Scrollbar::npos) return std::end(container);
|
||||||
|
|
||||||
typename Tcontainer::iterator it = std::begin(container);
|
return std::next(std::begin(container), row);
|
||||||
std::advance(it, row);
|
|
||||||
return it;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const;
|
EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const;
|
||||||
|
|
Loading…
Reference in New Issue