浏览代码

:arrow_up: Upgrade effects module

:recycle: MFXRippleGenerator: make sure the cached clip is updated when the region's layout bounds change

Signed-off-by: Alessadro Parisi <alessandro.parisi406@gmail.com>
Alessadro Parisi 2 年之前
父节点
当前提交
c0cca95384

+ 1 - 0
modules/effects/CHANGELOG.md

@@ -32,6 +32,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 - Improved efficiency of MFXRippleGenerators when disabled through the visible property. This was needed especially
 - Improved efficiency of MFXRippleGenerators when disabled through the visible property. This was needed especially
   because in CSS you cannot set the disable state but only the visibility
   because in CSS you cannot set the disable state but only the visibility
 - Moved Curve to new base package
 - Moved Curve to new base package
+- MFXRippleGenerator: make sure the cached clip is updated when the region's layout bounds change
 
 
 ## Removed
 ## Removed
 
 

+ 10 - 3
modules/effects/src/main/java/io/github/palexdev/mfxeffects/ripple/MFXRippleGenerator.java

@@ -30,6 +30,8 @@ import javafx.animation.Animation;
 import javafx.animation.Interpolator;
 import javafx.animation.Interpolator;
 import javafx.animation.ParallelTransition;
 import javafx.animation.ParallelTransition;
 import javafx.animation.Timeline;
 import javafx.animation.Timeline;
+import javafx.beans.InvalidationListener;
+import javafx.beans.WeakInvalidationListener;
 import javafx.css.*;
 import javafx.css.*;
 import javafx.event.EventHandler;
 import javafx.event.EventHandler;
 import javafx.geometry.Bounds;
 import javafx.geometry.Bounds;
@@ -44,6 +46,7 @@ import javafx.scene.shape.Shape;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.List;
 import java.util.List;
+import java.util.Optional;
 import java.util.function.Function;
 import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.function.Supplier;
 
 
@@ -98,8 +101,9 @@ public class MFXRippleGenerator extends Region implements RippleGenerator {
 	private Supplier<? extends Ripple<?>> rippleSupplier;
 	private Supplier<? extends Ripple<?>> rippleSupplier;
 	private Function<MouseEvent, Position> positionFunction;
 	private Function<MouseEvent, Position> positionFunction;
 
 
-	private final EventHandler<MouseEvent> handler;
 	private Node cachedClip;
 	private Node cachedClip;
+	private final EventHandler<MouseEvent> handler;
+	private final InvalidationListener clipUpdater;
 
 
 	//================================================================================
 	//================================================================================
 	// Constructors
 	// Constructors
@@ -107,6 +111,8 @@ public class MFXRippleGenerator extends Region implements RippleGenerator {
 	public MFXRippleGenerator(Region region) {
 	public MFXRippleGenerator(Region region) {
 		this.region = region;
 		this.region = region;
 		handler = this::generate;
 		handler = this::generate;
+		clipUpdater = new WeakInvalidationListener(i -> Optional.ofNullable(cachedClip)
+				.ifPresent(n -> n.resizeRelocate(0, 0, region.getWidth(), region.getHeight())));
 		initialize();
 		initialize();
 	}
 	}
 
 
@@ -118,6 +124,7 @@ public class MFXRippleGenerator extends Region implements RippleGenerator {
 		setClipSupplier(defaultClipSupplier());
 		setClipSupplier(defaultClipSupplier());
 		setPositionFunction(defaultPositionFunction());
 		setPositionFunction(defaultPositionFunction());
 		setRippleSupplier(defaultRippleSupplier());
 		setRippleSupplier(defaultRippleSupplier());
+		region.layoutBoundsProperty().addListener(clipUpdater);
 	}
 	}
 
 
 	/**
 	/**
@@ -253,9 +260,9 @@ public class MFXRippleGenerator extends Region implements RippleGenerator {
 			if (cachedClip != null) return cachedClip;
 			if (cachedClip != null) return cachedClip;
 			CornerRadii radius = StyleUtils.parseCornerRadius(region);
 			CornerRadii radius = StyleUtils.parseCornerRadius(region);
 			Region clip = new Region();
 			Region clip = new Region();
-			clip.resizeRelocate(0, 0, region.getWidth(), region.getHeight());
-			StyleUtils.setBackground(clip, Color.WHITE, radius);
 			cachedClip = clip;
 			cachedClip = clip;
+			StyleUtils.setBackground(clip, Color.WHITE, radius);
+			clipUpdater.invalidated(null);
 			return clip;
 			return clip;
 		}
 		}
 		return getClipSupplier().get();
 		return getClipSupplier().get();