protected void doValidate()

in view/src/main/java/jetbrains/jetpad/projectional/view/util/RelativePositionerView.java [49:92]


  protected void doValidate(ValidationContext ctx) {
    super.doValidate(ctx);

    Vector relativeTo = relativeTo().get();
    HorizontalAnchor hAnchor = horizontalAnchor().get();
    VerticalAnchor vAnchor = verticalAnchor().get();

    for (View child : children()) {
      Rectangle childBounds = child.bounds().get();
      int x = 0;
      int y = 0;

      if (hAnchor == HorizontalAnchor.LEFT) {
        x = 0;
      } else if (hAnchor == HorizontalAnchor.RIGHT) {
        x = -childBounds.dimension.x;
      } else if (hAnchor == HorizontalAnchor.CENTER) {
        x = -childBounds.dimension.x / 2;
      }

      if (vAnchor == VerticalAnchor.BASELINE) {
        y = child.baseLine();
      } else if (vAnchor == VerticalAnchor.TOP) {
        y = 0;
      } else if (vAnchor == VerticalAnchor.BOTTOM) {
        y = -childBounds.dimension.y;
      } else if (vAnchor == VerticalAnchor.CENTER) {
        y = -childBounds.dimension.y / 2;
      }

      child.moveTo(relativeTo.add(new Vector(x, y)));
    }

    Rectangle bounds = null;
    for (View child  : children()) {
      if (bounds == null) {
        bounds = child.bounds().get();
      } else {
        bounds = bounds.union(child.bounds().get());
      }
    }

    ctx.bounds(bounds != null ? bounds : new Rectangle(Vector.ZERO, Vector.ZERO), 0);
  }