componentsAtLocation<T> method
- T locationContext,
- List<
T> ? nestedContexts, - T? transformContext(),
- bool checkContains(
- Component,
- T
This is a generic implementation of componentsAtPoint; refer to those docs for context.
This will find components intersecting a given location context T
. The
context can be a single point or a more complicated structure. How to
interpret the structure T is determined by the provided lambdas,
transformContext
and checkContains
.
A simple choice of T would be a simple point (i.e. Vector2). In that case
transformContext needs to be able to transform a Vector2 on the parent
coordinate space into the coordinate space of a provided
CoordinateTransform; and checkContains
must be able to determine if
a given Component "contains" the Vector2 (the definition of "contains"
will vary and shall be determined by the nature of the chosen location
context T
).
Implementation
@override
Iterable<Component> componentsAtLocation<T>(
T locationContext,
List<T>? nestedContexts,
T? Function(CoordinateTransform, T) transformContext,
bool Function(Component, T) checkContains,
) sync* {
final viewportPoint = transformContext(viewport, locationContext);
if (viewportPoint == null) {
return;
}
yield* viewport.componentsAtLocation(
viewportPoint,
nestedContexts,
transformContext,
checkContains,
);
if ((world?.isMounted ?? false) &&
currentCameras.length < maxCamerasDepth) {
if (checkContains(viewport, viewportPoint)) {
currentCameras.add(this);
final worldPoint = transformContext(viewfinder, viewportPoint);
if (worldPoint == null) {
return;
}
yield* viewfinder.componentsAtLocation(
worldPoint,
nestedContexts,
transformContext,
checkContains,
);
yield* world!.componentsAtLocation(
worldPoint,
nestedContexts,
transformContext,
checkContains,
);
currentCameras.removeLast();
}
}
}