aligned<F extends StructFields> static method
Creates a naturally aligned struct layout from fields.
Each field is placed at the next offset satisfying its alignment requirement. The final struct size is rounded up to the largest alignment used by any field.
This matches the layout rules used by C for flat structs containing primitives and pointers.
Implementation
static StructLayout<F> aligned<F extends StructFields>(Map<F, RType> fields) {
final offsets = <F, int>{};
var offset = 0;
var maxAlign = 1;
for (final entry in fields.entries) {
final type = entry.value;
final align = type.alignment;
offset = (offset + align - 1) ~/ align * align;
offsets[entry.key] = offset;
offset += type.byteSize;
if (align > maxAlign) maxAlign = align;
}
final total = (offset + maxAlign - 1) ~/ maxAlign * maxAlign;
final floatFields = _collectFloatSlots(fields, offsets);
assert(
total <= RaylibConfig.maxStructByteSize,
'$F StructLayout byteSize ($total) exceeds MAX_STRUCT_BYTE_SIZE',
);
return StructLayout._(fields, offsets, floatFields, total, maxAlign);
}