修复应用外壳运行时样式与导航契约

This commit is contained in:
张家训
2026-08-01 16:52:08 +08:00
parent ce211c82a4
commit 855195e286
9 changed files with 441 additions and 179 deletions
@@ -114,15 +114,6 @@ public class WorkUtilsApplication implements CommandLineRunner {
settingsService.setNavItemsRefresher(ignoredItems -> Platform.runLater(() -> {
if (mainWindow != null) {
mainWindow.refreshNavItems(buildNavItems());
// 重新绑定插件面板
for (Plugin plugin : pluginManager.getEnabledPlugins()) {
PluginDescriptor desc = plugin.getDescriptor();
VisualPluginFactory factory = plugin.getVisualFactory();
Parent pane = factory != null ? factory.getEmbeddedPane() : null;
if (pane != null) {
mainWindow.embedPlugin(desc.getId(), desc.getIcon(), desc.getName(), pane);
}
}
}
}));
@@ -116,6 +116,8 @@ public class MainWindow {
Button menuButton = new Button(null, IconFactory.createButtonIcon(AppIcon.MENU, "切换导航栏"));
menuButton.setId("menu-button");
menuButton.setTooltip(new Tooltip("切换导航栏"));
menuButton.setAccessibleText("切换导航栏");
menuButton.setFocusTraversable(true);
menuButton.setOnAction(event -> navigationRail.toggle());
Label brand = new Label("WorkUtils", IconFactory.create(AppIcon.APP, 20));
@@ -135,9 +137,12 @@ public class MainWindow {
HBox.setHgrow(spacerRight, Priority.ALWAYS);
Button settingsButton = new Button(
null, IconFactory.createButtonIcon(AppIcon.SETTINGS, "系统设置"));
"系统设置", IconFactory.createButtonIcon(AppIcon.SETTINGS, "系统设置"));
settingsButton.setId("settings-button");
settingsButton.setTooltip(new Tooltip("系统设置"));
settingsButton.setAccessibleText("系统设置");
settingsButton.setContentDisplay(ContentDisplay.LEFT);
settingsButton.setFocusTraversable(true);
settingsButton.setOnAction(event -> openSettings.run());
bar.getChildren().addAll(
@@ -12,14 +12,11 @@ import javafx.css.PseudoClass;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import java.util.ArrayList;
@@ -41,7 +38,6 @@ public final class NavigationRail extends VBox {
private final List<ItemView> itemViews = new ArrayList<>();
private final Map<String, ItemView> viewsByPluginId = new LinkedHashMap<>();
private final VBox itemBox = new VBox();
private final Label brandLabel = new Label("WorkUtils");
private final Button collapseButton = new Button();
private MainWindow.NavItem selectedItem;
@@ -53,10 +49,13 @@ public final class NavigationRail extends VBox {
this.navigator = Objects.requireNonNull(navigator, "navigator must not be null");
getStyleClass().addAll(Theme.CSS_NAV_BAR, "navigation-rail");
buildHeader();
itemBox.getStyleClass().add("navigation-rail-items");
VBox.setVgrow(itemBox, Priority.ALWAYS);
getChildren().addAll(new Separator(), itemBox);
buildBottomToggle();
Separator separator = new Separator();
separator.getStyleClass().add(Theme.CSS_NAV_SEP);
getChildren().addAll(itemBox, separator, collapseButton);
expanded.addListener((observable, oldValue, newValue) -> updateAppearance());
setItems(items);
@@ -131,35 +130,31 @@ public final class NavigationRail extends VBox {
return view == null ? null : view.tooltip();
}
private void buildHeader() {
HBox header = new HBox(Theme.S2);
header.setAlignment(Pos.CENTER_LEFT);
header.setMinHeight(DesignTokens.HEADER_HEIGHT);
header.setPrefHeight(DesignTokens.HEADER_HEIGHT);
header.setMaxHeight(DesignTokens.HEADER_HEIGHT);
brandLabel.setGraphic(IconFactory.create(AppIcon.APP, 18));
brandLabel.setContentDisplay(ContentDisplay.LEFT);
brandLabel.setFont(Theme.sectionTitle());
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
collapseButton.getStyleClass().add("navigation-rail-toggle");
private void buildBottomToggle() {
collapseButton.setId("navigation-rail-toggle");
collapseButton.getStyleClass().addAll(Theme.CSS_NAV_CELL, "navigation-rail-toggle");
collapseButton.setContentDisplay(ContentDisplay.LEFT);
collapseButton.setGraphicTextGap(Theme.S3);
collapseButton.setMinHeight(DesignTokens.ROW_HEIGHT);
collapseButton.setPrefHeight(DesignTokens.ROW_HEIGHT);
collapseButton.setMaxHeight(DesignTokens.ROW_HEIGHT);
collapseButton.setMaxWidth(Double.MAX_VALUE);
collapseButton.setFocusTraversable(true);
collapseButton.setOnAction(event -> toggle());
header.getChildren().addAll(brandLabel, spacer, collapseButton);
getChildren().add(header);
}
private void addItem(MainWindow.NavItem item, int index) {
ToggleButton button = new ToggleButton(item.name, IconFactory.createButtonIcon(item.icon, item.name));
button.setToggleGroup(selection);
button.setContentDisplay(ContentDisplay.LEFT);
button.setGraphicTextGap(Theme.S3);
button.setAlignment(Pos.CENTER_LEFT);
button.setMinHeight(DesignTokens.ROW_HEIGHT);
button.setPrefHeight(DesignTokens.ROW_HEIGHT);
button.setMaxHeight(DesignTokens.ROW_HEIGHT);
button.setMaxWidth(Double.MAX_VALUE);
button.setAccessibleText(item.name);
button.setFocusTraversable(true);
button.getStyleClass().add(Theme.CSS_NAV_CELL);
if (item.pluginId != null) {
button.setId("nav-" + item.pluginId);
@@ -201,12 +196,15 @@ public final class NavigationRail extends VBox {
setMaxWidth(width);
pseudoClassStateChanged(COLLAPSED, !isExpanded());
brandLabel.setVisible(isExpanded());
brandLabel.setManaged(isExpanded());
String collapseLabel = isExpanded() ? "收起" : "展开";
String accessibleText = collapseLabel + "导航栏";
collapseButton.setGraphic(IconFactory.createButtonIcon(
isExpanded() ? AppIcon.CHEVRON_LEFT : AppIcon.CHEVRON_RIGHT,
isExpanded() ? "折叠导航" : "展开导航"));
collapseButton.setTooltip(new Tooltip(isExpanded() ? "折叠导航" : "展开导航"));
accessibleText));
collapseButton.setText(isExpanded() ? collapseLabel : null);
collapseButton.setAccessibleText(accessibleText);
collapseButton.setTooltip(new Tooltip(accessibleText));
collapseButton.setAlignment(isExpanded() ? Pos.CENTER_LEFT : Pos.CENTER);
updateItemAppearance();
}
@@ -216,6 +214,7 @@ public final class NavigationRail extends VBox {
ToggleButton button = view.button();
button.setText(isExpanded() ? item.name : null);
button.setTooltip(isExpanded() ? null : view.tooltip());
button.setAccessibleText(item.name);
button.setAlignment(isExpanded() ? Pos.CENTER_LEFT : Pos.CENTER);
}
}