Skip to content

将 JFXToggleButton 更新至 MD3 风格#6131

Open
Glavo wants to merge 1 commit into
HMCL-dev:mainfrom
Glavo:switch
Open

将 JFXToggleButton 更新至 MD3 风格#6131
Glavo wants to merge 1 commit into
HMCL-dev:mainfrom
Glavo:switch

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented May 21, 2026

No description provided.

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented May 21, 2026

/gemini review

Copy link
Copy Markdown
Contributor

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

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 updates the JFXToggleButton and its skin to implement Material Design 3 switch specifications. It introduces new styleable properties for touch target size and track shape while maintaining legacy size scaling for backward compatibility. The JFXToggleButtonSkin has been completely rewritten to support M3 visuals, including state layers and ripples, using standard JavaFX Timeline animations. Review feedback suggests using primitive boolean types for the disableVisualFocus and disableAnimation property accessors instead of boxed Boolean types to align with JavaFX best practices and eliminate unnecessary null checks.

Comment on lines +196 to 203
public final Boolean isDisableVisualFocus() {
return disableVisualFocus != null && disableVisualFocus.get();
}

public StyleableObjectProperty<Paint> unToggleLineColorProperty() {
return this.untoggleLineColor;
/// Sets whether focus state layers should be hidden.
public final void setDisableVisualFocus(Boolean disabled) {
disableVisualFocusProperty().set(Objects.requireNonNull(disabled, "disabled"));
}
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

The methods isDisableVisualFocus and setDisableVisualFocus use the boxed Boolean type. In JavaFX, it is standard practice to use the primitive boolean type for property getters and setters to avoid unnecessary boxing/unboxing and to prevent potential null values where they are not expected. Using boolean also eliminates the need for Objects.requireNonNull in the setter.

Suggested change
public final Boolean isDisableVisualFocus() {
return disableVisualFocus != null && disableVisualFocus.get();
}
public StyleableObjectProperty<Paint> unToggleLineColorProperty() {
return this.untoggleLineColor;
/// Sets whether focus state layers should be hidden.
public final void setDisableVisualFocus(Boolean disabled) {
disableVisualFocusProperty().set(Objects.requireNonNull(disabled, "disabled"));
}
/// Returns whether focus state layers are hidden.
public final boolean isDisableVisualFocus() {
return disableVisualFocus != null && disableVisualFocus.get();
}
/// Sets whether focus state layers should be hidden.
public final void setDisableVisualFocus(boolean disabled) {
disableVisualFocusProperty().set(disabled);
}

Comment on lines +219 to 226
public final Boolean isDisableAnimation() {
return disableAnimation != null ? disableAnimation.get() : !AnimationUtils.isAnimationEnabled();
}

public StyleableDoubleProperty sizeProperty() {
return this.size;
/// Sets whether switch animations should be disabled.
public final void setDisableAnimation(Boolean disabled) {
disableAnimationProperty().set(Objects.requireNonNull(disabled, "disabled"));
}
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

Similar to disableVisualFocus, the isDisableAnimation and setDisableAnimation methods should use the primitive boolean type instead of the boxed Boolean type to align with JavaFX best practices and simplify the implementation.

Suggested change
public final Boolean isDisableAnimation() {
return disableAnimation != null ? disableAnimation.get() : !AnimationUtils.isAnimationEnabled();
}
public StyleableDoubleProperty sizeProperty() {
return this.size;
/// Sets whether switch animations should be disabled.
public final void setDisableAnimation(Boolean disabled) {
disableAnimationProperty().set(Objects.requireNonNull(disabled, "disabled"));
}
/// Returns whether switch animations are disabled.
public final boolean isDisableAnimation() {
return disableAnimation != null ? disableAnimation.get() : !AnimationUtils.isAnimationEnabled();
}
/// Sets whether switch animations should be disabled.
public final void setDisableAnimation(boolean disabled) {
disableAnimationProperty().set(disabled);
}

@Glavo Glavo marked this pull request as ready for review May 21, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant