-
Notifications
You must be signed in to change notification settings - Fork 534
Expand file tree
/
Copy pathScalePane.java
More file actions
55 lines (46 loc) · 1.29 KB
/
Copy pathScalePane.java
File metadata and controls
55 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package software.coley.recaf.ui.pane;
import jakarta.annotation.Nonnull;
import javafx.beans.property.DoubleProperty;
import javafx.scene.Node;
import javafx.scene.layout.Pane;
import javafx.scene.transform.Scale;
/**
* Wraps a child node and scales it by {@code scale} while keeping it sized to fill this pane.
*/
public class ScalePane extends Pane {
private final DoubleProperty scale;
private final Node content;
/**
* @param content
* Original scene root to wrap (must have no parent!).
* @param scale
* Factor to scale by.
*/
public ScalePane(@Nonnull Node content, @Nonnull DoubleProperty scale) {
this.scale = scale;
this.content = content;
//Pivot so the child grows down/right to fill the window
var transform = new Scale();
transform.xProperty().bind(scale);
transform.yProperty().bind(scale);
content.getTransforms().add(transform);
//Reparent the orphaned root into this pane
getChildren().add(content);
scale.addListener(o -> requestLayout());
}
/**
* @return The wrapped original root.
*/
@Nonnull
public Node getContent() {
return content;
}
@Override
protected void layoutChildren() {
var scale = this.scale.get();
if (scale <= 0)
scale = 1;
content.resize(getWidth() / scale, getHeight() / scale);
content.relocate(0, 0);
}
}