|
25 | 25 | import javafx.application.Platform; |
26 | 26 | import javafx.beans.property.BooleanProperty; |
27 | 27 | import javafx.beans.property.SimpleBooleanProperty; |
| 28 | +import javafx.event.ActionEvent; |
| 29 | +import javafx.event.Event; |
| 30 | +import javafx.event.EventHandler; |
28 | 31 | import javafx.geometry.Insets; |
29 | 32 | import javafx.geometry.Pos; |
30 | 33 | import javafx.scene.Node; |
|
35 | 38 | import org.jackhuang.hmcl.setting.Theme; |
36 | 39 | import org.jackhuang.hmcl.ui.FXUtils; |
37 | 40 | import org.jackhuang.hmcl.ui.SVG; |
| 41 | +import org.jackhuang.hmcl.ui.animation.AnimationUtils; |
38 | 42 |
|
39 | 43 | /** |
40 | 44 | * @author huangyuhui |
@@ -70,6 +74,7 @@ protected void layoutChildren() { |
70 | 74 | } |
71 | 75 | } |
72 | 76 |
|
| 77 | + @SuppressWarnings("unchecked") |
73 | 78 | private void updateLayout() { |
74 | 79 | if (content instanceof ComponentList) { |
75 | 80 | ComponentList list = (ComponentList) content; |
@@ -134,42 +139,66 @@ private void updateLayout() { |
134 | 139 | container.getChildren().setAll(content); |
135 | 140 | groupNode.getChildren().add(container); |
136 | 141 |
|
137 | | - Runnable onExpand = () -> { |
138 | | - if (expandAnimation != null && expandAnimation.getStatus() == Animation.Status.RUNNING) { |
139 | | - expandAnimation.stop(); |
140 | | - } |
| 142 | + EventHandler<Event> onExpand; |
| 143 | + if (AnimationUtils.isAnimationEnabled()) { |
| 144 | + onExpand = e -> { |
| 145 | + if (expandAnimation != null && expandAnimation.getStatus() == Animation.Status.RUNNING) { |
| 146 | + expandAnimation.stop(); |
| 147 | + } |
141 | 148 |
|
142 | | - setExpanded(!isExpanded()); |
| 149 | + setExpanded(!isExpanded()); |
143 | 150 |
|
144 | | - if (isExpanded()) { |
145 | | - list.onExpand(); |
146 | | - list.layout(); |
147 | | - } |
| 151 | + if (isExpanded()) { |
| 152 | + list.onExpand(); |
| 153 | + list.layout(); |
| 154 | + } |
| 155 | + |
| 156 | + Platform.runLater(() -> { |
| 157 | + double newAnimatedHeight = (content.prefHeight(-1) + 8 + 10) * (isExpanded() ? 1 : -1); |
| 158 | + double newHeight = isExpanded() ? getHeight() + newAnimatedHeight : prefHeight(-1); |
| 159 | + double contentHeight = isExpanded() ? newAnimatedHeight : 0; |
| 160 | + |
| 161 | + if (isExpanded()) { |
| 162 | + updateClip(newHeight); |
| 163 | + } |
| 164 | + |
| 165 | + expandAnimation = new Timeline(new KeyFrame(new Duration(320.0), |
| 166 | + new KeyValue(container.minHeightProperty(), contentHeight, FXUtils.SINE), |
| 167 | + new KeyValue(container.maxHeightProperty(), contentHeight, FXUtils.SINE) |
| 168 | + )); |
| 169 | + |
| 170 | + if (!isExpanded()) { |
| 171 | + expandAnimation.setOnFinished(e2 -> updateClip(newHeight)); |
| 172 | + } |
| 173 | + |
| 174 | + expandAnimation.play(); |
| 175 | + }); |
| 176 | + }; |
| 177 | + } else { |
| 178 | + onExpand = e -> { |
| 179 | + setExpanded(!isExpanded()); |
148 | 180 |
|
149 | | - Platform.runLater(() -> { |
150 | 181 | double newAnimatedHeight = (content.prefHeight(-1) + 8 + 10) * (isExpanded() ? 1 : -1); |
151 | 182 | double newHeight = isExpanded() ? getHeight() + newAnimatedHeight : prefHeight(-1); |
152 | 183 | double contentHeight = isExpanded() ? newAnimatedHeight : 0; |
153 | 184 |
|
154 | 185 | if (isExpanded()) { |
| 186 | + list.onExpand(); |
| 187 | + list.layout(); |
155 | 188 | updateClip(newHeight); |
156 | 189 | } |
157 | 190 |
|
158 | | - expandAnimation = new Timeline(new KeyFrame(new Duration(320.0), |
159 | | - new KeyValue(container.minHeightProperty(), contentHeight, FXUtils.SINE), |
160 | | - new KeyValue(container.maxHeightProperty(), contentHeight, FXUtils.SINE) |
161 | | - )); |
| 191 | + container.setMinHeight(contentHeight); |
| 192 | + container.setMaxHeight(contentHeight); |
162 | 193 |
|
163 | 194 | if (!isExpanded()) { |
164 | | - expandAnimation.setOnFinished(e2 -> updateClip(newHeight)); |
| 195 | + updateClip(newHeight); |
165 | 196 | } |
| 197 | + }; |
| 198 | + } |
166 | 199 |
|
167 | | - expandAnimation.play(); |
168 | | - }); |
169 | | - }; |
170 | | - |
171 | | - headerRippler.setOnMouseClicked(e -> onExpand.run()); |
172 | | - expandButton.setOnMouseClicked(e -> onExpand.run()); |
| 200 | + headerRippler.setOnMouseClicked(onExpand); |
| 201 | + expandButton.setOnAction((EventHandler<ActionEvent>) (Object) onExpand); |
173 | 202 |
|
174 | 203 | expandedProperty().addListener((a, b, newValue) -> |
175 | 204 | expandIcon.setRotate(newValue ? 180 : 0)); |
|
0 commit comments