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.
Inherited Members
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)
- (ILayoutElement) _FindChildLayoutElement(FlexItem)
- (Single) ContentSize(Text, FlexItem, Axis, CSSAvailableSpace, Boolean)
Parameters
Text | text | |
FlexItem | item | |
Axis | axis | |
CSSAvailableSpace | containersInnerSize | |
Boolean | showDebugMessages |
Returns
Single |
Overrides
- (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
- (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
- (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 |