我使用以下代码安装Layer
并GlassPane
显示它:
glassPane.getLayers().add(myLayer);
MobileApplication.getInstance().addLayerFactory("myLayer", ()-> myLayer);
MobileApplication.getInstance().showLayer("myLayer");
虽然在Charm 3.0.0
图层上在当前视图顶部显示模式,但在Charm 4.0.0
图层上不再是模式。那么是否有一个内置函数来再次显示它的模态,或者我们必须使用一个EventFilter
?
编辑:
ProgressLayer 完整代码 (不适配 Charm 4.0.0)
ProgressLayer的简化代码:
public class ProgressLayer extends Layer {
private static final GlassPane GLASS_PANE = MobileApplication.getInstance().getGlassPane();
private String layerName;
private StackPane root;
private Circle clip;
private double size;
public ProgressLayer(Node icon, double radius, String layerName) {
setAutoHide(false);
this.layerName = layerName;
size = radius * 2;
ProgressIndicator progress = new ProgressIndicator();
progress.setStyle("-fx-color:#ff9100");
progress.setRadius(radius);
root = new StackPane(progress);
if (icon != null) {
icon.getStyleClass().add("progress-icon");
clip = new Circle(radius-1);
icon.setClip(clip);
root.getChildren().add(icon);
}
getChildren().add(root);
GLASS_PANE.getLayers().add(this);
}
@Override
public void layoutChildren() {
root.setVisible(isShowing());
if (!isShowing()) {
return;
}
root.resizeRelocate((GLASS_PANE.getWidth() - size) / 2, (GLASS_PANE.getHeight() - size) / 2, size, size);
if (clip != null) {
clip.setLayoutX(root.getWidth() / 2 -1);
clip.setLayoutY(root.getHeight() /2 -1);
}
}
public void setOnCancelled(EventHandler<MouseEvent> handler) {
root.setOnMouseClicked(handler);
}
}
只要有操作在运行,progressLayer 就会显示出来,你不能中断操作或隐藏图层,除非你按下中间的紫色图标:
progressLayer.setOnCancelled(e -> hideLayer(progressLayer.getLayerName()));
这就是问题所在。当root
不使用整个屏幕尺寸时,root
可以激活未被类似按钮覆盖的 UI 控件。此行为与 Gluon Charm 3.0.0 形成对比