summaryrefslogtreecommitdiff
path: root/src/sketch/shape.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-28 21:07:13 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit590ba7b9b579b97e34b51ab7e3460ebc85713343 (patch)
tree6a73a7570ff4f79f41deff078455877b9bc6571b /src/sketch/shape.zig
parentbc8e6eb1bfef0c5e9b3c40fc1e4fd5a1659e2b03 (diff)
downloadsketchbook-590ba7b9b579b97e34b51ab7e3460ebc85713343.tar.gz
sketchbook-590ba7b9b579b97e34b51ab7e3460ebc85713343.zip
sketchbook: Zig 0.17, a Store on disk, requests, a scope (waveform, spectrum, spectrogram), audio codecs and fonts, web host
Diffstat (limited to 'src/sketch/shape.zig')
-rw-r--r--src/sketch/shape.zig25
1 files changed, 13 insertions, 12 deletions
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;
},