Namespace NinjaTools.FlexBuilder.ContentSizing
Classes
ContentSizeCalculatorBasic441
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
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.
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
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.
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
Structs
ContentSizeCalculation_Text
Custom ContentSizeCalculation that lets us do extra fine-grained caching of the sizes of Unity Text objects