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

Function GuiGroupListAddChildren

src/group_gui.cpp:140–158  ·  view source on GitHub ↗

* Add children to GUI group list to build a hierarchical tree. * @param list Destination list. * @param item Group item to add children to. * @param fold Whether to handle group folding/hiding. * @param indent Current tree indentation level (set by self with recursion). */

Source from the content-addressed store, hash-verified

138 * @param indent Current tree indentation level (set by self with recursion).
139 */
140static void GuiGroupListAddChildren(GUIGroupList &list, GUIGroupListItem &item, bool fold, uint8_t indent = 1)
141{
142 if (fold && item.group->folded) {
143 Group::Get(item.group->index)->folded = !item.group->children.empty();
144 return;
145 }
146
147 if (item.group->children.empty()) return;
148
149 std::vector<GUIGroupListItem> sublist;
150 for (const GroupID &group : item.group->children) {
151 sublist.emplace_back(Group::Get(group), indent);
152 }
153 SortGUIGroupList(sublist);
154
155 for (const GUIGroupListItem &subitem : sublist) {
156 GuiGroupListAddChildren(list, list.emplace_back(subitem), fold, indent + 1);
157 }
158}
159
160/**
161 * Build GUI group list, a sorted hierarchical list of groups for owner and vehicle type.

Callers 1

BuildGuiGroupListFunction · 0.85

Calls 2

SortGUIGroupListFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected