size property
The logical size of the component. The game assumes that this is the approximate size of the object that will be drawn on the screen. This size will therefore be used for collision detection and tap handling.
This property can be reassigned at runtime, although this is not recommended. Instead, in order to make the PositionComponent larger or smaller, change its scale.
Implementation
@override
NotifyingVector2 get size => _size;
This size setter is nullable unlike its superclass, to allow this LayoutComponent to shrink-wrap its children. In other words, it sets the size to inherentSize. This setter also records the intent to shrink-wrap via the shrinkWrapMode property, so that layoutChildren knows whether or not to invoke this setter.
Internally, this size setter should only ever be invoked upon construction, and inside layoutChildren to make it easier to track and reason about.
Externally, this size setter is designed as an API, so a library user should feel free to use this.
Implementation
@override
set size(Vector2? newSize) {
final newShrinkWrapMode = newSize == null;
if (shrinkWrapMode != newShrinkWrapMode) {
// We only invoke this when [_shrinkWrapMode]'s value is changing.
// This is so we can avoid accumulation of listeners on the children.
_setupSizeListeners(newShrinkWrapMode);
}
shrinkWrapMode = newShrinkWrapMode;
// we use [super.size] to benefit from the superclass's notifier mechanisms.
if (newSize == null) {
super.size = inherentSize;
} else {
super.size = newSize;
}
// We might be tempted to use [layoutChildren], but recall that we already
// have listeners attached to size via [setupSizeListeners].
}