replace method
Replaces the parameters of the batch item at the given index.
At least one of the parameters must be different from null.
Note: the bleed value of a batch item cannot be changed after creation.
To use a different bleed value, remove the item with removeAt and add a
new one with add.
Implementation
void replace(
int index, {
Rect? source,
Color? color,
RSTransform? transform,
}) {
assert(
source != null || color != null || transform != null,
'At least one of the parameters must be different from null.',
);
final slot = _requireSlot(index);
final currentBatchItem = _batchItems[slot];
if (source != null) {
currentBatchItem.source = source;
final bleed = currentBatchItem.bleed;
currentBatchItem.destination = bleed > 0
? Rect.fromLTWH(
-bleed,
-bleed,
source.width + bleed * 2,
source.height + bleed * 2,
)
: Offset.zero & source.size;
currentBatchItem._invalidateMatrix();
}
if (transform != null) {
currentBatchItem.transform = transform;
currentBatchItem._invalidateMatrix();
}
if (color != null) {
currentBatchItem.color = color;
currentBatchItem.paint.color = color;
}
_sources[slot] = _resolveSourceForAtlas(currentBatchItem);
// Apply bleed to the updated transform
_transforms[slot] = _computeBleedTransform(
currentBatchItem.transform,
currentBatchItem.source,
currentBatchItem.bleed,
);
// If color is not explicitly provided, store transparent.
_colors[slot] = color ?? _defaultColor;
}