Class IContentSizeCalculator4x1
Layout Algorithms from 4.0.9 onwards delegate to an instance of this class to do all content-sizing, since it's
complicated and independent of the layout algorithm (enabling you to mix-and-match content-size approaches with
different flex-algorithms)
TODO: PERFORMANCE: instead of caching each individual MonoBehaviourAttachmentCalculation ... do a single compound call
that has a large struct with null refs to all the possible attachments, precisely one of which is filled-in, and
cache that -- then the subsequent calls don't need to hit the cache M times for N items, but instead 1 time for N items
Inheritance
IContentSizeCalculator4x1
Assembly: cs.temp.dll.dll
Syntax
public abstract class IContentSizeCalculator4x1 : ScriptableObject
Methods
- (ILayoutElement)
_FindAttachedLayoutElement(FlexItem)
- (T)
_FindBehaviourOrNull(IContentSizeCalculator4x1.BehaviourLocation, FlexItem, Boolean)
Parameters
Returns
Type Parameters
Exceptions
- (T)
_FindChildBehaviourOrNull(FlexItem)
Unity prevents the disabling of Component, only allows Behaviour/MonoBehaviour, so we only allow for content-sizing
of Behaviour/MonoBehaviour subclasses (since we MUST check for / respect disabling).
Used by subclasses to find specific components, in specific order, and decide which one(s) to use for inferred
content-sizing.
Parameters
Returns
Type Parameters
- (ILayoutElement)
_FindChildLayoutElement(FlexItem)
- (ILayoutElement)
_FindLayoutElementOrNull(IContentSizeCalculator4x1.BehaviourLocation, FlexItem)
Parameters
Returns
Exceptions
- (Single)
ContentSize(Text, FlexItem, Axis, CSSAvailableSpace, Boolean)
Also .
EXPERIMENTAL: this was a private internal call, but made public in 2024 so that users can piggyback on the high-performance,
auto-cached, text-layout/sizing calculations performed internally by FlexBuilder (there is a LOT of code here
that exists to fix bugs in core Unity that Unity staff have officially refused to fix themselves, even though
the existence of this code shows they could have done so at any time in the last 8 years if they had chosen to).
This method is subject to change without notice, and may be replaced or deleted in future releases - if you are
relying on it, please contact support@ninjatools.tech to make sure we know about your use case and have support
for it.
Parameters
Text |
text |
|
FlexItem |
item |
|
Axis |
axis |
|
CSSAvailableSpace |
containersInnerSize |
|
Boolean |
showDebugMessages |
|
Returns
Exceptions
- (Single)
GetItemLengthInAxis(FlexItem, Axis, CSSAvailableSpace, Boolean, out Boolean, Boolean)
The scaleToFit is literally false when doing CONTAINER's MainAxis, true when doing CONTAINER's CrossAxis -- because
when doing the CrossAxis, each item should re-think its own content size and scale into the space given, these
are 'forced' spaces.
By contrast, when doing MainAxis, each item should be providing its own 'preferred' size, either into the large
available (but definite!) space (but only using as much as the item needs), or expanding maximally into the MAX_CONTENT
direction if one was specified by caller.
TODO: I can see how this boils-down-to the incomptently-written (and wrong!) official CSS Spec, but they could have
made it 10x easier to read and understand and implement, and they would have removed their own bugs, if they'd
just explained this properly, instead of fudging it and trying to teleport to the solution (which is: some kind
of clever 'fit-content-stretch-scale-size-respecting-aspect-ratios..except-when-not-needed', which the Spec authors got wrong).
Parameters
FlexItem |
item |
|
Axis |
axis |
|
CSSAvailableSpace |
containersInnerSize |
|
Boolean |
scaleToFit |
true when the item should be scaled into the provided space, false when the item should use its own preferred size(s) by reading the constraints
|
Boolean |
wasSizeable |
will always return true UNLESS the attempt to establish a ContentSize failed (in which case 0 will be returned)
|
Boolean |
showDebugMessages |
|
Returns
Single |
0 (and wasSizeable set to false) if unable to auto-calculate a content-size (in future: may throw an exception instead)
|
- (Boolean)
HasIntrinsicAspectRatio(FlexItem, out Single)
Any element that has an intrinsic aspect ratio will automatically have its aspect-ratio respected by Flexbox,
except where the other dimension is FORCE overridden by the user e.g. by setting explict width or height. Aspect
ratios are also used in some cases where the main length is otherwise undefined.
Parameters
Returns
- (Axis)
InlineAxisFor(FlexItem)
Typically returns "Horizontal" for any Western text, but is required to return "Vertical" for Eastern text;
for non-text components it's hard to know: it's really only defined for Text by CSS authors, and the rest they
leave 'you can guess we won't help'
Parameters
FlexItem |
element |
The item to check the inline / wirting-direction of
|
Returns
Axis |
Horizontal by default for all cases
|
- (ContentLength)
MinimumIntrinsicContentSize(FlexItem, Axis, Boolean)
When shrinking items, flexbox clamps each item to its intrinsic 'minimum possible' size. This method allows e.g.
an Image to return its pixel size preventing it shrinking below 100%, or a Text to return in X the width if it
wrapped every word or in Y the height of one line of text, etc.
Parameters
Returns
- (void)
PurgeCachesForItem(FlexItem)
If this content-size calculator does any caching internally, this method tells it to purge/invalidate any
cached data for a specific FlexItem.
After this call, any calls to get the ItemLength/Size for this FlexItem should be recalculated as if there
were no previously-cached data.
Parameters