I have a templated function for containing a bitmap for a font:
pub fn MonoBitmapFont(Buffer: []const u8) type {
return struct {
mixin: MonoBitmapFontMixin(MonoBitmapFont(Buffer)) = .{},
pub fn setPixel(_: @This(), target: anytype, x: usize, y: usize, on: bool) void {
target.plot(x, y, on);
}
I have various public constant ‘instances’ thereof:
pub const SFPRO8 : MonoBitmapFont(&sfPro8Data) = undefined;
pub const MOBILESIGNAL8x16 : MonoBitmapFont(&mobileSignal8x16Data) = undefined;
pub const MESSAGE8x16 : MonoBitmapFont(&message8x16Data) = undefined;
pub const HACK8x16 : MonoBitmapFont(&battery8x16Data) = undefined;
The code works, it prints to various LCDs and displays but I want to make the font used in printing variable. How would I go about having a code that initializes and replace a font e.g.:
// this code is conceptual
var font : *MonoBitmapFont = @constCast(&HACK8x16);
if (hourOfDay > 8) font = @constCast(&SFPRO8) ...
My heart is telling me that it should be simple, my gut is telling me that Zig sees all these as fundamentally different types (while it is one and the same thing)…