I have this struct, with a nice api to receive the data associated with the command.
But the issue I have now is that instances of RenderCommand should be stored together in an array.
I am prevented since they are treated as different types, in this case it's frustrating since they are they exactly same size, containing the exact same types.
Does anyone have a suggestion how to solve my issue?
const RenderCommandTag = enum {
image,
text,
};
fn RenderCommand(comptime tag: RenderCommandTag) type {
return struct {
//
comptime tag: RenderCommandTag = tag,
bounding_box: BoundingBox,
tag_data_idx: u16,
z_index: u16,
const Data = switch (tag) {
.image => DataImage,
.text => DataText,
};
fn getData(self: *const RenderCommand, layout: *const LayoutEngine) *const Data {
return switch (self.tag) {
.image => layout.getDataImage(self.tag_data_idx),
.text => layout.getDataText(self.tag_data_idx),
};
}
};
}