Interface IScaleProvider
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 TypeMethodDescriptiondefault doubleGets the component's own computed CSSmax-heightin pixels, used by the unitchmax, which resolves to that value.default doubleGets the component's own computed CSSmax-widthin pixels, used by the unitcwmax, which resolves to that value.default doubleGets the component's own computed CSSmin-heightin pixels, used by the unitchmin, which resolves to that value.default doubleGets the component's own computed CSSmin-widthin pixels, used by the unitcwmin, which resolves to that value.default doubleGets the device pixel ratio, used directly bydprand as its reciprocal bydpx.doubleGets the average character width of the element's own font.doubleGets the EM size of the element's own font, used byem.doubleGets the EX size, i.e.doubleGets the height of the element's own font.doubleGets the size of one point for the element, i.e.default doubleGets the safe-area inset on the BOTTOM in pixels, used bynb.default doubleGets the notch cutout bounding-box HEIGHT in screen space, in pixels, used bynh.default doubleGets the safe-area inset on the LEFT in pixels, used bynl.default doubleGets the safe-area inset on the RIGHT in pixels, used bynr.default doubleGets the safe-area inset on the TOP in pixels, used bynt.default doubleGets the notch cutout bounding-box WIDTH in screen space, in pixels, used bynw.default doubleGets the offset along the top or bottom edge to the LEFT side of the notch, in pixels, used bynx.default doubleGets the offset along the left or right edge to the TOP of the notch, in pixels, used byny.doubleGets the parent's height in CSS pixels, used by%on the Y pass, and by%h,%minand%maxon both passes.doubleGets the parent's width in CSS pixels, used by%on the X pass, and by%w,%minand%maxon both passes.default doubleGets the ROOT element font size, used byrem.doubleGets the viewport height in CSS pixels, used byvh,vminandvmax.doubleGets the viewport width in CSS pixels, used byvw,vminandvmax.
Method Details
getParentWidth
double getParentWidth()Gets the parent's width in CSS pixels, used by%on the X pass, and by%w,%minand%maxon 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,%minand%maxon both passes.- Returns:
- The height in pixels.
getViewportWidth
double getViewportWidth()Gets the viewport width in CSS pixels, used byvw,vminandvmax.- Returns:
- The width in pixels.
getViewportHeight
double getViewportHeight()Gets the viewport height in CSS pixels, used byvh,vminandvmax.- Returns:
- The height in pixels.
getFontEM
double getFontEM()Gets the EM size of the element's own font, used byem.- 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 byex.- Returns:
- The EX size in pixels.
getFontPT
double getFontPT()Gets the size of one point for the element, i.e. dpi/72, used bypt.- Returns:
- The point size in pixels.
getFontAverageWidth
double getFontAverageWidth()Gets the average character width of the element's own font. Used bydlgon 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 bydlgon 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 byrem.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 bydprand as its reciprocal bydpx.The default returns 1.0, which makes
dpxanddprboth 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:
dpxis1/dprand 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 CSSmin-widthin pixels, used by the unitcwmin, which resolves to that value.CSS default:
min-widthdefaults to0.This default returns 0, which is the same state. An unset
min-widthand amin-widthof 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 CSSmax-widthin pixels, used by the unitcwmax, which resolves to that value.CSS default:
max-widthdefaults tonone, 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 reading100cwmaxon a component with nomax-widthwould collapse to zero, silently, and 0 is itself a legalmax-width, so "unset" andmax-width:0could 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 amin()the unit happened to be written.The approximation is real and the caller cannot detect it. A component with no
max-widthand a component whosemax-widthgenuinely 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 forcwmaxis almost always trying to find out.- Returns:
- The computed maximum width in pixels, or the viewport width when the
max-widthisnoneor unknown.
getComponentMinHeight
default double getComponentMinHeight()Gets the component's own computed CSSmin-heightin pixels, used by the unitchmin, which resolves to that value.CSS default:
min-heightdefaults to0.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 CSSmax-heightin pixels, used by the unitchmax, which resolves to that value.CSS default:
max-heightdefaults tonone, meaning UNBOUNDED.This default returns
getViewportHeight(), for exactly the reasons set out atgetComponentMaxWidth(): 0 would assert the opposite ofnoneand collapse100chmaxto zero; a sentinel or a non-finite value would be flattened to 0 by the end-of-evaluation clamp and would disturb theMIN2/MAX2NaN asymmetry.The approximation is real and the caller cannot detect it: an unset
max-heightand 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-heightisnoneor unknown.
getNotchLeft
default double getNotchLeft()Gets the safe-area inset on the LEFT in pixels, used bynl.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 bynr. The default returns 0; seegetNotchLeft().- Returns:
- The inset in pixels.
getNotchTop
default double getNotchTop()Gets the safe-area inset on the TOP in pixels, used bynt. The default returns 0; seegetNotchLeft().- Returns:
- The inset in pixels.
getNotchBottom
default double getNotchBottom()Gets the safe-area inset on the BOTTOM in pixels, used bynb. The default returns 0; seegetNotchLeft().- Returns:
- The inset in pixels.
getNotchWidth
default double getNotchWidth()Gets the notch cutout bounding-box WIDTH in screen space, in pixels, used bynw. SeeUnitType.UT_NWfor 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 bynh. The default returns 0; seegetNotchLeft().- 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 bynx. Edge, not centre; seeUnitType.UT_NX. The default returns 0; seegetNotchLeft().- 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 byny. Edge, not centre; seeUnitType.UT_NY. The default returns 0; seegetNotchLeft().- Returns:
- The offset in pixels, or 0 if unknown or if the device is in portrait.