Interface IScaleProvider


public interface IScaleProvider
Supplies the raw measurements from which a UnitType scale table is built, so that a compiled Formula can be evaluated.

The interface mirrors the shape of the value getter it replaces, GUnit.getPixelValue(UIComp,boolean): a component-and-axis pair, decomposed into the individual quantities the units actually need. It deliberately knows nothing about UIComp, the property tree or the transaction classes, which is what keeps the whole com.iizix.prop.gunit package free of dependencies on the rest of the runtime.

The AXIS is not part of this interface. It is passed separately to UnitType.fillAxis(IScaleProvider,double[],int), because exactly two of the 29 units resolve differently per axis and the remaining 27 slots can be filled once per element and reused for both passes.

Defaults. The methods with a defined fallback have a default implementation, so that a server-side or Designer-side implementation only has to supply what it genuinely knows. Every default is documented at the method. The methods without a defensible fallback are abstract.

Author:
Christopher Mindus
  • Method Summary

    Modifier and Type
    Method
    Description
    default double
    Gets the component's own computed CSS max-height in pixels, used by the unit chmax, which resolves to that value.
    default double
    Gets the component's own computed CSS max-width in pixels, used by the unit cwmax, which resolves to that value.
    default double
    Gets the component's own computed CSS min-height in pixels, used by the unit chmin, which resolves to that value.
    default double
    Gets the component's own computed CSS min-width in pixels, used by the unit cwmin, which resolves to that value.
    default double
    Gets the device pixel ratio, used directly by dpr and as its reciprocal by dpx.
    double
    Gets the average character width of the element's own font.
    double
    Gets the EM size of the element's own font, used by em.
    double
    Gets the EX size, i.e.
    double
    Gets the height of the element's own font.
    double
    Gets the size of one point for the element, i.e.
    default double
    Gets the safe-area inset on the BOTTOM in pixels, used by nb.
    default double
    Gets the notch cutout bounding-box HEIGHT in screen space, in pixels, used by nh.
    default double
    Gets the safe-area inset on the LEFT in pixels, used by nl.
    default double
    Gets the safe-area inset on the RIGHT in pixels, used by nr.
    default double
    Gets the safe-area inset on the TOP in pixels, used by nt.
    default double
    Gets the notch cutout bounding-box WIDTH in screen space, in pixels, used by nw.
    default double
    Gets the offset along the top or bottom edge to the LEFT side of the notch, in pixels, used by nx.
    default double
    Gets the offset along the left or right edge to the TOP of the notch, in pixels, used by ny.
    double
    Gets the parent's height in CSS pixels, used by % on the Y pass, and by %h, %min and %max on both passes.
    double
    Gets the parent's width in CSS pixels, used by % on the X pass, and by %w, %min and %max on both passes.
    default double
    Gets the ROOT element font size, used by rem.
    double
    Gets the viewport height in CSS pixels, used by vh, vmin and vmax.
    double
    Gets the viewport width in CSS pixels, used by vw, vmin and vmax.
  • Method Details

    • getParentWidth

      double getParentWidth()
      Gets the parent's width in CSS pixels, used by % on the X pass, and by %w, %min and %max on both passes.
      Returns:
      The width in pixels.
    • getParentHeight

      double getParentHeight()
      Gets the parent's height in CSS pixels, used by % on the Y pass, and by %h, %min and %max on both passes.
      Returns:
      The height in pixels.
    • getViewportWidth

      double getViewportWidth()
      Gets the viewport width in CSS pixels, used by vw, vmin and vmax.
      Returns:
      The width in pixels.
    • getViewportHeight

      double getViewportHeight()
      Gets the viewport height in CSS pixels, used by vh, vmin and vmax.
      Returns:
      The height in pixels.
    • getFontEM

      double getFontEM()
      Gets the EM size of the element's own font, used by em.
      Returns:
      The EM size in pixels.
    • getFontEX

      double getFontEX()
      Gets the EX size, i.e. the x-height, of the element's own font, used by ex.
      Returns:
      The EX size in pixels.
    • getFontPT

      double getFontPT()
      Gets the size of one point for the element, i.e. dpi/72, used by pt.
      Returns:
      The point size in pixels.
    • getFontAverageWidth

      double getFontAverageWidth()
      Gets the average character width of the element's own font. Used by dlg on the X pass, where one dialog unit is a quarter of it.
      Returns:
      The average character width in pixels.
    • getFontHeight

      double getFontHeight()
      Gets the height of the element's own font. Used by dlg on the Y pass, where one dialog unit is an eighth of it.
      Returns:
      The font height in pixels.
    • getRootFontSize

      default double getRootFontSize()
      Gets the ROOT element font size, used by rem.

      The default returns getFontEM(), i.e. the element's own font size, which is correct for an element that does not override the root font size and is the safest stand-in where the root font size is unknown.

      Returns:
      The root font size in pixels.
    • getDevicePixelRatio

      default double getDevicePixelRatio()
      Gets the device pixel ratio, used directly by dpr and as its reciprocal by dpx.

      The default returns 1.0, which makes dpx and dpr both the identity and is the correct answer where the density is unknown, such as in the Designer.

      Must never return 0 or a non-finite value: dpx is 1/dpr and the division would produce an infinity. An infinity does not corrupt the result, since a non-finite result is clamped to 0 once at the end of the evaluation, but it turns the whole formula into 0 rather than degrading gracefully.

      Returns:
      The device pixel ratio, e.g. 1, 1.25, 1.5, 2 or 3.
    • getComponentMinWidth

      default double getComponentMinWidth()
      Gets the component's own computed CSS min-width in pixels, used by the unit cwmin, which resolves to that value.

      CSS default: min-width defaults to 0.

      This default returns 0, which is the same state. An unset min-width and a min-width of zero are genuinely indistinguishable in CSS as well, so nothing is lost and no approximation is being made.

      Why the minima and the maxima behave differently. The four methods here are NOT symmetric, and the asymmetry is deliberate rather than an oversight: see getComponentMaxWidth(). A default has to degrade in the direction that keeps formulas working, and for a minimum that direction is 0 while for a maximum it is "unbounded". Do not "tidy" the maxima back to 0.

      Returns:
      The computed minimum width in pixels, 0 when unset or unknown.
    • getComponentMaxWidth

      default double getComponentMaxWidth()
      Gets the component's own computed CSS max-width in pixels, used by the unit cwmax, which resolves to that value.

      CSS default: max-width defaults to none, meaning UNBOUNDED. It is not a number at all.

      This default returns getViewportWidth(), the widest thing the component could occupy, as the nearest finite stand-in for "unbounded".

      Why not 0. Zero says the exact opposite of none: it claims the component may not exceed nothing. A formula reading 100cwmax on a component with no max-width would collapse to zero, silently, and 0 is itself a legal max-width, so "unset" and max-width:0 could not be told apart.

      Why not a sentinel or a non-finite value. Infinity and NaN both reach the end-of-evaluation clamp, which turns a non-finite result into 0 -- reintroducing the same wrong answer one step later. NaN would additionally interact with the deliberate asymmetry in MIN2/MAX2, where a NaN on the right of the compare is discarded and one on the left survives, so the answer would depend on which side of a min() the unit happened to be written.

      The approximation is real and the caller cannot detect it. A component with no max-width and a component whose max-width genuinely equals the viewport width return the same number here, and nothing downstream can distinguish them. That is accepted: both mean "this constraint is not what is limiting me", which is what a formula asking for cwmax is almost always trying to find out.

      Returns:
      The computed maximum width in pixels, or the viewport width when the max-width is none or unknown.
    • getComponentMinHeight

      default double getComponentMinHeight()
      Gets the component's own computed CSS min-height in pixels, used by the unit chmin, which resolves to that value.

      CSS default: min-height defaults to 0.

      This default returns 0, which is the same state, exactly as for getComponentMinWidth(). Unset and zero are indistinguishable in CSS too.

      See getComponentMaxHeight() for why this method and its maximum counterpart do not default alike.

      Returns:
      The computed minimum height in pixels, 0 when unset or unknown.
    • getComponentMaxHeight

      default double getComponentMaxHeight()
      Gets the component's own computed CSS max-height in pixels, used by the unit chmax, which resolves to that value.

      CSS default: max-height defaults to none, meaning UNBOUNDED.

      This default returns getViewportHeight(), for exactly the reasons set out at getComponentMaxWidth(): 0 would assert the opposite of none and collapse 100chmax to zero; a sentinel or a non-finite value would be flattened to 0 by the end-of-evaluation clamp and would disturb the MIN2/MAX2 NaN asymmetry.

      The approximation is real and the caller cannot detect it: an unset max-height and one that genuinely equals the viewport height return the same number.

      Returns:
      The computed maximum height in pixels, or the viewport height when the max-height is none or unknown.
    • getNotchLeft

      default double getNotchLeft()
      Gets the safe-area inset on the LEFT in pixels, used by nl.

      The default returns 0, matching the existing server and Designer behaviour where all notch values evaluate to zero.

      Returns:
      The inset in pixels.
    • getNotchRight

      default double getNotchRight()
      Gets the safe-area inset on the RIGHT in pixels, used by nr. The default returns 0; see getNotchLeft().
      Returns:
      The inset in pixels.
    • getNotchTop

      default double getNotchTop()
      Gets the safe-area inset on the TOP in pixels, used by nt. The default returns 0; see getNotchLeft().
      Returns:
      The inset in pixels.
    • getNotchBottom

      default double getNotchBottom()
      Gets the safe-area inset on the BOTTOM in pixels, used by nb. The default returns 0; see getNotchLeft().
      Returns:
      The inset in pixels.
    • getNotchWidth

      default double getNotchWidth()
      Gets the notch cutout bounding-box WIDTH in screen space, in pixels, used by nw. See UnitType.UT_NW for what "screen space" means here and why this is no longer "the maximum of the left and right insets".

      The default returns 0; see getNotchLeft().

      Returns:
      The width in pixels, or 0 if unknown.
    • getNotchHeight

      default double getNotchHeight()
      Gets the notch cutout bounding-box HEIGHT in screen space, in pixels, used by nh. The default returns 0; see getNotchLeft().
      Returns:
      The height in pixels, or 0 if unknown.
    • getNotchX

      default double getNotchX()
      Gets the offset along the top or bottom edge to the LEFT side of the notch, in pixels, used by nx. Edge, not centre; see UnitType.UT_NX. The default returns 0; see getNotchLeft().
      Returns:
      The offset in pixels, or 0 if unknown or if the device is in landscape.
    • getNotchY

      default double getNotchY()
      Gets the offset along the left or right edge to the TOP of the notch, in pixels, used by ny. Edge, not centre; see UnitType.UT_NY. The default returns 0; see getNotchLeft().
      Returns:
      The offset in pixels, or 0 if unknown or if the device is in portrait.