Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8102549

Add convenience API for getting snapped insets to Region and SkinBase

    XMLWordPrintable

Details

    Description

      We have been endlessly chasing bugs in UI Controls Skins where we are not reliably and consistently snapping to pixels the insets/padding values used in computePref/Min/Max etc methods and in the layoutChildren method.

      So I am suggesting adding some helper methods to Region and passing in values to the compute methods so that its much easier for developers to have the correctly snapped values at hand.

      Region Additions

      public class Region {
          …..
          public int snappedTopInset()
          public int snappedBottomInset()
          public int snappedRightInset()
          public int snappedLeftInset()
          …..
      }

      These will the the equivalent of "snapSize(getInsets().getTop())" but can in the future be implemented in a more efficient way.

      Changes to SkinBase

      OLD
      public abstract class SkinBase<C extends Control> implements Skin<C> {
          …..
          protected double computeMinWidth(double height)
          protected double computeMinHeight(double width)
          protected double computeMaxWidth(double height)
          protected double computeMaxHeight(double width)
          protected double computePrefWidth(double height)
          protected double computePrefHeight(double width)
          public double getBaselineOffset()
          …..
      }

      NEW
      public abstract class SkinBase<C extends Control> implements Skin<C> {
          …..
          protected double computeMinWidth(double height, int topInset, int rightInset, int bottomInset, int leftInset)
          protected double computeMinHeight(double width, int topInset, int rightInset, int bottomInset, int leftInset)
          protected double computeMaxWidth(double height, int topInset, int rightInset, int bottomInset, int leftInset)
          protected double computeMaxHeight(double width, int topInset, int rightInset, int bottomInset, int leftInset)
          protected double computePrefWidth(double height, int topInset, int rightInset, int bottomInset, int leftInset)
          protected double computePrefHeight(double width, int topInset, int rightInset, int bottomInset, int leftInset)
          public double computeBaselineOffset(int topInset, int rightInset, int bottomInset, int leftInset)
          …..
          // plus new methods
          protected int snappedTopInset()
          protected int snappedBottomInset()
          protected int snappedLeftInset()
          protected int snappedRightInset()
          .....
      }

      The topInsets etc will be calculated as getSkinnable().snappedTopInset(). The change from getBaselineOffset() to computeBaselineOffset() is just to make it clear this method is responsible for computing this value not getting one someone else has computed. The snappedXXXInset() map to getSkinnable().snappedXXXInset() which makes it easy to constantly use snappedXXXInset() in skin code if you are either in a SkinBase subclass or a Region Subclass.

      IMPORTANT! As part of this fix I will go though and clean up all uses in controls and charts of Region.getInsets() to make sure we have consistent usage.

      I am really hopping this will make it easy to maintain consistent behavior as we work on controls implementations in the future.

      Attachments

        Activity

          People

            jasper Jasper Potts (Inactive)
            jasper Jasper Potts (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: