Skip to content

添加了字体缩放功能#6437

Closed
Z9CR wants to merge 1 commit into
HMCL-dev:mainfrom
Z9CR:main
Closed

添加了字体缩放功能#6437
Z9CR wants to merge 1 commit into
HMCL-dev:mainfrom
Z9CR:main

Conversation

@Z9CR

@Z9CR Z9CR commented Jul 19, 2026

Copy link
Copy Markdown
untitled.mp4

@github-actions github-actions Bot added the 100+ label Jul 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1208 to +1211
FXUtils.bind(txtFontSize, settings().launcherFontSizeProperty(), SafeStringConverter.fromFiniteDouble()
.restrict(it -> it > 0)
.fallbackTo(FontManager.DEFAULT_FONT_SIZE)
.asPredicate(Validator.addTo(txtFontSize)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

字体大小的输入限制仅为 it > 0。这允许用户输入极小(如 0.1)或极大(如 10000)的值,这会导致启动器界面完全无法阅读或排版崩溃(即“软砖”风险)。建议将字体大小限制在合理的范围内(例如 672 之间),以确保界面的可用性。

Suggested change
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)));

Comment on lines +1225 to +1230
lblFontDisplay.fontProperty().bind(Bindings.createObjectBinding(
() -> Font.font(
Lang.requireNonNullElse(settings().launcherFontFamilyProperty().get(),
Font.getDefault().getFamily()),
settings().launcherFontSizeProperty().get()),
settings().launcherFontFamilyProperty(), settings().launcherFontSizeProperty()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

预览标签 lblFontDisplay 直接绑定到了 settings().launcherFontFamilyProperty()。然而,如果用户没有显式设置字体家族(即为 null),启动器仍可能通过 FontManager 的回退机制从本地目录加载自定义字体。在这种情况下,启动器的实际界面会使用该自定义字体,但预览标签却会回退到系统默认字体 Font.getDefault().getFamily(),导致预览与实际效果不一致。建议绑定到 FontManager.fontProperty() 以确保预览始终与实际使用的字体一致。

Suggested change
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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

防御性编程:如果用户手动编辑 launcher-settings.json 并将 launcherFontSize 设置为无效值(例如 <= 0NaN 或无穷大),可能会生成无效的 CSS,从而导致渲染问题或解析器错误。建议在生成样式表之前对字体大小进行有效性校验,若无效则回退到默认值。

Suggested change
final double fontSize = settings().launcherFontSizeProperty().get();
double rawFontSize = settings().launcherFontSizeProperty().get();
final double fontSize = (rawFontSize > 0 && Double.isFinite(rawFontSize)) ? rawFontSize : FontManager.DEFAULT_FONT_SIZE;

Comment on lines +141 to +143
"launcherFontSize": {
"type": "number"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了与 UI 中的限制保持一致,并防止在配置文件中写入不合理的字体大小,建议在 JSON Schema 中为 launcherFontSize 添加 minimummaximum 约束。

    "launcherFontSize": {
      "type": "number",
      "minimum": 6,
      "maximum": 72
    },

@3gf8jv4dv

Copy link
Copy Markdown
Contributor

字体大小对 UI 的影响挺大的,从视频里就能看出。

之前已经有维护者拒绝过 #3543

@Glavo

Glavo commented Jul 19, 2026

Copy link
Copy Markdown
Member

从你的视频里也可以看出来,这项功能会导致大量 UI 布局被破坏。在迁移到 MD3 并重写大部分 UI 控件前我们不考虑这项功能。

未来如果我们要实现字体大小调整,可能也不会直接暴露出字体大小的数字,而是预设几个配置让用户选择。

@Glavo Glavo closed this Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants