getZoomButtonY method
Calculates optimal Y position for zoom button
Determines vertical placement based on available horizontal space:
- Same Y as main button (if zoom button fits horizontally beside it)
- Below main button (if space available)
- Above main button (if space available)
- Constrained to screen bounds as fallback
Implementation
double getZoomButtonY(Size screenSize, double buttonX, double buttonY) {
const double buttonHeight = 56.0;
const double spacing = 14.0;
// Check if zoom button fits horizontally beside main button
double rightPosition = buttonX + buttonHeight + spacing;
double leftPosition = buttonX - buttonHeight - spacing;
// If button can be placed beside main button, use same Y position
if ((rightPosition + buttonHeight <= screenSize.width) || (leftPosition >= 0)) {
return buttonY;
}
// Otherwise, place below main button
double belowPosition = buttonY + buttonHeight + spacing;
// If there's space below, use it
if (belowPosition + buttonHeight <= screenSize.height) {
return belowPosition;
}
// Otherwise, place above main button
double abovePosition = buttonY - buttonHeight - spacing;
// If there's space above, use it
if (abovePosition >= 0) {
return abovePosition;
}
// As last resort, constrain to screen bounds
return buttonY.clamp(0.0, screenSize.height - buttonHeight);
}