添加了字体缩放功能#6437
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'launcherFontSize' setting to allow users to customize the font size of the launcher. It updates the settings model, CSS stylesheet generation, personalization UI, and the JSON schema. The review feedback suggests several key improvements: restricting the font size input range in the UI to prevent layout breakage, binding the preview label to the font manager property for accurate rendering, adding defensive validation for manually edited settings, and updating the JSON schema with minimum and maximum constraints.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| FXUtils.bind(txtFontSize, settings().launcherFontSizeProperty(), SafeStringConverter.fromFiniteDouble() | ||
| .restrict(it -> it > 0) | ||
| .fallbackTo(FontManager.DEFAULT_FONT_SIZE) | ||
| .asPredicate(Validator.addTo(txtFontSize))); |
There was a problem hiding this comment.
字体大小的输入限制仅为 it > 0。这允许用户输入极小(如 0.1)或极大(如 10000)的值,这会导致启动器界面完全无法阅读或排版崩溃(即“软砖”风险)。建议将字体大小限制在合理的范围内(例如 6 到 72 之间),以确保界面的可用性。
| FXUtils.bind(txtFontSize, settings().launcherFontSizeProperty(), SafeStringConverter.fromFiniteDouble() | |
| .restrict(it -> it > 0) | |
| .fallbackTo(FontManager.DEFAULT_FONT_SIZE) | |
| .asPredicate(Validator.addTo(txtFontSize))); | |
| FXUtils.bind(txtFontSize, settings().launcherFontSizeProperty(), SafeStringConverter.fromFiniteDouble() | |
| .restrict(it -> it >= 6 && it <= 72) | |
| .fallbackTo(FontManager.DEFAULT_FONT_SIZE) | |
| .asPredicate(Validator.addTo(txtFontSize))); |
| lblFontDisplay.fontProperty().bind(Bindings.createObjectBinding( | ||
| () -> Font.font( | ||
| Lang.requireNonNullElse(settings().launcherFontFamilyProperty().get(), | ||
| Font.getDefault().getFamily()), | ||
| settings().launcherFontSizeProperty().get()), | ||
| settings().launcherFontFamilyProperty(), settings().launcherFontSizeProperty())); |
There was a problem hiding this comment.
预览标签 lblFontDisplay 直接绑定到了 settings().launcherFontFamilyProperty()。然而,如果用户没有显式设置字体家族(即为 null),启动器仍可能通过 FontManager 的回退机制从本地目录加载自定义字体。在这种情况下,启动器的实际界面会使用该自定义字体,但预览标签却会回退到系统默认字体 Font.getDefault().getFamily(),导致预览与实际效果不一致。建议绑定到 FontManager.fontProperty() 以确保预览始终与实际使用的字体一致。
| lblFontDisplay.fontProperty().bind(Bindings.createObjectBinding( | |
| () -> Font.font( | |
| Lang.requireNonNullElse(settings().launcherFontFamilyProperty().get(), | |
| Font.getDefault().getFamily()), | |
| settings().launcherFontSizeProperty().get()), | |
| settings().launcherFontFamilyProperty(), settings().launcherFontSizeProperty())); | |
| lblFontDisplay.fontProperty().bind(Bindings.createObjectBinding( | |
| () -> { | |
| var fontRef = FontManager.getFont(); | |
| return Font.font(fontRef != null ? fontRef.family() : Font.getDefault().getFamily(), | |
| settings().launcherFontSizeProperty().get()); | |
| }, | |
| FontManager.fontProperty(), settings().launcherFontSizeProperty())); |
| if (font == null || "System".equals(font.family())) | ||
| return defaultCss; | ||
| final boolean hasCustomFont = font != null && !"System".equals(font.family()); | ||
| final double fontSize = settings().launcherFontSizeProperty().get(); |
There was a problem hiding this comment.
防御性编程:如果用户手动编辑 launcher-settings.json 并将 launcherFontSize 设置为无效值(例如 <= 0、NaN 或无穷大),可能会生成无效的 CSS,从而导致渲染问题或解析器错误。建议在生成样式表之前对字体大小进行有效性校验,若无效则回退到默认值。
| final double fontSize = settings().launcherFontSizeProperty().get(); | |
| double rawFontSize = settings().launcherFontSizeProperty().get(); | |
| final double fontSize = (rawFontSize > 0 && Double.isFinite(rawFontSize)) ? rawFontSize : FontManager.DEFAULT_FONT_SIZE; |
| "launcherFontSize": { | ||
| "type": "number" | ||
| }, |
|
字体大小对 UI 的影响挺大的,从视频里就能看出。 之前已经有维护者拒绝过 #3543 |
|
从你的视频里也可以看出来,这项功能会导致大量 UI 布局被破坏。在迁移到 MD3 并重写大部分 UI 控件前我们不考虑这项功能。 未来如果我们要实现字体大小调整,可能也不会直接暴露出字体大小的数字,而是预设几个配置让用户选择。 |
untitled.mp4