diff --git a/examples/web-test.zig b/examples/web-test.zig index 6f97fece..cc3f67a1 100644 --- a/examples/web-test.zig +++ b/examples/web-test.zig @@ -13,7 +13,7 @@ fn writeLog(_: void, msg: []const u8) WriteError!usize { pub fn logFn( comptime message_level: std.log.Level, - comptime scope: @Type(.EnumLiteral), + comptime scope: @Type(.enum_literal), comptime format: []const u8, args: anytype, ) void { diff --git a/src/Backend.zig b/src/Backend.zig index 5f825a70..163ba511 100644 --- a/src/Backend.zig +++ b/src/Backend.zig @@ -125,7 +125,7 @@ pub fn init( comptime var vtable: VTable = undefined; - inline for (@typeInfo(I).Struct.decls) |decl| { + inline for (@typeInfo(I).@"struct".decls) |decl| { const hasField = @hasDecl(implementation, decl.name); const DeclType = @field(I, decl.name); compile_assert(hasField, "Backend type " ++ @typeName(implementation) ++ " has no declaration '" ++ decl.name ++ ": " ++ @typeName(DeclType) ++ "'"); diff --git a/src/Examples.zig b/src/Examples.zig index 20cfe060..dcae26d8 100644 --- a/src/Examples.zig +++ b/src/Examples.zig @@ -774,7 +774,7 @@ pub fn basicWidgets(demo_win_id: u32) !void { te.deinit(); } - inline for (@typeInfo(RadioChoice).Enum.fields, 0..) |field, i| { + inline for (@typeInfo(RadioChoice).@"enum".fields, 0..) |field, i| { if (try dvui.radio(@src(), radio_choice == @as(RadioChoice, @enumFromInt(field.value)), "Radio " ++ field.name, .{ .id_extra = i })) { radio_choice = @enumFromInt(field.value); } @@ -2933,17 +2933,17 @@ pub fn dialogDirect() !void { } } -const icon_names: [@typeInfo(entypo).Struct.decls.len][]const u8 = blk: { - var blah: [@typeInfo(entypo).Struct.decls.len][]const u8 = undefined; - for (@typeInfo(entypo).Struct.decls, 0..) |d, i| { +const icon_names: [@typeInfo(entypo).@"struct".decls.len][]const u8 = blk: { + var blah: [@typeInfo(entypo).@"struct".decls.len][]const u8 = undefined; + for (@typeInfo(entypo).@"struct".decls, 0..) |d, i| { blah[i] = d.name; } break :blk blah; }; -const icon_fields: [@typeInfo(entypo).Struct.decls.len][]const u8 = blk: { - var blah: [@typeInfo(entypo).Struct.decls.len][]const u8 = undefined; - for (@typeInfo(entypo).Struct.decls, 0..) |d, i| { +const icon_fields: [@typeInfo(entypo).@"struct".decls.len][]const u8 = blk: { + var blah: [@typeInfo(entypo).@"struct".decls.len][]const u8 = undefined; + for (@typeInfo(entypo).@"struct".decls, 0..) |d, i| { blah[i] = @field(entypo, d.name); } break :blk blah; @@ -2954,7 +2954,7 @@ pub fn icon_browser() !void { defer fwin.deinit(); try dvui.windowHeader("Icon Browser", "", &IconBrowser.show); - const num_icons = @typeInfo(entypo).Struct.decls.len; + const num_icons = @typeInfo(entypo).@"struct".decls.len; const height = @as(f32, @floatFromInt(num_icons)) * IconBrowser.row_height; // we won't have the height the first frame, so always set it diff --git a/src/Font.zig b/src/Font.zig index a65cfe03..c83937e8 100644 --- a/src/Font.zig +++ b/src/Font.zig @@ -131,7 +131,7 @@ pub const TTFBytes = struct { pub fn initTTFBytesDatabase(allocator: std.mem.Allocator) !std.StringHashMap([]const u8) { var result = std.StringHashMap([]const u8).init(allocator); - inline for (@typeInfo(TTFBytes).Struct.decls) |decl| { + inline for (@typeInfo(TTFBytes).@"struct".decls) |decl| { try result.put(decl.name, @field(TTFBytes, decl.name)); } return result; diff --git a/src/Options.zig b/src/Options.zig index 4047e695..74c1b716 100644 --- a/src/Options.zig +++ b/src/Options.zig @@ -331,7 +331,7 @@ pub fn wrapInner(self: *const Options) Options { pub fn override(self: *const Options, over: Options) Options { var ret = self.*; - inline for (@typeInfo(Options).Struct.fields) |f| { + inline for (@typeInfo(Options).@"struct".fields) |f| { if (@field(over, f.name)) |fval| { @field(ret, f.name) = fval; } diff --git a/src/Widget.zig b/src/Widget.zig index bcbe69c2..fcac7fce 100644 --- a/src/Widget.zig +++ b/src/Widget.zig @@ -31,8 +31,8 @@ pub fn init( ) Widget { const Ptr = @TypeOf(pointer); const ptr_info = @typeInfo(Ptr); - std.debug.assert(ptr_info == .Pointer); // Must be a pointer - std.debug.assert(ptr_info.Pointer.size == .One); // Must be a single-item pointer + std.debug.assert(ptr_info == .pointer); // Must be a pointer + std.debug.assert(ptr_info.pointer.size == .One); // Must be a single-item pointer const gen = struct { fn dataImpl(ptr: *anyopaque) *WidgetData { diff --git a/src/backends/sdl_backend.zig b/src/backends/sdl_backend.zig index 65bfc14f..6e508c45 100644 --- a/src/backends/sdl_backend.zig +++ b/src/backends/sdl_backend.zig @@ -27,8 +27,8 @@ touch_mouse_events: bool = false, log_events: bool = false, initial_scale: f32 = 1.0, cursor_last: dvui.enums.Cursor = .arrow, -cursor_backing: [@typeInfo(dvui.enums.Cursor).Enum.fields.len]?*c.SDL_Cursor = [_]?*c.SDL_Cursor{null} ** @typeInfo(dvui.enums.Cursor).Enum.fields.len, -cursor_backing_tried: [@typeInfo(dvui.enums.Cursor).Enum.fields.len]bool = [_]bool{false} ** @typeInfo(dvui.enums.Cursor).Enum.fields.len, +cursor_backing: [@typeInfo(dvui.enums.Cursor).@"enum".fields.len]?*c.SDL_Cursor = [_]?*c.SDL_Cursor{null} ** @typeInfo(dvui.enums.Cursor).@"enum".fields.len, +cursor_backing_tried: [@typeInfo(dvui.enums.Cursor).@"enum".fields.len]bool = [_]bool{false} ** @typeInfo(dvui.enums.Cursor).@"enum".fields.len, arena: std.mem.Allocator = undefined, pub const InitOptions = struct { diff --git a/src/dvui.zig b/src/dvui.zig index f858036b..d6a62db3 100644 --- a/src/dvui.zig +++ b/src/dvui.zig @@ -1894,18 +1894,18 @@ pub fn dataSetSlice(win: ?*Window, id: u32, key: []const u8, data: anytype) void /// entries that you want to fill in after. pub fn dataSetSliceCopies(win: ?*Window, id: u32, key: []const u8, data: anytype, num_copies: usize) void { const dt = @typeInfo(@TypeOf(data)); - if (dt == .Pointer and dt.Pointer.size == .Slice) { - if (dt.Pointer.sentinel) |s| { - dataSetAdvanced(win, id, key, @as([:@as(*const dt.Pointer.child, @alignCast(@ptrCast(s))).*]dt.Pointer.child, @constCast(data)), true, num_copies); + if (dt == .pointer and dt.pointer.size == .Slice) { + if (dt.pointer.sentinel) |s| { + dataSetAdvanced(win, id, key, @as([:@as(*const dt.pointer.child, @alignCast(@ptrCast(s))).*]dt.pointer.child, @constCast(data)), true, num_copies); } else { - dataSetAdvanced(win, id, key, @as([]dt.Pointer.child, @constCast(data)), true, num_copies); + dataSetAdvanced(win, id, key, @as([]dt.pointer.child, @constCast(data)), true, num_copies); } - } else if (dt == .Pointer and dt.Pointer.size == .One and @typeInfo(dt.Pointer.child) == .Array) { - const child_type = @typeInfo(dt.Pointer.child); - if (child_type.Array.sentinel) |s| { - dataSetAdvanced(win, id, key, @as([:@as(*const child_type.Array.child, @alignCast(@ptrCast(s))).*]child_type.Array.child, @constCast(data)), true, num_copies); + } else if (dt == .pointer and dt.pointer.size == .One and @typeInfo(dt.pointer.child) == .array) { + const child_type = @typeInfo(dt.pointer.child); + if (child_type.array.sentinel) |s| { + dataSetAdvanced(win, id, key, @as([:@as(*const child_type.array.child, @alignCast(@ptrCast(s))).*]child_type.array.child, @constCast(data)), true, num_copies); } else { - dataSetAdvanced(win, id, key, @as([]child_type.Array.child, @constCast(data)), true, num_copies); + dataSetAdvanced(win, id, key, @as([]child_type.array.child, @constCast(data)), true, num_copies); } } else { @compileError("dataSetSlice needs a slice or pointer to array, given " ++ @typeName(@TypeOf(data))); @@ -2030,15 +2030,15 @@ pub fn dataGetPtr(win: ?*Window, id: u32, key: []const u8, comptime T: type) ?*T /// id/key combination. pub fn dataGetSlice(win: ?*Window, id: u32, key: []const u8, comptime T: type) ?T { const dt = @typeInfo(T); - if (dt != .Pointer or dt.Pointer.size != .Slice) { + if (dt != .pointer or dt.pointer.size != .Slice) { @compileError("dataGetSlice needs a slice, given " ++ @typeName(T)); } if (dataGetInternal(win, id, key, T, true)) |bytes| { - if (dt.Pointer.sentinel) |sentinel| { - return @as([:@as(*const dt.Pointer.child, @alignCast(@ptrCast(sentinel))).*]align(@alignOf(dt.Pointer.child)) dt.Pointer.child, @alignCast(@ptrCast(std.mem.bytesAsSlice(dt.Pointer.child, bytes[0 .. bytes.len - @sizeOf(dt.Pointer.child)])))); + if (dt.pointer.sentinel) |sentinel| { + return @as([:@as(*const dt.pointer.child, @alignCast(@ptrCast(sentinel))).*]align(@alignOf(dt.pointer.child)) dt.pointer.child, @alignCast(@ptrCast(std.mem.bytesAsSlice(dt.pointer.child, bytes[0 .. bytes.len - @sizeOf(dt.pointer.child)])))); } else { - return @as([]align(@alignOf(dt.Pointer.child)) dt.Pointer.child, @alignCast(std.mem.bytesAsSlice(dt.Pointer.child, bytes))); + return @as([]align(@alignOf(dt.pointer.child)) dt.pointer.child, @alignCast(std.mem.bytesAsSlice(dt.pointer.child, bytes))); } } else { return null; @@ -2058,7 +2058,7 @@ pub fn dataGetSlice(win: ?*Window, id: u32, key: []const u8, comptime T: type) ? /// The returned slice points to internal storage, which will be freed after /// a frame where there is no call to any dataGet/dataSet functions for that /// id/key combination. -pub fn dataGetSliceDefault(win: ?*Window, id: u32, key: []const u8, comptime T: type, default: []const @typeInfo(T).Pointer.child) T { +pub fn dataGetSliceDefault(win: ?*Window, id: u32, key: []const u8, comptime T: type, default: []const @typeInfo(T).pointer.child) T { return dataGetSlice(win, id, key, T) orelse blk: { dataSetSlice(win, id, key, default); break :blk dataGetSlice(win, id, key, T).?; @@ -3627,8 +3627,8 @@ pub const Window = struct { var bytes: []const u8 = undefined; if (copy_slice) { bytes = std.mem.sliceAsBytes(data_in); - if (dt.Pointer.sentinel != null) { - bytes.len += @sizeOf(dt.Pointer.child); + if (dt.pointer.sentinel != null) { + bytes.len += @sizeOf(dt.pointer.child); } } else { bytes = std.mem.asBytes(&data_in); @@ -3636,7 +3636,7 @@ pub const Window = struct { const alignment = comptime blk: { if (copy_slice) { - break :blk dt.Pointer.alignment; + break :blk dt.pointer.alignment; } else { break :blk @alignOf(@TypeOf(data_in)); } @@ -6046,7 +6046,7 @@ pub fn sliderEntry(src: std.builtin.SourceLocation, comptime label_fmt: ?[]const fn isF32Slice(comptime ptr: std.builtin.Type.Pointer, comptime child_info: std.builtin.Type) bool { const is_slice = ptr.size == .Slice; const holds_f32 = switch (child_info) { - .Float => |f| f.bits == 32, + .float => |f| f.bits == 32, else => false, }; @@ -6063,7 +6063,7 @@ fn isF32Slice(comptime ptr: std.builtin.Type.Pointer, comptime child_info: std.b fn checkAndCastDataPtr(comptime num_components: u32, value: anytype) *[num_components]f32 { switch (@typeInfo(@TypeOf(value))) { - .Pointer => |ptr| { + .pointer => |ptr| { const child_info = @typeInfo(ptr.child); const is_f32_slice = comptime isF32Slice(ptr, child_info); @@ -6074,8 +6074,8 @@ fn checkAndCastDataPtr(comptime num_components: u32, value: anytype) *[num_compo // If not slice, need to check for arrays and vectors. // Need to also check the length. const data_len = switch (child_info) { - .Vector => |vec| vec.len, - .Array => |arr| arr.len, + .vector => |vec| vec.len, + .array => |arr| arr.len, else => @compileError("Must supply a pointer to a vector or array!"), }; @@ -6380,11 +6380,11 @@ pub fn TextEntryNumberResult(comptime T: type) type { pub fn textEntryNumber(src: std.builtin.SourceLocation, comptime T: type, init_opts: TextEntryNumberInitOptions(T), opts: Options) !TextEntryNumberResult(T) { const base_filter = "1234567890"; const filter = switch (@typeInfo(T)) { - .Int => |int| switch (int.signedness) { + .int => |int| switch (int.signedness) { .signed => base_filter ++ "+-", .unsigned => base_filter ++ "+", }, - .Float => base_filter ++ "+-.e", + .float => base_filter ++ "+-.e", else => unreachable, }; @@ -6416,8 +6416,8 @@ pub fn textEntryNumber(src: std.builtin.SourceLocation, comptime T: type, init_o // validation const text = te.getText(); const num = switch (@typeInfo(T)) { - .Int => std.fmt.parseInt(T, text, 10) catch null, - .Float => std.fmt.parseFloat(T, text) catch null, + .int => std.fmt.parseInt(T, text, 10) catch null, + .float => std.fmt.parseFloat(T, text) catch null, else => unreachable, }; diff --git a/src/hsluv.zig b/src/hsluv.zig index 00cb0a8e..32918835 100644 --- a/src/hsluv.zig +++ b/src/hsluv.zig @@ -137,6 +137,7 @@ fn from_linear(c: f32) f32 { if (c <= 0.0031308) { return 12.92 * c; } else { + @setEvalBranchQuota(2000); return 1.055 * std.math.pow(f32, c, 1.0 / 2.4) - 0.055; } } diff --git a/src/structEntry.zig b/src/structEntry.zig index 0b38e4e4..17d5fe37 100644 --- a/src/structEntry.zig +++ b/src/structEntry.zig @@ -70,7 +70,7 @@ fn intFieldWidget( } fn normalizedPercentToInt(normalized_percent: f32, comptime T: type, min: T, max: T) T { - if (@typeInfo(T) != .Int) @compileError("T is not an int type"); + if (@typeInfo(T) != .int) @compileError("T is not an int type"); std.debug.assert(normalized_percent >= 0); std.debug.assert(normalized_percent <= 1); const range: f32 = @floatFromInt(max - min); @@ -155,7 +155,7 @@ fn enumFieldWidget( result.* = @enumFromInt(choice); }, .radio => { - inline for (@typeInfo(T).Enum.fields) |field| { + inline for (@typeInfo(T).@"enum".fields) |field| { if (try dvui.radio( @src(), result.* == @as(T, @enumFromInt(field.value)), @@ -362,7 +362,7 @@ pub fn unionFieldWidget( } } - inline for (@typeInfo(T).Union.fields, 0..) |field, i| { + inline for (@typeInfo(T).@"union".fields, 0..) |field, i| { if (choice == i) { if (std.meta.activeTag(result.*) != @as(FieldEnum, @enumFromInt(i))) { result.* = @unionInit(T, field.name, undefined); @@ -387,7 +387,7 @@ pub fn unionFieldWidget( //=======Optional Field Widget and Options======= pub fn OptionalFieldOptions(comptime T: type) type { return struct { - child: FieldOptions(@typeInfo(T).Optional.child) = .{}, + child: FieldOptions(@typeInfo(T).optional.child) = .{}, disabled: bool = false, label_override: ?[]const u8 = null, }; @@ -406,7 +406,7 @@ pub fn optionalFieldWidget( var box = try dvui.box(@src(), .vertical, .{}); defer box.deinit(); - const Child = @typeInfo(T).Optional.child; + const Child = @typeInfo(T).optional.child; const checkbox_state = dvui.dataGetPtrDefault(null, box.widget().data().id, "checked", bool, false); { @@ -433,7 +433,7 @@ pub fn optionalFieldWidget( } pub fn PointerFieldOptions(comptime T: type) type { - const info = @typeInfo(T).Pointer; + const info = @typeInfo(T).pointer; if (info.size == .Slice and info.child == u8) { return TextFieldOptions; @@ -455,7 +455,7 @@ pub fn pointerFieldWidget( allocator: ?std.mem.Allocator, alignment: *dvui.Alignment, ) !void { - const info = @typeInfo(T).Pointer; + const info = @typeInfo(T).pointer; if (info.size == .Slice and info.child == u8) { try textFieldWidget(name, T, result, opt, alloc, allocator, alignment); @@ -717,7 +717,7 @@ fn structFieldWidget( comptime alloc: bool, allocator: ?std.mem.Allocator, ) !void { - if (@typeInfo(T) != .Struct) @compileError("Input Type Must Be A Struct"); + if (@typeInfo(T) != .@"struct") @compileError("Input Type Must Be A Struct"); if (opt.disabled) return; const fields = @typeInfo(T).Struct.fields; @@ -784,15 +784,15 @@ fn structFieldWidget( //=========Generic Field Widget and Options Implementations=========== pub fn FieldOptions(comptime T: type) type { return switch (@typeInfo(T)) { - .Int => IntFieldOptions(T), - .Float => FloatFieldOptions(T), - .Enum => EnumFieldOptions, - .Bool => BoolFieldOptions, - .Struct => StructFieldOptions(T), - .Union => UnionFieldOptions(T), - .Optional => OptionalFieldOptions(T), - .Pointer => PointerFieldOptions(T), - .Array => ArrayFieldOptions(T), + .int => IntFieldOptions(T), + .float => FloatFieldOptions(T), + .@"enum" => EnumFieldOptions, + .bool => BoolFieldOptions, + .@"struct" => StructFieldOptions(T), + .@"union" => UnionFieldOptions(T), + .optional => OptionalFieldOptions(T), + .pointer => PointerFieldOptions(T), + .array => ArrayFieldOptions(T), else => @compileError("Invalid Type: " ++ @typeName(T)), }; } @@ -810,7 +810,7 @@ pub fn NamespaceFieldOptions(comptime T: type) type { .type = FieldType, }; } - return @Type(.{ .Struct = .{ + return @Type(.{ .@"struct" = .{ .decls = &.{}, .fields = &fields, .is_tuple = false, @@ -828,15 +828,15 @@ pub fn fieldWidget( alignment: *dvui.Alignment, ) !void { switch (@typeInfo(T)) { - .Int => try intFieldWidget(name, T, result, options, alignment), - .Float => try floatFieldWidget(name, T, result, options, alignment), - .Bool => try boolFieldWidget(name, result, options, alignment), - .Enum => try enumFieldWidget(name, T, result, options, alignment), - .Pointer => try pointerFieldWidget(name, T, result, options, alloc, allocator, alignment), - .Optional => try optionalFieldWidget(name, T, result, options, alloc, allocator, alignment), - .Union => try unionFieldWidget(name, T, result, options, alloc, allocator, alignment), - .Struct => try structFieldWidget(name, T, result, options, alloc, allocator), - .Array => try arrayFieldWidget(name, T, result, options, alloc, allocator), + .int => try intFieldWidget(name, T, result, options, alignment), + .float => try floatFieldWidget(name, T, result, options, alignment), + .bool => try boolFieldWidget(name, result, options, alignment), + .@"enum" => try enumFieldWidget(name, T, result, options, alignment), + .pointer => try pointerFieldWidget(name, T, result, options, alloc, allocator, alignment), + .optional => try optionalFieldWidget(name, T, result, options, alloc, allocator, alignment), + .@"union" => try unionFieldWidget(name, T, result, options, alloc, allocator, alignment), + .@"struct" => try structFieldWidget(name, T, result, options, alloc, allocator), + .array => try arrayFieldWidget(name, T, result, options, alloc, allocator), else => @compileError("Invalid type: " ++ @typeName(T)), } } diff --git a/src/tinyvg/parsing.zig b/src/tinyvg/parsing.zig index 3c35c01b..35be6deb 100644 --- a/src/tinyvg/parsing.zig +++ b/src/tinyvg/parsing.zig @@ -629,7 +629,7 @@ fn convertStyleType(value: u2) !StyleType { } fn MapZeroToMax(comptime T: type) type { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; return std.meta.Int(.unsigned, info.bits + 1); } fn mapZeroToMax(value: anytype) MapZeroToMax(@TypeOf(value)) {