On Mon, 3 Jun 2024 09:48:40 GMT, Florian Kirmaier <fkirma...@openjdk.org> wrote:

> Can you elaborate on this? Are changes in the Region.background still trigger 
> change events? If not, is there a mechanism to get them? Like 
> Transform.onTransformChanged? Are the previous immutable objects like 
> Background and Border now mutable?

I'm not entirely sure what you mean here, but nothing how backgrounds and 
borders work has changed. Both are still deeply immutable, what's new is that 
they implement `Interpolatable`.

For example, if you want to change the background color of a region, you can't 
reassign `BackgroundFill.fill`. Instead, you will have to create a new 
`Background` instance that contains a new `BackgroundFill`, which contains the 
new color. This is what CSS does when it applies a new background color.

This PR allows the CSS system to also create intermediate backgrounds that 
represent the transition from one color to the next.

The `interpolate()` method may or may not return a new instance of the 
interpolatable object. For example, consider the current version of 
`Color.interpolate()`, which returns `this` for t<=0 and `endValue` for t>=1 
(in other words, a new instance is not returned in all cases):

    @Override
    public Color interpolate(Color endValue, double t) {
        if (t <= 0.0) return this;
        if (t >= 1.0) return endValue;
        ...
    }


However, the current specification of `Interpolatable.interpolate()` is a bit 
unclear on that:

    /*
     * The function calculates an interpolated value along the fraction
     * {@code t} between {@code 0.0} and {@code 1.0}. When {@code t} = 1.0,
     * {@code endVal} is returned.
     */


The updated specification is clearer:


    /**
     * Returns an intermediate value between the value of this {@code 
Interpolatable} and the specified
     * {@code endValue} using the linear interpolation factor {@code t}, 
ranging from 0 (inclusive)
     * to 1 (inclusive).
     * <p>
     * The returned value may not be a new instance; an implementation might 
also return one of the
     * two existing instances if the intermediate value would be equal to one 
of the existing values.
     * However, this is an optimization and applications should not assume any 
particular identity
     * of the returned value.
     * <p>
     * An implementation is not required to reject interpolation factors less 
than 0 or larger than 1,
     * but this specification gives no meaning to values returned outside of 
this range. For example,
     * an implementation might clamp the interpolation factor to [0..1], or it 
might continue the linear
     * interpolation outside of this range.
     */

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1471#issuecomment-2145035539

Reply via email to