DynamicElementPosition.center constructor

DynamicElementPosition.center(
  1. PCanvasElement? parent, [
  2. PCanvasElement? element
])

Implementation

factory DynamicElementPosition.center(PCanvasElement? parent,
    [PCanvasElement? element]) {
  return DynamicElementPosition(parent, element, (o) {
    return (Point translate) {
      var parent = o.parent;
      var element = o.element;

      if (parent == null || element == null) {
        return Point.pZero;
      }

      var pD = parent.dimension;
      var d = element.dimension;

      num x = (pD.width - d.width) ~/ 2;
      num y = (pD.height - d.height) ~/ 2;

      if (!translate.isZero) {
        x += translate.x;
        y += translate.y;
      }

      return Point(x, y);
    };
  });
}