getZoomButtonX method

double getZoomButtonX(
  1. Size screenSize,
  2. double buttonX
)

Calculates optimal X position for zoom button

Tries to place the zoom button in the following priority order:

  1. To the right of main button (if space available)
  2. To the left of main button (if space available)
  3. Aligned with main button but constrained to screen bounds

Implementation

double getZoomButtonX(Size screenSize, double buttonX) {
  const double buttonWidth = 56.0;
  const double spacing = 14.0;

  // Try to place to the right of main button
  double rightPosition = buttonX + buttonWidth + spacing;

  // If there's space on the right, use it
  if (rightPosition + buttonWidth <= screenSize.width) {
    return rightPosition;
  }

  // Otherwise, place to the left of main button
  double leftPosition = buttonX - buttonWidth - spacing;

  // If there's space on the left, use it
  if (leftPosition >= 0) {
    return leftPosition;
  }

  // If neither side works, place it aligned with main button but constrained to screen
  return buttonX.clamp(0.0, screenSize.width - buttonWidth);
}