All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
tornadofx.control.skin.ListMenuSkin Maven / Gradle / Ivy
package tornadofx.control.skin;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.SkinBase;
import tornadofx.control.ListMenu;
import java.util.function.Function;
public class ListMenuSkin extends SkinBase {
public ListMenuSkin(ListMenu control) {
super(control);
}
private double acc(Function fn) {
double val = 0;
for (Node node : getChildren())
val += fn.apply(node);
return val;
}
private double biggest(Function fn) {
double val = 0d;
for (Node node : getChildren()) {
double nval = fn.apply(node);
if (nval > val)
val = nval;
}
return val;
}
protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
if (getSkinnable().getOrientation() == Orientation.VERTICAL)
return biggest(n -> n.minWidth(height));
else
return acc(n -> n.minWidth(height));
}
protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
if (getSkinnable().getOrientation() == Orientation.VERTICAL)
return acc(n -> n.minHeight(width));
else
return biggest(n -> n.minHeight(width));
}
protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
double prefWidth;
if (getSkinnable().getOrientation() == Orientation.VERTICAL)
prefWidth = biggest(n -> n.prefWidth(height)) + leftInset + rightInset;
else
prefWidth = acc(n -> n.prefWidth(height)) + leftInset + rightInset;
return Math.max(prefWidth, getSkinnable().getPrefWidth());
}
protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
double prefHeight;
if (getSkinnable().getOrientation() == Orientation.VERTICAL)
prefHeight = acc(n -> n.prefHeight(width)) + topInset + bottomInset;
else
prefHeight = biggest(n -> n.prefHeight(width)) + topInset + bottomInset;
return Math.max(prefHeight, getSkinnable().getPrefHeight());
}
protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
return computePrefWidth(height, topInset, rightInset, bottomInset, leftInset);
}
protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
return computePrefHeight(width, topInset, rightInset, bottomInset, leftInset);
}
protected void layoutChildren(double x, double y, double w, double h) {
for (Node node : getChildren()) {
if (getSkinnable().getOrientation() == Orientation.VERTICAL) {
double prefHeight = node.prefHeight(-1);
node.resizeRelocate(x, y, w, prefHeight);
y += prefHeight;
} else {
double prefWidth = node.prefWidth(-1);
node.resizeRelocate(x, y, prefWidth, h);
x += prefWidth;
}
}
}
}