mirror of
https://github.com/octopusYan/alist-gui.git
synced 2024-11-22 03:56:42 +08:00
chore: 添加窗体阴影
This commit is contained in:
parent
fdbafdbb3f
commit
4692e4b436
@ -4,6 +4,7 @@ import cn.octopusyan.alistgui.base.BaseController;
|
||||
import cn.octopusyan.alistgui.controller.MainController;
|
||||
import cn.octopusyan.alistgui.controller.RootController;
|
||||
import cn.octopusyan.alistgui.controller.SetupController;
|
||||
import cn.octopusyan.alistgui.manager.ConfigManager;
|
||||
import cn.octopusyan.alistgui.util.FxmlUtil;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.StringBinding;
|
||||
@ -12,13 +13,11 @@ import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.effect.DropShadow;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.util.Callback;
|
||||
import lombok.Getter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -35,9 +34,11 @@ public class Context {
|
||||
private static final Logger log = LoggerFactory.getLogger(Context.class);
|
||||
private static Scene scene;
|
||||
private static final IntegerProperty currentViewIndexProperty = new SimpleIntegerProperty(0);
|
||||
// 获取控制器集合
|
||||
/**
|
||||
* 控制器集合
|
||||
*/
|
||||
@Getter
|
||||
private static final Map<String, BaseController<?>> controllers = new HashMap<>();
|
||||
/**
|
||||
* 默认语言文件 Base Name
|
||||
@ -61,11 +62,6 @@ public class Context {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
// 获取控制器集合
|
||||
public static Map<String, BaseController<?>> getControllers() {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
// 获取控制工厂
|
||||
public static Callback<Class<?>, Object> getControlFactory() {
|
||||
return type -> {
|
||||
@ -171,39 +167,34 @@ public class Context {
|
||||
private static void loadScene() throws IOException {
|
||||
FXMLLoader loader = FxmlUtil.load("root-view");
|
||||
loader.setControllerFactory(Context.getControlFactory());
|
||||
Parent root = loader.load();//底层面板
|
||||
// bindShadow((Pane) root);
|
||||
//底层面板
|
||||
Pane root = loader.load();
|
||||
Optional.ofNullable(scene).ifPresentOrElse(
|
||||
s -> s.setRoot(root),
|
||||
() -> {
|
||||
scene = new Scene(root);
|
||||
URL resource = Objects.requireNonNull(Context.class.getResource("/css/root.css"));
|
||||
scene = new Scene(root, root.getPrefWidth() + 20, root.getPrefHeight() + 20, Color.TRANSPARENT);
|
||||
URL resource = Objects.requireNonNull(Context.class.getResource("/css/root-view.css"));
|
||||
scene.getStylesheets().addAll(resource.toExternalForm());
|
||||
scene.setFill(Color.TRANSPARENT);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 设置当前展示的界面
|
||||
public static void setCurrentViewIndex(Number newValue) {
|
||||
currentViewIndexProperty.setValue(newValue);
|
||||
/**
|
||||
* 设置当前展示的界面
|
||||
*
|
||||
* @param index 界面Index
|
||||
*/
|
||||
public static void setCurrentViewIndex(Number index) {
|
||||
currentViewIndexProperty.setValue(index);
|
||||
}
|
||||
|
||||
// 获取当前展示的界面Index
|
||||
/**
|
||||
* 获取当前展示的界面Index
|
||||
*
|
||||
* @return 界面Index
|
||||
*/
|
||||
public static Integer getCurrentViewIndex() {
|
||||
return currentViewIndexProperty.get();
|
||||
}
|
||||
|
||||
private static void bindShadow(Pane pane) {
|
||||
Pane root = new Pane();
|
||||
root.setPadding(new Insets(20, 20, 20, 20));
|
||||
DropShadow dropshadow = new DropShadow();// 阴影向外
|
||||
dropshadow.setRadius(10);// 颜色蔓延的距离
|
||||
dropshadow.setOffsetX(0);// 水平方向,0则向左右两侧,正则向右,负则向左
|
||||
dropshadow.setOffsetY(0);// 垂直方向,0则向上下两侧,正则向下,负则向上
|
||||
dropshadow.setSpread(0.1);// 颜色变淡的程度
|
||||
dropshadow.setColor(Color.BLACK);// 设置颜色
|
||||
root.setEffect(dropshadow);// 绑定指定窗口控件
|
||||
root.getChildren().addAll(pane);
|
||||
}
|
||||
}
|
@ -2,13 +2,17 @@
|
||||
* Root
|
||||
**************************************************/
|
||||
|
||||
.root {
|
||||
.root-pane {
|
||||
-fx-font-size: 15;
|
||||
-fx-font-weight: normal;
|
||||
}
|
||||
|
||||
.root-pane {
|
||||
-fx-background-radius: 15;
|
||||
-fx-border-radius: 15;
|
||||
|
||||
// 窗口阴影
|
||||
-fx-background-color: rgba(255, 255, 255, 1);
|
||||
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.3), 15, 0, 0, 0);
|
||||
-fx-background-insets: 20;
|
||||
-fx-padding: 20;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user