Skip to content

Commit

Permalink
fix compilation for zig 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
raddari committed Dec 24, 2024
1 parent 6bedaf8 commit 1601392
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 69 deletions.
2 changes: 1 addition & 1 deletion examples/web-test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/Backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) ++ "'");
Expand Down
16 changes: 8 additions & 8 deletions src/Examples.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Font.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Widget.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/backends/sdl_backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
50 changes: 25 additions & 25 deletions src/dvui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand All @@ -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).?;
Expand Down Expand Up @@ -3627,16 +3627,16 @@ 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);
}

const alignment = comptime blk: {
if (copy_slice) {
break :blk dt.Pointer.alignment;
break :blk dt.pointer.alignment;
} else {
break :blk @alignOf(@TypeOf(data_in));
}
Expand Down Expand Up @@ -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,
};

Expand All @@ -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);

Expand All @@ -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!"),
};

Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,
};

Expand Down
1 change: 1 addition & 0 deletions src/hsluv.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
54 changes: 27 additions & 27 deletions src/structEntry.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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);
Expand All @@ -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,
};
Expand All @@ -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);
{
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)),
};
}
Expand All @@ -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,
Expand All @@ -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)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tinyvg/parsing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 1601392

Please sign in to comment.