Search Results for

    Show / Hide Table of Contents

    Class ContentSizeCalculatorBasic4x1

    Simple (but not optimized - see below) implementation of IContentSizeCalculator that doesn't try to be too clever, but DOES support text-flowing in the way CSS 'suggests': i.e. Text is soft-wrapped at word boundaries. It also allows custom overrides by checking for the presence of IProvidesContentSize (not supported yet) subclasses attached to the GameObject of each FlexItem

    Spec: https://www.w3.org/TR/css-sizing-3/#min-content-inline-size Spec: https://www.w3.org/TR/css-sizing-3/#max-content-inline-size

    Known issues:

    • Unity has some major bugs in the handling of variable size fonts, and rather than handle all possible variations, this currently uses the exact 'fontSize' on each Unity.UI.Text object - it makes NO ATTEMPT to pre-size-to-fit the Text (which would be my preference). "size to fit" is treated as a 'post layout cosmetic operation, fully managed by Unity' since Unity's APIs and their bugs make it very difficult to do that without a huge amount of custom code.

    Future possible optimizations:

    • for variable-size content (i.e. size-to-fit Text, and scalable-images): this re-calcs both width AND height whenever it needs either, because the first time its called per-layout (parent's main-sizing - could be x OR y first) it has to 'set' the variable-size part, and second time its called (parent's cross-sizing) it has to 're-use' the exact same variable-size part. I didn't want to have to add parameters and state and state-handling to the calling-classes to manage keeping that data for only the duration of one layout, but keeping and re-using it - so instead I just re-calc both values each time.
    Inheritance
    Object
    IContentSizeCalculator4x1
    ContentSizeCalculatorBasic4x1
    Inherited Members
    IContentSizeCalculator4x1.InlineAxisFor(FlexItem)
    IContentSizeCalculator4x1._FindBehaviourOrNull<T>(IContentSizeCalculator4x1.BehaviourLocation, FlexItem, Boolean)
    IContentSizeCalculator4x1._FindLayoutElementOrNull(IContentSizeCalculator4x1.BehaviourLocation, FlexItem)
    IContentSizeCalculator4x1._FindChildBehaviourOrNull<T>(FlexItem)
    Namespace: NinjaTools.FlexBuilder.ContentSizing
    Assembly: cs.temp.dll.dll
    Syntax
    public class ContentSizeCalculatorBasic4x1 : IContentSizeCalculator4x1

    Fields

    - (Boolean) debugTextCache

    - (Boolean) suppressUnityBugWarning

    There's a major text bug in all versions of Unity that Unity staff (as of spring 2022) have officially stated they will not fix. There's nothing we can do - their own support policy requires them to fix it, but they refuse to.

    Maybe if enough people complain then Unity staff will take it seriously?

    If you run into this warning/error a lot, you can disable the warning here - BUT your text layouts will now silently be incorrect.

    Methods

    - (ILayoutElement) _FindAttachedLayoutElement(FlexItem)

    Parameters
    FlexItem mainObject
    Returns
    ILayoutElement
    Overrides
    IContentSizeCalculator4x1._FindAttachedLayoutElement(FlexItem)

    - (ILayoutElement) _FindChildLayoutElement(FlexItem)

    Parameters
    FlexItem mainObject
    Returns
    ILayoutElement
    Overrides
    IContentSizeCalculator4x1._FindChildLayoutElement(FlexItem)

    - (Single) ContentSize(Text, FlexItem, Axis, CSSAvailableSpace, Boolean)

    Parameters
    Text text
    FlexItem item
    Axis axis
    CSSAvailableSpace containersInnerSize
    Boolean showDebugMessages
    Returns
    Single
    Overrides
    IContentSizeCalculator4x1.ContentSize(Text, FlexItem, Axis, CSSAvailableSpace, Boolean)

    - (Single) GetItemLengthInAxis(FlexItem, Axis, CSSAvailableSpace, Boolean, out Boolean, Boolean)

    There is a specific order of searching here that makes sure we don't e.g. try to process a Button as Text (because we found the Button's child Text object by accident).

    Priority order:

    • User-provided overrides
    • UI Elements that have an embedded Text
    • UI Elements that have an embedded Image
    • Raw Text
    • Raw Image
    • Everything else
    Parameters
    FlexItem element
    Axis axis
    CSSAvailableSpace containersInnerSize
    Boolean scaleToFit
    Boolean wasSizeable
    Boolean showDebugMessages
    Returns
    Single
    Overrides
    IContentSizeCalculator4x1.GetItemLengthInAxis(FlexItem, Axis, CSSAvailableSpace, Boolean, out Boolean, Boolean)

    - (Boolean) HasIntrinsicAspectRatio(FlexItem, out Single)

    There is a specific order of searching here that makes sure we don't e.g. try to process a Button as Text (because we found the Button's child Text object by accident).

    Priority order:

    • User-provided overrides
    • UI Elements that have an embedded Text
    • UI Elements that have an embedded Image
    • Raw Text
    • Raw Image
    • Everything else
    Parameters
    FlexItem element
    Single ratio
    Returns
    Boolean
    Overrides
    IContentSizeCalculator4x1.HasIntrinsicAspectRatio(FlexItem, out Single)

    - (ContentLength) MinimumIntrinsicContentSize(FlexItem, Axis, Boolean)

    There is a specific order of searching here that makes sure we don't e.g. try to process a Button as Text (because we found the Button's child Text object by accident).

    Priority order:

    • User-provided overrides
    • UI Elements that have an embedded Text
    • UI Elements that have an embedded Image
    • Raw Text
    • Raw Image
    • Everything else
    Parameters
    FlexItem element
    Axis axis
    Boolean showDebugMessages
    Returns
    ContentLength
    Overrides
    IContentSizeCalculator4x1.MinimumIntrinsicContentSize(FlexItem, Axis, Boolean)

    - (void) PurgeCachesForItem(FlexItem)

    Parameters
    FlexItem item
    Overrides
    IContentSizeCalculator4x1.PurgeCachesForItem(FlexItem)

    - (void) TestText_UsingCachedContentSize(Text, FlexItem, Axis, CSSAvailableSpace, Boolean)

    Parameters
    Text t
    FlexItem element
    Axis axis
    CSSAvailableSpace containersInnerSize
    Boolean debug

    - (void) TestText_UsingCachedFindBehaviour(FlexItem, Axis, Boolean)

    Parameters
    FlexItem element
    Axis axis
    Boolean debug
    In This Article
    Back to top http://flexbuilder.ninja