MCPcopy Create free account
hub / github.com/axmolengine/axmol / findNearestChildWidgetIndex

Method findNearestChildWidgetIndex

core/ui/UILayout.cpp:1161–1206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1159}
1160
1161int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWidget)
1162{
1163 if (baseWidget == nullptr || baseWidget == this)
1164 {
1165 return this->findFirstFocusEnabledWidgetIndex();
1166 }
1167 int index = 0;
1168 ssize_t count = this->getChildren().size();
1169
1170 float distance = FLT_MAX;
1171 int found = 0;
1172 if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT || direction == FocusDirection::DOWN ||
1173 direction == FocusDirection::UP)
1174 {
1175 Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
1176 while (index < count)
1177 {
1178 Widget* w = dynamic_cast<Widget*>(this->getChildren().at(index));
1179 if (w && w->isFocusEnabled())
1180 {
1181 Vec2 wPosition = this->getWorldCenterPoint(w);
1182 float length;
1183 Layout* layout = dynamic_cast<Layout*>(w);
1184 if (layout)
1185 {
1186 length = layout->calculateNearestDistance(baseWidget);
1187 }
1188 else
1189 {
1190 length = (wPosition - widgetPosition).getLength();
1191 }
1192
1193 if (length < distance)
1194 {
1195 found = index;
1196 distance = length;
1197 }
1198 }
1199 index++;
1200 }
1201 return found;
1202 }
1203
1204 AXASSERT(0, "invalid focus direction!!!");
1205 return 0;
1206}
1207
1208int Layout::findFarthestChildWidgetIndex(FocusDirection direction, ax::ui::Widget* baseWidget)
1209{

Callers

nothing calls this directly

Calls 7

getWorldCenterPointMethod · 0.95
isFocusEnabledMethod · 0.80
sizeMethod · 0.45
atMethod · 0.45
getLengthMethod · 0.45

Tested by

no test coverage detected