Volver al índice
src/main/java/ar/com/companeros/panel/PanelLayout.java
package ar.com.companeros.panel;
import java.util.List;
/** Geometría independiente del renderizado para evitar botones superpuestos. */
public final class PanelLayout {
private PanelLayout() { }
public record Rect(int x, int y, int width, int height) {
public boolean overlaps(Rect other) {
return x < other.x + other.width && x + width > other.x
&& y < other.y + other.height && y + height > other.y;
}
}
public static Rect icon(int width, int height, List<Rect> occupied) {
for (int offset = 0; offset < height; offset += 24) {
for (int y : new int[]{height / 2 - 10 + offset, height / 2 - 10 - offset}) {
for (int x : new int[]{width / 2 - 180, width / 2 + 160, width - 24, 4}) {
Rect candidate = new Rect(x, y, 20, 20);
if (x >= 2 && y >= 2 && x + 20 <= width - 2 && y + 20 <= height - 2
&& occupied.stream().noneMatch(candidate::overlaps)) return candidate;
}
}
}
// Escalas pequeñas pueden dejar sólo una franja libre en el borde superior.
for (int y = 2; y + 20 <= height - 2; y += 2) for (int x : new int[]{width - 24, 4}) {
Rect candidate = new Rect(x, y, 20, 20);
if (x >= 2 && x + 20 <= width - 2 && occupied.stream().noneMatch(candidate::overlaps)) return candidate;
}
return null;
}
public static int panelWidth(int width) { return Math.max(200, Math.min(400, width - 24)); }
public static int rows(int height) { return Math.max(1, (height - 124) / 34); }
}