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

Method EnsureSelectedTypeIsVisible

src/picker_gui.cpp:724–742  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

722}
723
724void PickerWindow::EnsureSelectedTypeIsVisible()
725{
726 if (!this->has_type_picker) return;
727 if (this->types.empty()) {
728 this->GetWidget<NWidgetMatrix>(WID_PW_TYPE_MATRIX)->SetClicked(-1);
729 return;
730 }
731
732 int class_index = this->callbacks.GetSelectedClass();
733 int index = this->callbacks.GetSelectedType();
734
735 auto it = std::ranges::find_if(this->types, [class_index, index](const auto &item) { return item.class_index == class_index && item.index == index; });
736 int pos = -1;
737 if (it != std::end(this->types)) {
738 pos = static_cast<int>(std::distance(std::begin(this->types), it));
739 }
740
741 this->GetWidget<NWidgetMatrix>(WID_PW_TYPE_MATRIX)->SetClicked(pos);
742}
743
744/** Create nested widgets for the class picker widgets. */
745std::unique_ptr<NWidgetBase> MakePickerClassWidgets()

Callers 1

OnInvalidateDataMethod · 0.95

Calls 6

SetClickedMethod · 0.80
endFunction · 0.50
beginFunction · 0.50
emptyMethod · 0.45
GetSelectedClassMethod · 0.45
GetSelectedTypeMethod · 0.45

Tested by

no test coverage detected