From 590ba7b9b579b97e34b51ab7e3460ebc85713343 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 28 Oct 2026 21:07:13 -0300 Subject: sketchbook: Zig 0.17, a Store on disk, requests, a scope (waveform, spectrum, spectrogram), audio codecs and fonts, web host --- src/sketch/shape.zig | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/sketch/shape.zig') diff --git a/src/sketch/shape.zig b/src/sketch/shape.zig index 9bd4cee..e7575e1 100644 --- a/src/sketch/shape.zig +++ b/src/sketch/shape.zig @@ -52,7 +52,7 @@ pub const Point = struct { x: f32 = 0, y: f32 = 0 }; /// `abi.Rect`. pub fn Out(comptime T: type) type { if (@typeInfo(T) != .@"struct") return T; - for (@typeInfo(T).@"struct".fields) |field| switch (@typeInfo(field.type)) { + for (@typeInfo(T).@"struct".field_types) |F| switch (@typeInfo(F)) { .comptime_int, .comptime_float => return if (isRect(T)) abi.Rect else Point, else => {}, }; @@ -84,19 +84,20 @@ pub fn make(comptime T: type, x: f32, y: f32, w: f32, h: f32) T { .array => |a| return if (a.len == 2) .{ cast(a.child, x), cast(a.child, y) } else .{ cast(a.child, x), cast(a.child, y), cast(a.child, w), cast(a.child, h) }, .@"struct" => { var result: T = undefined; - inline for (@typeInfo(T).@"struct".fields) |field| { - @field(result, field.name) = if (comptime eql(field.name, "x")) - cast(field.type, x) - else if (comptime eql(field.name, "y")) - cast(field.type, y) - else if (comptime eql(field.name, "w") or eql(field.name, "width")) - cast(field.type, w) - else if (comptime eql(field.name, "h") or eql(field.name, "height")) - cast(field.type, h) - else if (field.defaultValue()) |default| + const s = @typeInfo(T).@"struct"; + inline for (s.field_names, s.field_types, s.field_attrs) |name, F, attrs| { + @field(result, name) = if (comptime eql(name, "x")) + cast(F, x) + else if (comptime eql(name, "y")) + cast(F, y) + else if (comptime eql(name, "w") or eql(name, "width")) + cast(F, w) + else if (comptime eql(name, "h") or eql(name, "height")) + cast(F, h) + else if (comptime attrs.defaultValue(F)) |default| default else - @compileError(@typeName(T) ++ "." ++ field.name ++ " has no default"); + @compileError(@typeName(T) ++ "." ++ name ++ " has no default"); } return result; }, -- cgit v1.3