JDK-8314534 : Region.snapInnerSpace*()
  • Type: CSR
  • Component: javafx
  • Sub-Component: controls
  • Priority: P4
  • Status: Draft
  • Resolution: Unresolved
  • Fix Versions: tbd
  • Submitted: 2023-08-17
  • Updated: 2023-08-17
Related Reports
CSR :  
Description
Summary
-------

Adding Region.snapInnerSpaceX() and Region.snapInnerSpaceY() with the semantics of floor() operation to complement existing snapPositionX/Y and snapPortionX/Y methods.

Problem
-------

Some layout calculations need the snapped coordinates not to exceed some available space, such as width of the table header.  There are existing snapPortionX/Y methods with the required semantics, but they are not public.

Solution
--------

The solution is to add two new public methods. 

Specification
-------------

javafx.graphics/src/main/java/javafx/scene/layout/Region.java
```
+    /**
+     * If this region's snapToPixel property is true, then the value is either floored (positive values) or
+     * ceiled (negative values) with a scale. When the absolute value of the given value
+     * multiplied by the current scale is less than 10^15, then this method guarantees that:
+     *
+     * <pre>snapInnerSpaceX(snapInnerSpaceX(value)) == snapInnerSpaceX(value)</pre>
+     *
+     * The limit is about 10^15 because double values will no longer be able to represent
+     * larger integers with exact precision beyond this limit.
+     *
+     * @since 22
+     * @param value The value that needs to be snapped
+     * @return value either as passed, or floored or ceiled with scale, based on snapToPixel property
+     */
+    public double snapInnerSpaceX(double value) {
+        return snapPortionX(value, isSnapToPixel());
+    }
+
+    /**
+     * If this region's snapToPixel property is true, then the value is either floored (positive values) or
+     * ceiled (negative values) with a scale. When the absolute value of the given value
+     * multiplied by the current scale is less than 10^15, then this method guarantees that:
+     *
+     * <pre>snapInnerSpaceY(snapInnerSpaceY(value)) == snapInnerSpaceY(value)</pre>
+     *
+     * The limit is about 10^15 because double values will no longer be able to represent
+     * larger integers with exact precision beyond this limit.
+     *
+     * @since 22
+     * @param value The value that needs to be snapped
+     * @return value either as passed, or floored or ceiled with scale, based on snapToPixel property
+     */
+    public double snapInnerSpaceY(double value) {
+        return snapPortionY(value, isSnapToPixel());
+    }
```