Search Results for

    Show / Hide Table of Contents

    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
    Object
    IContentSizeCalculator4x1
    ContentSizeCalculatorBasic441
    ContentSizeCalculatorBasic470
    ContentSizeCalculatorBasic4x1
    Namespace: NinjaTools.FlexBuilder.ContentSizing
    Assembly: cs.temp.dll.dll
    Syntax
    public abstract class IContentSizeCalculator4x1 : ScriptableObject

    Methods

    - (ILayoutElement) _FindAttachedLayoutElement(FlexItem)

    As for _FindBehaviourOrNull<T>(IContentSizeCalculator4x1.BehaviourLocation, FlexItem, Boolean) except this looks for direct-attached ILayoutElement subclasses, because Unity screwed up MonoBehaviour and made it a class (it was supposed to be an interface), so ILayoutElement is type-incompatible with it

    Parameters
    FlexItem mainObject
    Returns
    ILayoutElement

    - (T) _FindBehaviourOrNull(IContentSizeCalculator4x1.BehaviourLocation, FlexItem, Boolean)

    Checks the FlexItem for an attached MonoBehaviour, or a child GameObject with MonoBehaviour, so that the algorithm can decide whether to use that for content-sizing

    _FindLayoutElementOrNull(IContentSizeCalculator4x1.BehaviourLocation, FlexItem)

    Parameters
    IContentSizeCalculator4x1.BehaviourLocation loc
    FlexItem mainObject
    Boolean showDebugMessages
    Returns
    T
    Type Parameters
    T
    Exceptions
    Exception

    - (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
    FlexItem mainObject
    Returns
    T
    Type Parameters
    T

    - (ILayoutElement) _FindChildLayoutElement(FlexItem)

    As for _FindBehaviourOrNull<T>(IContentSizeCalculator4x1.BehaviourLocation, FlexItem, Boolean) except this looks for children with ILayoutElement subclasses, because Unity screwed up MonoBehaviour and made it a class (it was supposed to be an interface), so ILayoutElement is type-incompatible with it

    Parameters
    FlexItem mainObject
    Returns
    ILayoutElement

    - (ILayoutElement) _FindLayoutElementOrNull(IContentSizeCalculator4x1.BehaviourLocation, FlexItem)

    Checks the FlexItem for an attached ILayoutElement, or a child GameObject with ILayoutElement, so that the algorithm can decide whether to use that for content-sizing - note that this is typically only checked if no instance of a known MonoBehaviour subclass was found

    _FindBehaviourOrNull<T>(IContentSizeCalculator4x1.BehaviourLocation, FlexItem, Boolean)

    Parameters
    IContentSizeCalculator4x1.BehaviourLocation loc
    FlexItem mainObject
    Returns
    ILayoutElement
    Exceptions
    Exception

    - (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
    Single
    Exceptions
    Exception

    - (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
    FlexItem element
    Single ratio
    Returns
    Boolean

    - (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
    FlexItem element
    Axis axis
    Boolean showDebugMessages
    Returns
    ContentLength

    - (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
    FlexItem item
    In This Article
    Back to top http://flexbuilder.ninja