summaryrefslogtreecommitdiff
path: root/src/sketch/shape.zig
diff options
context:
space:
mode:
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;
},