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

Method RefreshScrollbar

src/vehicle_gui.cpp:883–901  ·  view source on GitHub ↗

* Refresh scrollbar after selection changed */

Source from the content-addressed store, hash-verified

881 * Refresh scrollbar after selection changed
882 */
883 void RefreshScrollbar()
884 {
885 size_t scroll_row = 0;
886 size_t rows = 0;
887 CargoType cargo = this->selected_refit == nullptr ? INVALID_CARGO : this->selected_refit->cargo;
888
889 for (const auto &pair : this->refit_list) {
890 if (pair.first == cargo) {
891 /* selected_refit points to an element in the vector so no need to search for it. */
892 scroll_row = rows + (this->selected_refit - pair.second.data());
893 rows += pair.second.size();
894 } else {
895 rows++; /* Unselected cargo type is collapsed into one row. */
896 }
897 }
898
899 this->vscroll->SetCount(rows);
900 this->vscroll->ScrollTowards(static_cast<int>(scroll_row));
901 }
902
903 /**
904 * Select a row.

Callers 1

OnInvalidateDataMethod · 0.95

Calls 4

ScrollTowardsMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
SetCountMethod · 0.45

Tested by

no test coverage detected