VPR-Frontend/client/app/src/main/java/helper/SvgBtnCreator.java

35 lines
1.0 KiB
Java
Raw Normal View History

2022-01-20 14:40:50 +01:00
package helper;
2022-01-20 13:49:07 +01:00
import javafx.geometry.Bounds;
import javafx.scene.Group;
import customUI.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.shape.SVGPath;
public class SvgBtnCreator {
public static Button createBtn(Group group, int svgSize) {
2022-01-20 13:49:07 +01:00
Button btn = new Button();
Bounds boundsDel = group.getBoundsInParent();
double scaleDel = Math.min(svgSize / boundsDel.getWidth(), svgSize / boundsDel.getHeight());
2022-01-20 13:49:07 +01:00
group.setScaleX(scaleDel);
group.setScaleY(scaleDel);
btn.setGraphic(group);
2022-01-20 13:52:35 +01:00
btn.setMaxSize(svgSize, svgSize);
btn.setMinSize(svgSize, svgSize);
2022-01-20 13:49:07 +01:00
btn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
return btn;
}
public static SVGPath createPath(String d, String fill, String hoverFill) {
SVGPath path = new SVGPath();
path.getStyleClass().add("svg");
path.setContent(d);
path.setStyle("-fill:" + fill + ";-hover-fill:"+hoverFill+';');
return path;
}
}