selectElementWhere<T extends PCanvasElement> method

List<T> selectElementWhere<T extends PCanvasElement>(
  1. bool selector(
    1. T elem
    ), {
  2. bool recursive = false,
})

Returns a list of PCanvasElement of type T filtered by selector.

Implementation

List<T> selectElementWhere<T extends PCanvasElement>(
    bool Function(T elem) selector,
    {bool recursive = false}) {
  var elements = this.elements;

  var sel = elements.whereType<T>().where(selector).toList();

  if (!recursive) {
    return sel;
  }

  var subList = elements
      .whereType<PCanvasElementContainer>()
      .expand((e) => e.selectElementWhere<T>(selector, recursive: true))
      .toList();

  return [...sel, ...subList];
}