Position svg logo

This commit is contained in:
2026-03-11 12:34:45 -06:00
parent e070e7d367
commit 6b54654d7e

View File

@@ -1,7 +1,7 @@
package org.example.petshopdesktop.ui;
import javafx.scene.Group;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.FillRule;
@@ -24,18 +24,20 @@ public final class SvgNodeLoader {
private SvgNodeLoader() {
}
public static StackPane loadSquare(String resourcePath, double size) {
public static Pane loadSquare(String resourcePath, double size) {
Group content = readSvg(resourcePath);
var bounds = content.getLayoutBounds();
Group translated = new Group(content);
translated.setTranslateX(-bounds.getMinX());
translated.setTranslateY(-bounds.getMinY());
double scale = Math.min(size / bounds.getWidth(), size / bounds.getHeight());
translated.setScaleX(scale);
translated.setScaleY(scale);
StackPane pane = new StackPane(translated);
Group graphic = new Group(content);
graphic.setScaleX(scale);
graphic.setScaleY(scale);
graphic.relocate(
(size - (bounds.getWidth() * scale)) / 2 - (bounds.getMinX() * scale),
(size - (bounds.getHeight() * scale)) / 2 - (bounds.getMinY() * scale)
);
Pane pane = new Pane(graphic);
pane.setMinSize(size, size);
pane.setPrefSize(size, size);
pane.setMaxSize(size, size);
@@ -176,6 +178,4 @@ public final class SvgNodeLoader {
styleMap.put(attribute, value);
}
}
}