Merge pull request #161 from mitchellh/update-zig

Update Zig
This commit is contained in:
Mitchell Hashimoto
2023-06-25 11:21:07 -07:00
committed by GitHub
71 changed files with 380 additions and 380 deletions

View File

@ -36,7 +36,7 @@ const system_sdk = @import("vendor/mach-glfw/system_sdk.zig");
// but we liberally update it. In the future, we'll be more careful about // but we liberally update it. In the future, we'll be more careful about
// using released versions so that package managers can integrate better. // using released versions so that package managers can integrate better.
comptime { comptime {
const required_zig = "0.11.0-dev.3312+ab37ab33c"; const required_zig = "0.11.0-dev.3803+7ad104227";
const current_zig = builtin.zig_version; const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable; const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable;
if (current_zig.order(min_zig) == .lt) { if (current_zig.order(min_zig) == .lt) {
@ -48,7 +48,7 @@ comptime {
} }
/// The version of the next release. /// The version of the next release.
const app_version = std.builtin.Version{ .major = 0, .minor = 1, .patch = 0 }; const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
/// Build options, see the build options help for more info. /// Build options, see the build options help for more info.
var tracy: bool = false; var tracy: bool = false;
@ -63,12 +63,12 @@ pub fn build(b: *std.Build) !void {
if (result.isLinux() and result.isGnuLibC()) { if (result.isLinux() and result.isGnuLibC()) {
// https://github.com/ziglang/zig/issues/9485 // https://github.com/ziglang/zig/issues/9485
result.glibc_version = .{ .major = 2, .minor = 28 }; result.glibc_version = .{ .major = 2, .minor = 28, .patch = 0 };
} }
if (result.isDarwin()) { if (result.isDarwin()) {
if (result.os_version_min == null) { if (result.os_version_min == null) {
result.os_version_min = .{ .semver = .{ .major = 12, .minor = 0 } }; result.os_version_min = .{ .semver = .{ .major = 12, .minor = 0, .patch = 0 } };
} }
} }

6
flake.lock generated
View File

@ -126,11 +126,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1686917286, "lastModified": 1687694884,
"narHash": "sha256-dbs4tcFlJqLyrrZrvdMsKjUe9B86N6INKvkG4uSnUfM=", "narHash": "sha256-TLXEykE/LSMwGETveZ9lI8fvd7nuJgq0+6tQwvCvP1k=",
"owner": "mitchellh", "owner": "mitchellh",
"repo": "zig-overlay", "repo": "zig-overlay",
"rev": "18cb1c5a59b38e2054a76a296f2fac659cd6eed4", "rev": "1c1c9f9ecc76ec222826770e10e6fef4c54d1e82",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -46,7 +46,7 @@ pub const Config = opaque {
return c.FcConfigSubstitute( return c.FcConfigSubstitute(
self.cval(), self.cval(),
pat.cval(), pat.cval(),
@enumToInt(kind), @intFromEnum(kind),
) == c.FcTrue; ) == c.FcTrue;
} }

View File

@ -37,7 +37,7 @@ pub const Pattern = opaque {
pub fn get(self: *Pattern, prop: Property, id: u32) Error!Value { pub fn get(self: *Pattern, prop: Property, id: u32) Error!Value {
var val: c.struct__FcValue = undefined; var val: c.struct__FcValue = undefined;
try @intToEnum(Result, c.FcPatternGet( try @enumFromInt(Result, c.FcPatternGet(
self.cval(), self.cval(),
prop.cval().ptr, prop.cval().ptr,
@intCast(c_int, id), @intCast(c_int, id),
@ -139,8 +139,8 @@ pub const Pattern = opaque {
self.id += 1; self.id += 1;
return Entry{ return Entry{
.result = @intToEnum(Result, result), .result = @enumFromInt(Result, result),
.binding = @intToEnum(ValueBinding, binding), .binding = @enumFromInt(ValueBinding, binding),
.value = Value.init(&value), .value = Value.init(&value),
}; };
} }
@ -154,7 +154,7 @@ test "create" {
defer pat.destroy(); defer pat.destroy();
try testing.expect(pat.add(.family, .{ .string = "monospace" }, false)); try testing.expect(pat.add(.family, .{ .string = "monospace" }, false));
try testing.expect(pat.add(.weight, .{ .integer = @enumToInt(Weight.bold) }, false)); try testing.expect(pat.add(.weight, .{ .integer = @intFromEnum(Weight.bold) }, false));
{ {
const val = try pat.get(.family, 0); const val = try pat.get(.family, 0);

View File

@ -34,7 +34,7 @@ pub const Value = union(Type) {
range: *const Range, range: *const Range,
pub fn init(cvalue: *c.struct__FcValue) Value { pub fn init(cvalue: *c.struct__FcValue) Value {
return switch (@intToEnum(Type, cvalue.type)) { return switch (@enumFromInt(Type, cvalue.type)) {
.unknown => .{ .unknown = {} }, .unknown => .{ .unknown = {} },
.void => .{ .void = {} }, .void => .{ .void = {} },
.string => .{ .string = std.mem.sliceTo(cvalue.u.s, 0) }, .string => .{ .string = std.mem.sliceTo(cvalue.u.s, 0) },
@ -51,7 +51,7 @@ pub const Value = union(Type) {
pub fn cval(self: Value) c.struct__FcValue { pub fn cval(self: Value) c.struct__FcValue {
return .{ return .{
.type = @enumToInt(std.meta.activeTag(self)), .type = @intFromEnum(std.meta.activeTag(self)),
.u = switch (self) { .u = switch (self) {
.unknown => undefined, .unknown => undefined,
.void => undefined, .void => undefined,

View File

@ -33,7 +33,7 @@ pub const Face = struct {
/// Select a given charmap by its encoding tag (as listed in freetype.h). /// Select a given charmap by its encoding tag (as listed in freetype.h).
pub fn selectCharmap(self: Face, encoding: Encoding) Error!void { pub fn selectCharmap(self: Face, encoding: Encoding) Error!void {
return intToError(c.FT_Select_Charmap(self.handle, @enumToInt(encoding))); return intToError(c.FT_Select_Charmap(self.handle, @intFromEnum(encoding)));
} }
/// Call FT_Request_Size to request the nominal size (in points). /// Call FT_Request_Size to request the nominal size (in points).
@ -81,7 +81,7 @@ pub const Face = struct {
const T = tag.DataType(); const T = tag.DataType();
return @ptrCast(?*T, @alignCast(@alignOf(T), c.FT_Get_Sfnt_Table( return @ptrCast(?*T, @alignCast(@alignOf(T), c.FT_Get_Sfnt_Table(
self.handle, self.handle,
@enumToInt(tag), @intFromEnum(tag),
))); )));
} }
}; };

View File

@ -55,7 +55,7 @@ pub const Blob = struct {
const handle = c.hb_blob_create_or_fail( const handle = c.hb_blob_create_or_fail(
data.ptr, data.ptr,
@intCast(c_uint, data.len), @intCast(c_uint, data.len),
@enumToInt(mode), @intFromEnum(mode),
null, null,
null, null,
) orelse return Error.HarfbuzzFailed; ) orelse return Error.HarfbuzzFailed;

View File

@ -39,13 +39,13 @@ pub const Buffer = struct {
/// Sets the type of buffer contents. Buffers are either empty, contain /// Sets the type of buffer contents. Buffers are either empty, contain
/// characters (before shaping), or contain glyphs (the result of shaping). /// characters (before shaping), or contain glyphs (the result of shaping).
pub fn setContentType(self: Buffer, ct: ContentType) void { pub fn setContentType(self: Buffer, ct: ContentType) void {
c.hb_buffer_set_content_type(self.handle, @enumToInt(ct)); c.hb_buffer_set_content_type(self.handle, @intFromEnum(ct));
} }
/// Fetches the type of buffer contents. Buffers are either empty, contain /// Fetches the type of buffer contents. Buffers are either empty, contain
/// characters (before shaping), or contain glyphs (the result of shaping). /// characters (before shaping), or contain glyphs (the result of shaping).
pub fn getContentType(self: Buffer) ContentType { pub fn getContentType(self: Buffer) ContentType {
return @intToEnum(ContentType, c.hb_buffer_get_content_type(self.handle)); return @enumFromInt(ContentType, c.hb_buffer_get_content_type(self.handle));
} }
/// Appends a character with the Unicode value of codepoint to buffer, /// Appends a character with the Unicode value of codepoint to buffer,
@ -144,12 +144,12 @@ pub const Buffer = struct {
/// direction is not the same as keeping the text in logical order and /// direction is not the same as keeping the text in logical order and
/// shaping with RTL direction. /// shaping with RTL direction.
pub fn setDirection(self: Buffer, dir: Direction) void { pub fn setDirection(self: Buffer, dir: Direction) void {
c.hb_buffer_set_direction(self.handle, @enumToInt(dir)); c.hb_buffer_set_direction(self.handle, @intFromEnum(dir));
} }
/// See hb_buffer_set_direction() /// See hb_buffer_set_direction()
pub fn getDirection(self: Buffer) Direction { pub fn getDirection(self: Buffer) Direction {
return @intToEnum(Direction, c.hb_buffer_get_direction(self.handle)); return @enumFromInt(Direction, c.hb_buffer_get_direction(self.handle));
} }
/// Sets the script of buffer to script. /// Sets the script of buffer to script.
@ -162,12 +162,12 @@ pub const Buffer = struct {
/// hb_script_from_string() or hb_script_from_iso15924_tag() to get the /// hb_script_from_string() or hb_script_from_iso15924_tag() to get the
/// corresponding script from an ISO 15924 script tag. /// corresponding script from an ISO 15924 script tag.
pub fn setScript(self: Buffer, script: Script) void { pub fn setScript(self: Buffer, script: Script) void {
c.hb_buffer_set_script(self.handle, @enumToInt(script)); c.hb_buffer_set_script(self.handle, @intFromEnum(script));
} }
/// See hb_buffer_set_script() /// See hb_buffer_set_script()
pub fn getScript(self: Buffer) Script { pub fn getScript(self: Buffer) Script {
return @intToEnum(Script, c.hb_buffer_get_script(self.handle)); return @enumFromInt(Script, c.hb_buffer_get_script(self.handle));
} }
/// Sets the language of buffer to language . /// Sets the language of buffer to language .

View File

@ -17,7 +17,7 @@ pub const FontAtlas = opaque {
_ = c.ImFontAtlas_AddFontFromMemoryTTF( _ = c.ImFontAtlas_AddFontFromMemoryTTF(
self.cval(), self.cval(),
@intToPtr(?*anyopaque, @ptrToInt(data.ptr)), @ptrFromInt(?*anyopaque, @intFromPtr(data.ptr)),
@intCast(c_int, data.len), @intCast(c_int, data.len),
size_px, size_px,
cfg, cfg,

View File

@ -18,9 +18,9 @@ pub const AttributedString = opaque {
} }
pub fn getString(self: *AttributedString) *foundation.String { pub fn getString(self: *AttributedString) *foundation.String {
return @intToPtr( return @ptrFromInt(
*foundation.String, *foundation.String,
@ptrToInt( @intFromPtr(
c.CFAttributedStringGetString(@ptrCast(c.CFAttributedStringRef, self)), c.CFAttributedStringGetString(@ptrCast(c.CFAttributedStringRef, self)),
), ),
); );
@ -29,9 +29,9 @@ pub const AttributedString = opaque {
pub const MutableAttributedString = opaque { pub const MutableAttributedString = opaque {
pub fn create(cap: usize) Allocator.Error!*MutableAttributedString { pub fn create(cap: usize) Allocator.Error!*MutableAttributedString {
return @intToPtr( return @ptrFromInt(
?*MutableAttributedString, ?*MutableAttributedString,
@ptrToInt(c.CFAttributedStringCreateMutable( @intFromPtr(c.CFAttributedStringCreateMutable(
null, null,
@intCast(c.CFIndex, cap), @intCast(c.CFIndex, cap),
)), )),

View File

@ -8,7 +8,7 @@ pub const CharacterSet = opaque {
pub fn createWithCharactersInString( pub fn createWithCharactersInString(
str: *foundation.String, str: *foundation.String,
) Allocator.Error!*CharacterSet { ) Allocator.Error!*CharacterSet {
return @intToPtr(?*CharacterSet, @ptrToInt(c.CFCharacterSetCreateWithCharactersInString( return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInString(
null, null,
@ptrCast(c.CFStringRef, str), @ptrCast(c.CFStringRef, str),
))) orelse Allocator.Error.OutOfMemory; ))) orelse Allocator.Error.OutOfMemory;
@ -17,7 +17,7 @@ pub const CharacterSet = opaque {
pub fn createWithCharactersInRange( pub fn createWithCharactersInRange(
range: foundation.Range, range: foundation.Range,
) Allocator.Error!*CharacterSet { ) Allocator.Error!*CharacterSet {
return @intToPtr(?*CharacterSet, @ptrToInt(c.CFCharacterSetCreateWithCharactersInRange( return @ptrFromInt(?*CharacterSet, @intFromPtr(c.CFCharacterSetCreateWithCharactersInRange(
null, null,
range.cval(), range.cval(),
))) orelse Allocator.Error.OutOfMemory; ))) orelse Allocator.Error.OutOfMemory;

View File

@ -5,9 +5,9 @@ const c = @import("c.zig");
pub const Data = opaque { pub const Data = opaque {
pub fn createWithBytesNoCopy(data: []const u8) Allocator.Error!*Data { pub fn createWithBytesNoCopy(data: []const u8) Allocator.Error!*Data {
return @intToPtr( return @ptrFromInt(
?*Data, ?*Data,
@ptrToInt(c.CFDataCreateWithBytesNoCopy( @intFromPtr(c.CFDataCreateWithBytesNoCopy(
null, null,
data.ptr, data.ptr,
@intCast(c_long, data.len), @intCast(c_long, data.len),

View File

@ -15,7 +15,7 @@ pub const Dictionary = opaque {
assert(keys.?.len == values.?.len); assert(keys.?.len == values.?.len);
} }
return @intToPtr(?*Dictionary, @ptrToInt(c.CFDictionaryCreate( return @ptrFromInt(?*Dictionary, @intFromPtr(c.CFDictionaryCreate(
null, null,
@ptrCast([*c]?*const anyopaque, if (keys) |slice| slice.ptr else null), @ptrCast([*c]?*const anyopaque, if (keys) |slice| slice.ptr else null),
@ptrCast([*c]?*const anyopaque, if (values) |slice| slice.ptr else null), @ptrCast([*c]?*const anyopaque, if (values) |slice| slice.ptr else null),
@ -34,7 +34,7 @@ pub const Dictionary = opaque {
} }
pub fn getValue(self: *Dictionary, comptime V: type, key: ?*const anyopaque) ?*V { pub fn getValue(self: *Dictionary, comptime V: type, key: ?*const anyopaque) ?*V {
return @intToPtr(?*V, @ptrToInt(c.CFDictionaryGetValue( return @ptrFromInt(?*V, @intFromPtr(c.CFDictionaryGetValue(
@ptrCast(c.CFDictionaryRef, self), @ptrCast(c.CFDictionaryRef, self),
key, key,
))); )));
@ -43,7 +43,7 @@ pub const Dictionary = opaque {
pub const MutableDictionary = opaque { pub const MutableDictionary = opaque {
pub fn create(cap: usize) Allocator.Error!*MutableDictionary { pub fn create(cap: usize) Allocator.Error!*MutableDictionary {
return @intToPtr(?*MutableDictionary, @ptrToInt(c.CFDictionaryCreateMutable( return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutable(
null, null,
@intCast(c.CFIndex, cap), @intCast(c.CFIndex, cap),
&c.kCFTypeDictionaryKeyCallBacks, &c.kCFTypeDictionaryKeyCallBacks,
@ -52,7 +52,7 @@ pub const MutableDictionary = opaque {
} }
pub fn createMutableCopy(cap: usize, src: *Dictionary) Allocator.Error!*MutableDictionary { pub fn createMutableCopy(cap: usize, src: *Dictionary) Allocator.Error!*MutableDictionary {
return @intToPtr(?*MutableDictionary, @ptrToInt(c.CFDictionaryCreateMutableCopy( return @ptrFromInt(?*MutableDictionary, @intFromPtr(c.CFDictionaryCreateMutableCopy(
null, null,
@intCast(c.CFIndex, cap), @intCast(c.CFIndex, cap),
@ptrCast(c.CFDictionaryRef, src), @ptrCast(c.CFDictionaryRef, src),

View File

@ -8,9 +8,9 @@ pub const Number = opaque {
comptime type_: NumberType, comptime type_: NumberType,
value: *const type_.ValueType(), value: *const type_.ValueType(),
) Allocator.Error!*Number { ) Allocator.Error!*Number {
return @intToPtr(?*Number, @ptrToInt(c.CFNumberCreate( return @ptrFromInt(?*Number, @intFromPtr(c.CFNumberCreate(
null, null,
@enumToInt(type_), @intFromEnum(type_),
value, value,
))) orelse Allocator.Error.OutOfMemory; ))) orelse Allocator.Error.OutOfMemory;
} }
@ -18,7 +18,7 @@ pub const Number = opaque {
pub fn getValue(self: *Number, comptime t: NumberType, ptr: *t.ValueType()) bool { pub fn getValue(self: *Number, comptime t: NumberType, ptr: *t.ValueType()) bool {
return c.CFNumberGetValue( return c.CFNumberGetValue(
@ptrCast(c.CFNumberRef, self), @ptrCast(c.CFNumberRef, self),
@enumToInt(t), @intFromEnum(t),
ptr, ptr,
) == 1; ) == 1;
} }

View File

@ -10,12 +10,12 @@ pub const String = opaque {
encoding: StringEncoding, encoding: StringEncoding,
external: bool, external: bool,
) Allocator.Error!*String { ) Allocator.Error!*String {
return @intToPtr(?*String, @ptrToInt(c.CFStringCreateWithBytes( return @ptrFromInt(?*String, @intFromPtr(c.CFStringCreateWithBytes(
null, null,
bs.ptr, bs.ptr,
@intCast(c_long, bs.len), @intCast(c_long, bs.len),
@enumToInt(encoding), @intFromEnum(encoding),
@boolToInt(external), @intFromBool(external),
))) orelse Allocator.Error.OutOfMemory; ))) orelse Allocator.Error.OutOfMemory;
} }
@ -39,7 +39,7 @@ pub const String = opaque {
other: *String, other: *String,
options: StringComparison, options: StringComparison,
) foundation.ComparisonResult { ) foundation.ComparisonResult {
return @intToEnum( return @enumFromInt(
foundation.ComparisonResult, foundation.ComparisonResult,
c.CFStringCompare( c.CFStringCompare(
@ptrCast(c.CFStringRef, self), @ptrCast(c.CFStringRef, self),
@ -54,7 +54,7 @@ pub const String = opaque {
@ptrCast(c.CFStringRef, self), @ptrCast(c.CFStringRef, self),
buf.ptr, buf.ptr,
@intCast(c_long, buf.len), @intCast(c_long, buf.len),
@enumToInt(encoding), @intFromEnum(encoding),
) == 0) return null; ) == 0) return null;
return std.mem.sliceTo(buf, 0); return std.mem.sliceTo(buf, 0);
} }
@ -62,7 +62,7 @@ pub const String = opaque {
pub fn cstringPtr(self: *String, encoding: StringEncoding) ?[:0]const u8 { pub fn cstringPtr(self: *String, encoding: StringEncoding) ?[:0]const u8 {
const ptr = c.CFStringGetCStringPtr( const ptr = c.CFStringGetCStringPtr(
@ptrCast(c.CFStringRef, self), @ptrCast(c.CFStringRef, self),
@enumToInt(encoding), @intFromEnum(encoding),
); );
if (ptr == null) return null; if (ptr == null) return null;
return std.mem.sliceTo(ptr, 0); return std.mem.sliceTo(ptr, 0);

View File

@ -17,12 +17,12 @@ pub const URL = opaque {
style: URLPathStyle, style: URLPathStyle,
dir: bool, dir: bool,
) Allocator.Error!*URL { ) Allocator.Error!*URL {
return @intToPtr( return @ptrFromInt(
?*URL, ?*URL,
@ptrToInt(c.CFURLCreateWithFileSystemPath( @intFromPtr(c.CFURLCreateWithFileSystemPath(
null, null,
@ptrCast(c.CFStringRef, path), @ptrCast(c.CFStringRef, path),
@enumToInt(style), @intFromEnum(style),
if (dir) 1 else 0, if (dir) 1 else 0,
)), )),
) orelse error.OutOfMemory; ) orelse error.OutOfMemory;

View File

@ -17,9 +17,9 @@ pub const BitmapContext = opaque {
space: *graphics.ColorSpace, space: *graphics.ColorSpace,
opts: c_uint, opts: c_uint,
) Allocator.Error!*BitmapContext { ) Allocator.Error!*BitmapContext {
return @intToPtr( return @ptrFromInt(
?*BitmapContext, ?*BitmapContext,
@ptrToInt(c.CGBitmapContextCreate( @intFromPtr(c.CGBitmapContextCreate(
@ptrCast(?*anyopaque, if (data) |d| d.ptr else null), @ptrCast(?*anyopaque, if (data) |d| d.ptr else null),
width, width,
height, height,

View File

@ -5,16 +5,16 @@ const c = @import("c.zig");
pub const ColorSpace = opaque { pub const ColorSpace = opaque {
pub fn createDeviceGray() Allocator.Error!*ColorSpace { pub fn createDeviceGray() Allocator.Error!*ColorSpace {
return @intToPtr( return @ptrFromInt(
?*ColorSpace, ?*ColorSpace,
@ptrToInt(c.CGColorSpaceCreateDeviceGray()), @intFromPtr(c.CGColorSpaceCreateDeviceGray()),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
} }
pub fn createDeviceRGB() Allocator.Error!*ColorSpace { pub fn createDeviceRGB() Allocator.Error!*ColorSpace {
return @intToPtr( return @ptrFromInt(
?*ColorSpace, ?*ColorSpace,
@ptrToInt(c.CGColorSpaceCreateDeviceRGB()), @intFromPtr(c.CGColorSpaceCreateDeviceRGB()),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
} }

View File

@ -69,7 +69,7 @@ pub fn Context(comptime T: type) type {
pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void { pub fn setTextDrawingMode(self: *T, mode: TextDrawingMode) void {
c.CGContextSetTextDrawingMode( c.CGContextSetTextDrawingMode(
@ptrCast(c.CGContextRef, self), @ptrCast(c.CGContextRef, self),
@enumToInt(mode), @intFromEnum(mode),
); );
} }

View File

@ -10,9 +10,9 @@ pub const Path = opaque {
rect: graphics.Rect, rect: graphics.Rect,
transform: ?*const graphics.AffineTransform, transform: ?*const graphics.AffineTransform,
) Allocator.Error!*Path { ) Allocator.Error!*Path {
return @intToPtr( return @ptrFromInt(
?*Path, ?*Path,
@ptrToInt(c.CGPathCreateWithRect( @intFromPtr(c.CGPathCreateWithRect(
rect.cval(), rect.cval(),
@ptrCast(?[*]const c.struct_CGAffineTransform, transform), @ptrCast(?[*]const c.struct_CGAffineTransform, transform),
)), )),
@ -26,9 +26,9 @@ pub const Path = opaque {
pub const MutablePath = opaque { pub const MutablePath = opaque {
pub fn create() Allocator.Error!*MutablePath { pub fn create() Allocator.Error!*MutablePath {
return @intToPtr( return @ptrFromInt(
?*MutablePath, ?*MutablePath,
@ptrToInt(c.CGPathCreateMutable()), @intFromPtr(c.CGPathCreateMutable()),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
} }

View File

@ -8,7 +8,7 @@ pub const Log = opaque {
subsystem: [:0]const u8, subsystem: [:0]const u8,
category: [:0]const u8, category: [:0]const u8,
) *Log { ) *Log {
return @intToPtr(?*Log, @ptrToInt(c.os_log_create( return @ptrFromInt(?*Log, @intFromPtr(c.os_log_create(
subsystem.ptr, subsystem.ptr,
category.ptr, category.ptr,
))).?; ))).?;
@ -21,7 +21,7 @@ pub const Log = opaque {
pub fn typeEnabled(self: *Log, typ: LogType) bool { pub fn typeEnabled(self: *Log, typ: LogType) bool {
return c.os_log_type_enabled( return c.os_log_type_enabled(
@ptrCast(c.os_log_t, self), @ptrCast(c.os_log_t, self),
@enumToInt(typ), @intFromEnum(typ),
); );
} }

View File

@ -8,9 +8,9 @@ const c = @import("c.zig");
pub const Font = opaque { pub const Font = opaque {
pub fn createWithFontDescriptor(desc: *text.FontDescriptor, size: f32) Allocator.Error!*Font { pub fn createWithFontDescriptor(desc: *text.FontDescriptor, size: f32) Allocator.Error!*Font {
return @intToPtr( return @ptrFromInt(
?*Font, ?*Font,
@ptrToInt(c.CTFontCreateWithFontDescriptor( @intFromPtr(c.CTFontCreateWithFontDescriptor(
@ptrCast(c.CTFontDescriptorRef, desc), @ptrCast(c.CTFontDescriptorRef, desc),
size, size,
null, null,
@ -19,9 +19,9 @@ pub const Font = opaque {
} }
pub fn copyWithAttributes(self: *Font, size: f32, attrs: ?*text.FontDescriptor) Allocator.Error!*Font { pub fn copyWithAttributes(self: *Font, size: f32, attrs: ?*text.FontDescriptor) Allocator.Error!*Font {
return @intToPtr( return @ptrFromInt(
?*Font, ?*Font,
@ptrToInt(c.CTFontCreateCopyWithAttributes( @intFromPtr(c.CTFontCreateCopyWithAttributes(
@ptrCast(c.CTFontRef, self), @ptrCast(c.CTFontRef, self),
size, size,
null, null,
@ -69,7 +69,7 @@ pub const Font = opaque {
if (rects) |s| assert(glyphs.len == s.len); if (rects) |s| assert(glyphs.len == s.len);
return @bitCast(graphics.Rect, c.CTFontGetBoundingRectsForGlyphs( return @bitCast(graphics.Rect, c.CTFontGetBoundingRectsForGlyphs(
@ptrCast(c.CTFontRef, self), @ptrCast(c.CTFontRef, self),
@enumToInt(orientation), @intFromEnum(orientation),
glyphs.ptr, glyphs.ptr,
@ptrCast(?[*]c.struct_CGRect, if (rects) |s| s.ptr else null), @ptrCast(?[*]c.struct_CGRect, if (rects) |s| s.ptr else null),
@intCast(c_long, glyphs.len), @intCast(c_long, glyphs.len),
@ -85,7 +85,7 @@ pub const Font = opaque {
if (advances) |s| assert(glyphs.len == s.len); if (advances) |s| assert(glyphs.len == s.len);
return c.CTFontGetAdvancesForGlyphs( return c.CTFontGetAdvancesForGlyphs(
@ptrCast(c.CTFontRef, self), @ptrCast(c.CTFontRef, self),
@enumToInt(orientation), @intFromEnum(orientation),
glyphs.ptr, glyphs.ptr,
@ptrCast(?[*]c.struct_CGSize, if (advances) |s| s.ptr else null), @ptrCast(?[*]c.struct_CGSize, if (advances) |s| s.ptr else null),
@intCast(c_long, glyphs.len), @intCast(c_long, glyphs.len),
@ -93,16 +93,16 @@ pub const Font = opaque {
} }
pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() { pub fn copyAttribute(self: *Font, comptime attr: text.FontAttribute) attr.Value() {
return @intToPtr(attr.Value(), @ptrToInt(c.CTFontCopyAttribute( return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontCopyAttribute(
@ptrCast(c.CTFontRef, self), @ptrCast(c.CTFontRef, self),
@ptrCast(c.CFStringRef, attr.key()), @ptrCast(c.CFStringRef, attr.key()),
))); )));
} }
pub fn copyDisplayName(self: *Font) *foundation.String { pub fn copyDisplayName(self: *Font) *foundation.String {
return @intToPtr( return @ptrFromInt(
*foundation.String, *foundation.String,
@ptrToInt(c.CTFontCopyDisplayName(@ptrCast(c.CTFontRef, self))), @intFromPtr(c.CTFontCopyDisplayName(@ptrCast(c.CTFontRef, self))),
); );
} }

View File

@ -6,16 +6,16 @@ const c = @import("c.zig");
pub const FontCollection = opaque { pub const FontCollection = opaque {
pub fn createFromAvailableFonts() Allocator.Error!*FontCollection { pub fn createFromAvailableFonts() Allocator.Error!*FontCollection {
return @intToPtr( return @ptrFromInt(
?*FontCollection, ?*FontCollection,
@ptrToInt(c.CTFontCollectionCreateFromAvailableFonts(null)), @intFromPtr(c.CTFontCollectionCreateFromAvailableFonts(null)),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
} }
pub fn createWithFontDescriptors(descs: *foundation.Array) Allocator.Error!*FontCollection { pub fn createWithFontDescriptors(descs: *foundation.Array) Allocator.Error!*FontCollection {
return @intToPtr( return @ptrFromInt(
?*FontCollection, ?*FontCollection,
@ptrToInt(c.CTFontCollectionCreateWithFontDescriptors( @intFromPtr(c.CTFontCollectionCreateWithFontDescriptors(
@ptrCast(c.CFArrayRef, descs), @ptrCast(c.CFArrayRef, descs),
null, null,
)), )),
@ -31,7 +31,7 @@ pub const FontCollection = opaque {
@ptrCast(c.CTFontCollectionRef, self), @ptrCast(c.CTFontCollectionRef, self),
); );
if (result) |ptr| { if (result) |ptr| {
return @intToPtr(*foundation.Array, @ptrToInt(ptr)); return @ptrFromInt(*foundation.Array, @intFromPtr(ptr));
} }
// If we have no results, we create an empty array. This is not // If we have no results, we create an empty array. This is not

View File

@ -5,16 +5,16 @@ const c = @import("c.zig");
pub const FontDescriptor = opaque { pub const FontDescriptor = opaque {
pub fn createWithNameAndSize(name: *foundation.String, size: f64) Allocator.Error!*FontDescriptor { pub fn createWithNameAndSize(name: *foundation.String, size: f64) Allocator.Error!*FontDescriptor {
return @intToPtr( return @ptrFromInt(
?*FontDescriptor, ?*FontDescriptor,
@ptrToInt(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(c.CFStringRef, name), size)), @intFromPtr(c.CTFontDescriptorCreateWithNameAndSize(@ptrCast(c.CFStringRef, name), size)),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
} }
pub fn createWithAttributes(dict: *foundation.Dictionary) Allocator.Error!*FontDescriptor { pub fn createWithAttributes(dict: *foundation.Dictionary) Allocator.Error!*FontDescriptor {
return @intToPtr( return @ptrFromInt(
?*FontDescriptor, ?*FontDescriptor,
@ptrToInt(c.CTFontDescriptorCreateWithAttributes(@ptrCast(c.CFDictionaryRef, dict))), @intFromPtr(c.CTFontDescriptorCreateWithAttributes(@ptrCast(c.CFDictionaryRef, dict))),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
} }
@ -22,9 +22,9 @@ pub const FontDescriptor = opaque {
original: *FontDescriptor, original: *FontDescriptor,
dict: *foundation.Dictionary, dict: *foundation.Dictionary,
) Allocator.Error!*FontDescriptor { ) Allocator.Error!*FontDescriptor {
return @intToPtr( return @ptrFromInt(
?*FontDescriptor, ?*FontDescriptor,
@ptrToInt(c.CTFontDescriptorCreateCopyWithAttributes( @intFromPtr(c.CTFontDescriptorCreateCopyWithAttributes(
@ptrCast(c.CTFontDescriptorRef, original), @ptrCast(c.CTFontDescriptorRef, original),
@ptrCast(c.CFDictionaryRef, dict), @ptrCast(c.CFDictionaryRef, dict),
)), )),
@ -36,14 +36,14 @@ pub const FontDescriptor = opaque {
} }
pub fn copyAttribute(self: *FontDescriptor, comptime attr: FontAttribute) attr.Value() { pub fn copyAttribute(self: *FontDescriptor, comptime attr: FontAttribute) attr.Value() {
return @intToPtr(attr.Value(), @ptrToInt(c.CTFontDescriptorCopyAttribute( return @ptrFromInt(attr.Value(), @intFromPtr(c.CTFontDescriptorCopyAttribute(
@ptrCast(c.CTFontDescriptorRef, self), @ptrCast(c.CTFontDescriptorRef, self),
@ptrCast(c.CFStringRef, attr.key()), @ptrCast(c.CFStringRef, attr.key()),
))); )));
} }
pub fn copyAttributes(self: *FontDescriptor) *foundation.Dictionary { pub fn copyAttributes(self: *FontDescriptor) *foundation.Dictionary {
return @intToPtr(*foundation.Dictionary, @ptrToInt(c.CTFontDescriptorCopyAttributes( return @ptrFromInt(*foundation.Dictionary, @intFromPtr(c.CTFontDescriptorCopyAttributes(
@ptrCast(c.CTFontDescriptorRef, self), @ptrCast(c.CTFontDescriptorRef, self),
))); )));
} }
@ -76,7 +76,7 @@ pub const FontAttribute = enum {
downloaded, downloaded,
pub fn key(self: FontAttribute) *foundation.String { pub fn key(self: FontAttribute) *foundation.String {
return @intToPtr(*foundation.String, @ptrToInt(switch (self) { return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) {
.url => c.kCTFontURLAttribute, .url => c.kCTFontURLAttribute,
.name => c.kCTFontNameAttribute, .name => c.kCTFontNameAttribute,
.display_name => c.kCTFontDisplayNameAttribute, .display_name => c.kCTFontDisplayNameAttribute,
@ -141,7 +141,7 @@ pub const FontTraitKey = enum {
slant, slant,
pub fn key(self: FontTraitKey) *foundation.String { pub fn key(self: FontTraitKey) *foundation.String {
return @intToPtr(*foundation.String, @ptrToInt(switch (self) { return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) {
.symbolic => c.kCTFontSymbolicTrait, .symbolic => c.kCTFontSymbolicTrait,
.weight => c.kCTFontWeightTrait, .weight => c.kCTFontWeightTrait,
.width => c.kCTFontWidthTrait, .width => c.kCTFontWidthTrait,

View File

@ -4,18 +4,18 @@ const foundation = @import("../foundation.zig");
const c = @import("c.zig"); const c = @import("c.zig");
pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array { pub fn createFontDescriptorsFromURL(url: *foundation.URL) ?*foundation.Array {
return @intToPtr( return @ptrFromInt(
?*foundation.Array, ?*foundation.Array,
@ptrToInt(c.CTFontManagerCreateFontDescriptorsFromURL( @intFromPtr(c.CTFontManagerCreateFontDescriptorsFromURL(
@ptrCast(c.CFURLRef, url), @ptrCast(c.CFURLRef, url),
)), )),
); );
} }
pub fn createFontDescriptorsFromData(data: *foundation.Data) ?*foundation.Array { pub fn createFontDescriptorsFromData(data: *foundation.Data) ?*foundation.Array {
return @intToPtr( return @ptrFromInt(
?*foundation.Array, ?*foundation.Array,
@ptrToInt(c.CTFontManagerCreateFontDescriptorsFromData( @intFromPtr(c.CTFontManagerCreateFontDescriptorsFromData(
@ptrCast(c.CFDataRef, data), @ptrCast(c.CFDataRef, data),
)), )),
); );

View File

@ -24,9 +24,9 @@ pub const Frame = opaque {
} }
pub fn getLines(self: *Frame) *foundation.Array { pub fn getLines(self: *Frame) *foundation.Array {
return @intToPtr( return @ptrFromInt(
*foundation.Array, *foundation.Array,
@ptrToInt(c.CTFrameGetLines(@ptrCast(c.CTFrameRef, self))), @intFromPtr(c.CTFrameGetLines(@ptrCast(c.CTFrameRef, self))),
); );
} }
}; };

View File

@ -8,9 +8,9 @@ const c = @import("c.zig");
pub const Framesetter = opaque { pub const Framesetter = opaque {
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter { pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Framesetter {
return @intToPtr( return @ptrFromInt(
?*Framesetter, ?*Framesetter,
@ptrToInt(c.CTFramesetterCreateWithAttributedString( @intFromPtr(c.CTFramesetterCreateWithAttributedString(
@ptrCast(c.CFAttributedStringRef, str), @ptrCast(c.CFAttributedStringRef, str),
)), )),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
@ -26,9 +26,9 @@ pub const Framesetter = opaque {
path: *graphics.Path, path: *graphics.Path,
attrs: ?*foundation.Dictionary, attrs: ?*foundation.Dictionary,
) !*text.Frame { ) !*text.Frame {
return @intToPtr( return @ptrFromInt(
?*text.Frame, ?*text.Frame,
@ptrToInt(c.CTFramesetterCreateFrame( @intFromPtr(c.CTFramesetterCreateFrame(
@ptrCast(c.CTFramesetterRef, self), @ptrCast(c.CTFramesetterRef, self),
@bitCast(c.CFRange, range), @bitCast(c.CFRange, range),
@ptrCast(c.CGPathRef, path), @ptrCast(c.CGPathRef, path),

View File

@ -8,9 +8,9 @@ const c = @import("c.zig");
pub const Line = opaque { pub const Line = opaque {
pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Line { pub fn createWithAttributedString(str: *foundation.AttributedString) Allocator.Error!*Line {
return @intToPtr( return @ptrFromInt(
?*Line, ?*Line,
@ptrToInt(c.CTLineCreateWithAttributedString( @intFromPtr(c.CTLineCreateWithAttributedString(
@ptrCast(c.CFAttributedStringRef, str), @ptrCast(c.CFAttributedStringRef, str),
)), )),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;

View File

@ -5,7 +5,7 @@ pub const StringAttribute = enum {
font, font,
pub fn key(self: StringAttribute) *foundation.String { pub fn key(self: StringAttribute) *foundation.String {
return @intToPtr(*foundation.String, @ptrToInt(switch (self) { return @ptrFromInt(*foundation.String, @intFromPtr(switch (self) {
.font => c.kCTFontAttributeName, .font => c.kCTFontAttributeName,
})); }));
} }

View File

@ -93,7 +93,7 @@ pub const FormatCode = enum(c_uint) {
// Converted from pixman.h // Converted from pixman.h
fn reshift(self: FormatCode, ofs: u5, num: u5) u32 { fn reshift(self: FormatCode, ofs: u5, num: u5) u32 {
const val = @enumToInt(self); const val = @intFromEnum(self);
const v1 = val >> ofs; const v1 = val >> ofs;
const v2 = @as(c_uint, 1) << num; const v2 = @as(c_uint, 1) << num;
const v3 = @intCast(u5, (val >> 22) & 3); const v3 = @intCast(u5, (val >> 22) & 3);

View File

@ -11,7 +11,7 @@ pub const Image = opaque {
stride: c_int, stride: c_int,
) pixman.Error!*Image { ) pixman.Error!*Image {
return @ptrCast(?*Image, c.pixman_image_create_bits_no_clear( return @ptrCast(?*Image, c.pixman_image_create_bits_no_clear(
@enumToInt(format), @intFromEnum(format),
width, width,
height, height,
bits, bits,
@ -66,7 +66,7 @@ pub const Image = opaque {
boxes: []const pixman.Box32, boxes: []const pixman.Box32,
) pixman.Error!void { ) pixman.Error!void {
if (c.pixman_image_fill_boxes( if (c.pixman_image_fill_boxes(
@enumToInt(op), @intFromEnum(op),
@ptrCast(*c.pixman_image_t, self), @ptrCast(*c.pixman_image_t, self),
@ptrCast(*const c.pixman_color_t, &color), @ptrCast(*const c.pixman_color_t, &color),
@intCast(c_int, boxes.len), @intCast(c_int, boxes.len),
@ -81,7 +81,7 @@ pub const Image = opaque {
rects: []const pixman.Rectangle16, rects: []const pixman.Rectangle16,
) pixman.Error!void { ) pixman.Error!void {
if (c.pixman_image_fill_rectangles( if (c.pixman_image_fill_rectangles(
@enumToInt(op), @intFromEnum(op),
@ptrCast(*c.pixman_image_t, self), @ptrCast(*c.pixman_image_t, self),
@ptrCast(*const c.pixman_color_t, &color), @ptrCast(*const c.pixman_color_t, &color),
@intCast(c_int, rects.len), @intCast(c_int, rects.len),
@ -118,7 +118,7 @@ pub const Image = opaque {
height: u16, height: u16,
) void { ) void {
c.pixman_image_composite( c.pixman_image_composite(
@enumToInt(op), @intFromEnum(op),
@ptrCast(*c.pixman_image_t, src), @ptrCast(*c.pixman_image_t, src),
@ptrCast(?*c.pixman_image_t, mask), @ptrCast(?*c.pixman_image_t, mask),
@ptrCast(*c.pixman_image_t, self), @ptrCast(*c.pixman_image_t, self),
@ -145,10 +145,10 @@ pub const Image = opaque {
tris: []const pixman.Triangle, tris: []const pixman.Triangle,
) void { ) void {
c.pixman_composite_triangles( c.pixman_composite_triangles(
@enumToInt(op), @intFromEnum(op),
@ptrCast(*c.pixman_image_t, src), @ptrCast(*c.pixman_image_t, src),
@ptrCast(*c.pixman_image_t, self), @ptrCast(*c.pixman_image_t, self),
@enumToInt(mask_format), @intFromEnum(mask_format),
x_src, x_src,
y_src, y_src,
x_dst, x_dst,

View File

@ -73,8 +73,8 @@ pub const Fixed = enum(i32) {
pub fn init(v: anytype) Fixed { pub fn init(v: anytype) Fixed {
return switch (@TypeOf(v)) { return switch (@TypeOf(v)) {
comptime_int, i32, u32 => @intToEnum(Fixed, v << 16), comptime_int, i32, u32 => @enumFromInt(Fixed, v << 16),
f64 => @intToEnum(Fixed, @floatToInt(i32, v * 65536)), f64 => @enumFromInt(Fixed, @intFromFloat(i32, v * 65536)),
else => { else => {
@compileLog(@TypeOf(v)); @compileLog(@TypeOf(v));
@compileError("unsupported type"); @compileError("unsupported type");

View File

@ -99,7 +99,7 @@ pub fn update(self: *const DevMode) !void {
const atlas = &surface.font_group.atlas_greyscale; const atlas = &surface.font_group.atlas_greyscale;
const tex = switch (Renderer) { const tex = switch (Renderer) {
renderer.OpenGL => @intCast(usize, surface.renderer.texture.id), renderer.OpenGL => @intCast(usize, surface.renderer.texture.id),
renderer.Metal => @ptrToInt(surface.renderer.texture_greyscale.value), renderer.Metal => @intFromPtr(surface.renderer.texture_greyscale.value),
else => @compileError("renderer unsupported, add it!"), else => @compileError("renderer unsupported, add it!"),
}; };
try self.atlasInfo(atlas, tex); try self.atlasInfo(atlas, tex);
@ -110,7 +110,7 @@ pub fn update(self: *const DevMode) !void {
const atlas = &surface.font_group.atlas_color; const atlas = &surface.font_group.atlas_color;
const tex = switch (Renderer) { const tex = switch (Renderer) {
renderer.OpenGL => @intCast(usize, surface.renderer.texture_color.id), renderer.OpenGL => @intCast(usize, surface.renderer.texture_color.id),
renderer.Metal => @ptrToInt(surface.renderer.texture_color.value), renderer.Metal => @intFromPtr(surface.renderer.texture_color.value),
else => @compileError("renderer unsupported, add it!"), else => @compileError("renderer unsupported, add it!"),
}; };
try self.atlasInfo(atlas, tex); try self.atlasInfo(atlas, tex);
@ -166,10 +166,10 @@ fn atlasInfo(self: *const DevMode, atlas: *font.Atlas, tex: ?usize) !void {
if (tex) |id| { if (tex) |id| {
imgui.c.igImage( imgui.c.igImage(
@intToPtr(*anyopaque, id), @ptrFromInt(*anyopaque, id),
.{ .{
.x = @intToFloat(f32, atlas.size), .x = @floatFromInt(f32, atlas.size),
.y = @intToFloat(f32, atlas.size), .y = @floatFromInt(f32, atlas.size),
}, },
.{ .x = 0, .y = 0 }, .{ .x = 0, .y = 0 },
.{ .x = 1, .y = 1 }, .{ .x = 1, .y = 1 },

View File

@ -87,7 +87,7 @@ pub fn deinit(self: *Pty) void {
/// Return the size of the pty. /// Return the size of the pty.
pub fn getSize(self: Pty) !winsize { pub fn getSize(self: Pty) !winsize {
var ws: winsize = undefined; var ws: winsize = undefined;
if (c.ioctl(self.master, TIOCGWINSZ, @ptrToInt(&ws)) < 0) if (c.ioctl(self.master, TIOCGWINSZ, @intFromPtr(&ws)) < 0)
return error.IoctlFailed; return error.IoctlFailed;
return ws; return ws;
@ -95,7 +95,7 @@ pub fn getSize(self: Pty) !winsize {
/// Set the size of the pty. /// Set the size of the pty.
pub fn setSize(self: Pty, size: winsize) !void { pub fn setSize(self: Pty, size: winsize) !void {
if (c.ioctl(self.master, TIOCSWINSZ, @ptrToInt(&size)) < 0) if (c.ioctl(self.master, TIOCSWINSZ, @intFromPtr(&size)) < 0)
return error.IoctlFailed; return error.IoctlFailed;
} }

View File

@ -196,8 +196,8 @@ pub fn init(
// The font size we desire along with the DPI determined for the surface // The font size we desire along with the DPI determined for the surface
const font_size: font.face.DesiredSize = .{ const font_size: font.face.DesiredSize = .{
.points = config.@"font-size", .points = config.@"font-size",
.xdpi = @floatToInt(u16, x_dpi), .xdpi = @intFromFloat(u16, x_dpi),
.ydpi = @floatToInt(u16, y_dpi), .ydpi = @intFromFloat(u16, y_dpi),
}; };
// Find all the fonts for this surface // Find all the fonts for this surface
@ -320,8 +320,8 @@ pub fn init(
const cell_size = try renderer.CellSize.init(alloc, font_group); const cell_size = try renderer.CellSize.init(alloc, font_group);
// Convert our padding from points to pixels // Convert our padding from points to pixels
const padding_x = (@intToFloat(f32, config.@"window-padding-x") * x_dpi) / 72; const padding_x = (@floatFromInt(f32, config.@"window-padding-x") * x_dpi) / 72;
const padding_y = (@intToFloat(f32, config.@"window-padding-y") * y_dpi) / 72; const padding_y = (@floatFromInt(f32, config.@"window-padding-y") * y_dpi) / 72;
const padding: renderer.Padding = .{ const padding: renderer.Padding = .{
.top = padding_y, .top = padding_y,
.bottom = padding_y, .bottom = padding_y,
@ -425,8 +425,8 @@ pub fn init(
// Set a minimum size that is cols=10 h=4. This matches Mac's Terminal.app // Set a minimum size that is cols=10 h=4. This matches Mac's Terminal.app
// but is otherwise somewhat arbitrary. // but is otherwise somewhat arbitrary.
try rt_surface.setSizeLimits(.{ try rt_surface.setSizeLimits(.{
.width = @floatToInt(u32, cell_size.width * 10), .width = @intFromFloat(u32, cell_size.width * 10),
.height = @floatToInt(u32, cell_size.height * 4), .height = @intFromFloat(u32, cell_size.height * 4),
}, null); }, null);
// Call our size callback which handles all our retina setup // Call our size callback which handles all our retina setup
@ -446,7 +446,7 @@ pub fn init(
const dev_atlas = @ptrCast(*imgui.FontAtlas, dev_io.cval().Fonts); const dev_atlas = @ptrCast(*imgui.FontAtlas, dev_io.cval().Fonts);
dev_atlas.addFontFromMemoryTTF( dev_atlas.addFontFromMemoryTTF(
face_ttf, face_ttf,
@intToFloat(f32, font_size.pixels()), @floatFromInt(f32, font_size.pixels()),
); );
// Default dark style // Default dark style
@ -524,7 +524,7 @@ pub fn deinit(self: *Surface) void {
self.alloc.destroy(self.renderer_state.mutex); self.alloc.destroy(self.renderer_state.mutex);
self.config.deinit(); self.config.deinit();
log.info("surface closed addr={x}", .{@ptrToInt(self)}); log.info("surface closed addr={x}", .{@intFromPtr(self)});
} }
/// Close this surface. This will trigger the runtime to start the /// Close this surface. This will trigger the runtime to start the
@ -658,7 +658,7 @@ pub fn imePoint(self: *const Surface) apprt.IMEPos {
const x: f64 = x: { const x: f64 = x: {
// Simple x * cell width gives the top-left corner // Simple x * cell width gives the top-left corner
var x: f64 = @floatCast(f64, @intToFloat(f32, cursor.x) * self.cell_size.width); var x: f64 = @floatCast(f64, @floatFromInt(f32, cursor.x) * self.cell_size.width);
// We want the midpoint // We want the midpoint
x += self.cell_size.width / 2; x += self.cell_size.width / 2;
@ -671,7 +671,7 @@ pub fn imePoint(self: *const Surface) apprt.IMEPos {
const y: f64 = y: { const y: f64 = y: {
// Simple x * cell width gives the top-left corner // Simple x * cell width gives the top-left corner
var y: f64 = @floatCast(f64, @intToFloat(f32, cursor.y) * self.cell_size.height); var y: f64 = @floatCast(f64, @floatFromInt(f32, cursor.y) * self.cell_size.height);
// We want the bottom // We want the bottom
y += self.cell_size.height; y += self.cell_size.height;
@ -1572,7 +1572,7 @@ pub fn mouseButtonCallback(
} }
// Always record our latest mouse state // Always record our latest mouse state
self.mouse.click_state[@intCast(usize, @enumToInt(button))] = action; self.mouse.click_state[@intCast(usize, @intFromEnum(button))] = action;
self.mouse.mods = @bitCast(input.Mods, mods); self.mouse.mods = @bitCast(input.Mods, mods);
// Shift-click continues the previous mouse state. cursorPosCallback // Shift-click continues the previous mouse state. cursorPosCallback
@ -1713,7 +1713,7 @@ pub fn cursorPosCallback(
// since the spec (afaict) does not say... // since the spec (afaict) does not say...
const button: ?input.MouseButton = button: for (self.mouse.click_state, 0..) |state, i| { const button: ?input.MouseButton = button: for (self.mouse.click_state, 0..) |state, i| {
if (state == .press) if (state == .press)
break :button @intToEnum(input.MouseButton, i); break :button @enumFromInt(input.MouseButton, i);
} else null; } else null;
try self.mouseReport(button, .motion, self.mouse.mods, pos); try self.mouseReport(button, .motion, self.mouse.mods, pos);
@ -1724,7 +1724,7 @@ pub fn cursorPosCallback(
} }
// If the cursor isn't clicked currently, it doesn't matter // If the cursor isn't clicked currently, it doesn't matter
if (self.mouse.click_state[@enumToInt(input.MouseButton.left)] != .press) return; if (self.mouse.click_state[@intFromEnum(input.MouseButton.left)] != .press) return;
// All roads lead to requiring a re-render at this pont. // All roads lead to requiring a re-render at this pont.
try self.queueRender(); try self.queueRender();
@ -1733,7 +1733,7 @@ pub fn cursorPosCallback(
// up. The amount we scroll up is dependent on how negative we are. // up. The amount we scroll up is dependent on how negative we are.
// Note: one day, we can change this from distance to time based if we want. // Note: one day, we can change this from distance to time based if we want.
//log.warn("CURSOR POS: {} {}", .{ pos, self.screen_size }); //log.warn("CURSOR POS: {} {}", .{ pos, self.screen_size });
const max_y = @intToFloat(f32, self.screen_size.height); const max_y = @floatFromInt(f32, self.screen_size.height);
if (pos.y < 0 or pos.y > max_y) { if (pos.y < 0 or pos.y > max_y) {
const delta: isize = if (pos.y < 0) -1 else 1; const delta: isize = if (pos.y < 0) -1 else 1;
try self.io.terminal.scrollViewport(.{ .delta = delta }); try self.io.terminal.scrollViewport(.{ .delta = delta });
@ -1845,7 +1845,7 @@ fn dragLeftClickSingle(
const cell_xboundary = self.cell_size.width * 0.6; const cell_xboundary = self.cell_size.width * 0.6;
// first xpos of the clicked cell // first xpos of the clicked cell
const cell_xstart = @intToFloat(f32, self.mouse.left_click_point.x) * self.cell_size.width; const cell_xstart = @floatFromInt(f32, self.mouse.left_click_point.x) * self.cell_size.width;
const cell_start_xpos = self.mouse.left_click_xpos - cell_xstart; const cell_start_xpos = self.mouse.left_click_xpos - cell_xstart;
// If this is the same cell, then we only start the selection if weve // If this is the same cell, then we only start the selection if weve
@ -1921,7 +1921,7 @@ fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
.x = if (xpos < 0) 0 else x: { .x = if (xpos < 0) 0 else x: {
// Our cell is the mouse divided by cell width // Our cell is the mouse divided by cell width
const cell_width = @floatCast(f64, self.cell_size.width); const cell_width = @floatCast(f64, self.cell_size.width);
const x = @floatToInt(usize, xpos / cell_width); const x = @intFromFloat(usize, xpos / cell_width);
// Can be off the screen if the user drags it out, so max // Can be off the screen if the user drags it out, so max
// it out on our available columns // it out on our available columns
@ -1930,7 +1930,7 @@ fn posToViewport(self: Surface, xpos: f64, ypos: f64) terminal.point.Viewport {
.y = if (ypos < 0) 0 else y: { .y = if (ypos < 0) 0 else y: {
const cell_height = @floatCast(f64, self.cell_size.height); const cell_height = @floatCast(f64, self.cell_size.height);
const y = @floatToInt(usize, ypos / cell_height); const y = @intFromFloat(usize, ypos / cell_height);
break :y @min(y, self.grid_size.rows - 1); break :y @min(y, self.grid_size.rows - 1);
}, },
}; };

View File

@ -291,8 +291,8 @@ pub const Surface = struct {
}; };
const physical_size = monitor.getPhysicalSize(); const physical_size = monitor.getPhysicalSize();
const video_mode = monitor.getVideoMode() orelse return glfw.mustGetErrorCode(); const video_mode = monitor.getVideoMode() orelse return glfw.mustGetErrorCode();
const physical_x_dpi = @intToFloat(f32, video_mode.getWidth()) / (@intToFloat(f32, physical_size.width_mm) / 25.4); const physical_x_dpi = @floatFromInt(f32, video_mode.getWidth()) / (@floatFromInt(f32, physical_size.width_mm) / 25.4);
const physical_y_dpi = @intToFloat(f32, video_mode.getHeight()) / (@intToFloat(f32, physical_size.height_mm) / 25.4); const physical_y_dpi = @floatFromInt(f32, video_mode.getHeight()) / (@floatFromInt(f32, physical_size.height_mm) / 25.4);
log.debug("physical dpi x={} y={}", .{ log.debug("physical dpi x={} y={}", .{
physical_x_dpi, physical_x_dpi,
physical_y_dpi, physical_y_dpi,
@ -512,8 +512,8 @@ pub const Surface = struct {
if (fb_size.width == size.width and fb_size.height == size.height) if (fb_size.width == size.width and fb_size.height == size.height)
return pos; return pos;
const x_scale = @intToFloat(f64, fb_size.width) / @intToFloat(f64, size.width); const x_scale = @floatFromInt(f64, fb_size.width) / @floatFromInt(f64, size.width);
const y_scale = @intToFloat(f64, fb_size.height) / @intToFloat(f64, size.height); const y_scale = @floatFromInt(f64, fb_size.height) / @floatFromInt(f64, size.height);
return .{ return .{
.xpos = pos.xpos * x_scale, .xpos = pos.xpos * x_scale,
.ypos = pos.ypos * y_scale, .ypos = pos.ypos * y_scale,

View File

@ -418,8 +418,8 @@ pub const Config = struct {
} }
{ {
// Cmd+N for goto tab N // Cmd+N for goto tab N
const start = @enumToInt(inputpkg.Key.one); const start = @intFromEnum(inputpkg.Key.one);
const end = @enumToInt(inputpkg.Key.nine); const end = @intFromEnum(inputpkg.Key.nine);
var i: usize = start; var i: usize = start;
while (i <= end) : (i += 1) { while (i <= end) : (i += 1) {
// On macOS we default to super but everywhere else // On macOS we default to super but everywhere else
@ -431,7 +431,7 @@ pub const Config = struct {
try result.keybind.set.put( try result.keybind.set.put(
alloc, alloc,
.{ .key = @intToEnum(inputpkg.Key, i), .mods = mods }, .{ .key = @enumFromInt(inputpkg.Key, i), .mods = mods },
.{ .goto_tab = (i - start) + 1 }, .{ .goto_tab = (i - start) + 1 },
); );
} }

View File

@ -317,7 +317,7 @@ pub const Wasm = struct {
const atlas = init( const atlas = init(
alloc, alloc,
size, size,
@intToEnum(Format, format), @enumFromInt(Format, format),
) catch return null; ) catch return null;
const result = alloc.create(Atlas) catch return null; const result = alloc.create(Atlas) catch return null;
result.* = atlas; result.* = atlas;
@ -449,12 +449,12 @@ pub const Wasm = struct {
// Draw it // Draw it
try ctx.call(void, "putImageData", .{ image_data, 0, 0 }); try ctx.call(void, "putImageData", .{ image_data, 0, 0 });
const id = @bitCast(js.Ref, @enumToInt(canvas.value)).id; const id = @bitCast(js.Ref, @intFromEnum(canvas.value)).id;
return id; return id;
} }
test "happy path" { test "happy path" {
var atlas = atlas_new(512, @enumToInt(Format.greyscale)).?; var atlas = atlas_new(512, @intFromEnum(Format.greyscale)).?;
defer atlas_free(atlas); defer atlas_free(atlas);
const reg = atlas_reserve(atlas, 2, 2).?; const reg = atlas_reserve(atlas, 2, 2).?;

View File

@ -353,7 +353,7 @@ pub const Wasm = struct {
.wc = .{ .wc = .{
.alloc = alloc, .alloc = alloc,
.font_str = font_str, .font_str = font_str,
.presentation = @intToEnum(font.Presentation, presentation), .presentation = @enumFromInt(font.Presentation, presentation),
}, },
}; };
errdefer face.deinit(); errdefer face.deinit();

View File

@ -138,7 +138,7 @@ pub const FontIndex = packed struct(u8) {
/// Initialize a special font index. /// Initialize a special font index.
pub fn initSpecial(v: Special) FontIndex { pub fn initSpecial(v: Special) FontIndex {
return .{ .style = .regular, .idx = @enumToInt(v) }; return .{ .style = .regular, .idx = @intFromEnum(v) };
} }
/// Convert to int /// Convert to int
@ -151,7 +151,7 @@ pub const FontIndex = packed struct(u8) {
/// this font. /// this font.
pub fn special(self: FontIndex) ?Special { pub fn special(self: FontIndex) ?Special {
if (self.idx < Special.start) return null; if (self.idx < Special.start) return null;
return @intToEnum(Special, self.idx); return @enumFromInt(Special, self.idx);
} }
test { test {
@ -327,15 +327,15 @@ pub const Wasm = struct {
// Set details for our sprite font // Set details for our sprite font
self.sprite = font.sprite.Face{ self.sprite = font.sprite.Face{
.width = @floatToInt(u32, metrics.cell_width), .width = @intFromFloat(u32, metrics.cell_width),
.height = @floatToInt(u32, metrics.cell_height), .height = @intFromFloat(u32, metrics.cell_height),
.thickness = 2, .thickness = 2,
.underline_position = @floatToInt(u32, metrics.underline_position), .underline_position = @intFromFloat(u32, metrics.underline_position),
}; };
} }
export fn group_add_face(self: *Group, style: u16, face: *font.DeferredFace) void { export fn group_add_face(self: *Group, style: u16, face: *font.DeferredFace) void {
return self.addFace(alloc, @intToEnum(Style, style), face.*) catch |err| { return self.addFace(alloc, @enumFromInt(Style, style), face.*) catch |err| {
log.warn("error adding face to group err={}", .{err}); log.warn("error adding face to group err={}", .{err});
return; return;
}; };
@ -350,10 +350,10 @@ pub const Wasm = struct {
/// Presentation is negative for doesn't matter. /// Presentation is negative for doesn't matter.
export fn group_index_for_codepoint(self: *Group, cp: u32, style: u16, p: i16) i16 { export fn group_index_for_codepoint(self: *Group, cp: u32, style: u16, p: i16) i16 {
const presentation = if (p < 0) null else @intToEnum(Presentation, p); const presentation = if (p < 0) null else @enumFromInt(Presentation, p);
const idx = self.indexForCodepoint( const idx = self.indexForCodepoint(
cp, cp,
@intToEnum(Style, style), @enumFromInt(Style, style),
presentation, presentation,
) orelse return -1; ) orelse return -1;
return @intCast(i16, @bitCast(u8, idx)); return @intCast(i16, @bitCast(u8, idx));
@ -473,7 +473,7 @@ test "box glyph" {
// Should find a box glyph // Should find a box glyph
const idx = group.indexForCodepoint(0x2500, .regular, null).?; const idx = group.indexForCodepoint(0x2500, .regular, null).?;
try testing.expectEqual(Style.regular, idx.style); try testing.expectEqual(Style.regular, idx.style);
try testing.expectEqual(@enumToInt(FontIndex.Special.sprite), idx.idx); try testing.expectEqual(@intFromEnum(FontIndex.Special.sprite), idx.idx);
// Should render it // Should render it
const glyph = try group.renderGlyph( const glyph = try group.renderGlyph(
@ -597,6 +597,6 @@ test "faceFromIndex returns pointer" {
const idx = group.indexForCodepoint('A', .regular, null).?; const idx = group.indexForCodepoint('A', .regular, null).?;
const face1 = try group.faceFromIndex(idx); const face1 = try group.faceFromIndex(idx);
const face2 = try group.faceFromIndex(idx); const face2 = try group.faceFromIndex(idx);
try testing.expectEqual(@ptrToInt(face1), @ptrToInt(face2)); try testing.expectEqual(@intFromPtr(face1), @intFromPtr(face2));
} }
} }

View File

@ -266,11 +266,11 @@ pub const Wasm = struct {
/// Presentation is negative for doesn't matter. /// Presentation is negative for doesn't matter.
export fn group_cache_index_for_codepoint(self: *GroupCache, cp: u32, style: u16, p: i16) i16 { export fn group_cache_index_for_codepoint(self: *GroupCache, cp: u32, style: u16, p: i16) i16 {
const presentation = if (p < 0) null else @intToEnum(Presentation, p); const presentation = if (p < 0) null else @enumFromInt(Presentation, p);
if (self.indexForCodepoint( if (self.indexForCodepoint(
alloc, alloc,
cp, cp,
@intToEnum(Style, style), @enumFromInt(Style, style),
presentation, presentation,
)) |idx| { )) |idx| {
return @intCast(i16, @bitCast(u8, idx orelse return -1)); return @intCast(i16, @bitCast(u8, idx orelse return -1));

View File

@ -64,12 +64,12 @@ pub const Descriptor = struct {
)); ));
if (self.bold) assert(pat.add( if (self.bold) assert(pat.add(
.weight, .weight,
.{ .integer = @enumToInt(fontconfig.Weight.bold) }, .{ .integer = @intFromEnum(fontconfig.Weight.bold) },
false, false,
)); ));
if (self.italic) assert(pat.add( if (self.italic) assert(pat.add(
.slant, .slant,
.{ .integer = @enumToInt(fontconfig.Slant.italic) }, .{ .integer = @intFromEnum(fontconfig.Slant.italic) },
false, false,
)); ));

View File

@ -42,7 +42,7 @@ pub const Face = struct {
/// adjusted to the final size for final load. /// adjusted to the final size for final load.
pub fn initFontCopy(base: *macos.text.Font, size: font.face.DesiredSize) !Face { pub fn initFontCopy(base: *macos.text.Font, size: font.face.DesiredSize) !Face {
// Create a copy // Create a copy
const ct_font = try base.copyWithAttributes(@intToFloat(f32, size.points), null); const ct_font = try base.copyWithAttributes(@floatFromInt(f32, size.points), null);
errdefer ct_font.release(); errdefer ct_font.release();
var hb_font = try harfbuzz.coretext.createFont(ct_font); var hb_font = try harfbuzz.coretext.createFont(ct_font);
@ -115,8 +115,8 @@ pub const Face = struct {
// of the bitmap. We use the rounded up width/height of the bounding rect. // of the bitmap. We use the rounded up width/height of the bounding rect.
var bounding: [1]macos.graphics.Rect = undefined; var bounding: [1]macos.graphics.Rect = undefined;
_ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding); _ = self.font.getBoundingRectForGlyphs(.horizontal, &glyphs, &bounding);
const glyph_width = @floatToInt(u32, @ceil(bounding[0].size.width)); const glyph_width = @intFromFloat(u32, @ceil(bounding[0].size.width));
const glyph_height = @floatToInt(u32, @ceil(bounding[0].size.height)); const glyph_height = @intFromFloat(u32, @ceil(bounding[0].size.height));
// Width and height. Note the padding doubling is because we want // Width and height. Note the padding doubling is because we want
// the padding on both sides (top/bottom, left/right). // the padding on both sides (top/bottom, left/right).
@ -156,8 +156,8 @@ pub const Face = struct {
8, 8,
width, width,
space, space,
@enumToInt(macos.graphics.BitmapInfo.alpha_mask) & @intFromEnum(macos.graphics.BitmapInfo.alpha_mask) &
@enumToInt(macos.graphics.ImageAlphaInfo.none), @intFromEnum(macos.graphics.ImageAlphaInfo.none),
); );
defer ctx.release(); defer ctx.release();
@ -195,13 +195,13 @@ pub const Face = struct {
// by default below the line. We have to add height (glyph height) // by default below the line. We have to add height (glyph height)
// so that we shift the glyph UP to be on the line, then we add our // so that we shift the glyph UP to be on the line, then we add our
// baseline offset to move the glyph further UP to match the baseline. // baseline offset to move the glyph further UP to match the baseline.
break :offset_y @intCast(i32, height) + @floatToInt(i32, @ceil(baseline_with_offset)); break :offset_y @intCast(i32, height) + @intFromFloat(i32, @ceil(baseline_with_offset));
}; };
return font.Glyph{ return font.Glyph{
.width = glyph_width, .width = glyph_width,
.height = glyph_height, .height = glyph_height,
.offset_x = @floatToInt(i32, @ceil(bounding[0].origin.x)), .offset_x = @intFromFloat(i32, @ceil(bounding[0].origin.x)),
.offset_y = offset_y, .offset_y = offset_y,
.atlas_x = region.x + padding, .atlas_x = region.x + padding,
.atlas_y = region.y + padding, .atlas_y = region.y + padding,

View File

@ -242,14 +242,14 @@ pub const Face = struct {
const glyph_metrics = if (bitmap_resized) |bm| metrics: { const glyph_metrics = if (bitmap_resized) |bm| metrics: {
// Our ratio for the resize // Our ratio for the resize
const ratio = ratio: { const ratio = ratio: {
const new = @intToFloat(f64, bm.rows); const new = @floatFromInt(f64, bm.rows);
const old = @intToFloat(f64, bitmap_original.rows); const old = @floatFromInt(f64, bitmap_original.rows);
break :ratio new / old; break :ratio new / old;
}; };
var copy = glyph.*; var copy = glyph.*;
copy.bitmap_top = @floatToInt(c_int, @round(@intToFloat(f64, copy.bitmap_top) * ratio)); copy.bitmap_top = @intFromFloat(c_int, @round(@floatFromInt(f64, copy.bitmap_top) * ratio));
copy.bitmap_left = @floatToInt(c_int, @round(@intToFloat(f64, copy.bitmap_left) * ratio)); copy.bitmap_left = @intFromFloat(c_int, @round(@floatFromInt(f64, copy.bitmap_left) * ratio));
break :metrics copy; break :metrics copy;
} else glyph.*; } else glyph.*;
@ -325,7 +325,7 @@ pub const Face = struct {
// baseline calculation. The baseline calculation is so that everything // baseline calculation. The baseline calculation is so that everything
// is properly centered when we render it out into a monospace grid. // is properly centered when we render it out into a monospace grid.
// Note: we add here because our X/Y is actually reversed, adding goes UP. // Note: we add here because our X/Y is actually reversed, adding goes UP.
break :offset_y glyph_metrics.bitmap_top + @floatToInt(c_int, self.metrics.cell_baseline); break :offset_y glyph_metrics.bitmap_top + @intFromFloat(c_int, self.metrics.cell_baseline);
}; };
// Store glyph metadata // Store glyph metadata
@ -351,7 +351,7 @@ pub const Face = struct {
/// Convert 26.6 pixel format to f32 /// Convert 26.6 pixel format to f32
fn f26dot6ToFloat(v: freetype.c.FT_F26Dot6) f32 { fn f26dot6ToFloat(v: freetype.c.FT_F26Dot6) f32 {
return @intToFloat(f32, v >> 6); return @floatFromInt(f32, v >> 6);
} }
/// Calculate the metrics associated with a face. This is not public because /// Calculate the metrics associated with a face. This is not public because
@ -398,8 +398,8 @@ pub const Face = struct {
if (face.getCharIndex('_')) |glyph_index| { if (face.getCharIndex('_')) |glyph_index| {
if (face.loadGlyph(glyph_index, .{ .render = true })) { if (face.loadGlyph(glyph_index, .{ .render = true })) {
var res: f32 = f26dot6ToFloat(size_metrics.ascender); var res: f32 = f26dot6ToFloat(size_metrics.ascender);
res -= @intToFloat(f32, face.handle.*.glyph.*.bitmap_top); res -= @floatFromInt(f32, face.handle.*.glyph.*.bitmap_top);
res += @intToFloat(f32, face.handle.*.glyph.*.bitmap.rows); res += @floatFromInt(f32, face.handle.*.glyph.*.bitmap.rows);
break :underscore res; break :underscore res;
} else |_| { } else |_| {
// Ignore the error since we just fall back below // Ignore the error since we just fall back below
@ -434,7 +434,7 @@ pub const Face = struct {
// We use the declared underline position if its available // We use the declared underline position if its available
const declared = ascender_px - declared_px; const declared = ascender_px - declared_px;
if (declared > 0) if (declared > 0)
break :underline_pos @intToFloat(f32, declared); break :underline_pos @floatFromInt(f32, declared);
// If we have no declared underline position, we go slightly under the // If we have no declared underline position, we go slightly under the
// cell height (mainly: non-scalable fonts, i.e. emoji) // cell height (mainly: non-scalable fonts, i.e. emoji)
@ -459,7 +459,7 @@ pub const Face = struct {
@intCast(i32, face.handle.*.size.*.metrics.y_scale), @intCast(i32, face.handle.*.size.*.metrics.y_scale),
) >> 6; ) >> 6;
break :pos @intToFloat(f32, ascender_px - declared_px); break :pos @floatFromInt(f32, ascender_px - declared_px);
}, },
.thickness = @max(@as(f32, 1), fontUnitsToPxY(face, os2.yStrikeoutSize)), .thickness = @max(@as(f32, 1), fontUnitsToPxY(face, os2.yStrikeoutSize)),
} else .{ } else .{
@ -491,7 +491,7 @@ pub const Face = struct {
/// Convert freetype "font units" to pixels using the Y scale. /// Convert freetype "font units" to pixels using the Y scale.
fn fontUnitsToPxY(face: freetype.Face, x: i32) f32 { fn fontUnitsToPxY(face: freetype.Face, x: i32) f32 {
const mul = freetype.mulFix(x, @intCast(i32, face.handle.*.size.*.metrics.y_scale)); const mul = freetype.mulFix(x, @intCast(i32, face.handle.*.size.*.metrics.y_scale));
const div = @intToFloat(f32, mul) / 64; const div = @floatFromInt(f32, mul) / 64;
return @ceil(div); return @ceil(div);
} }
}; };

View File

@ -370,7 +370,7 @@ pub const Face = struct {
// Get the width and height of the render // Get the width and height of the render
const metrics = try measure_ctx.call(js.Object, "measureText", .{glyph_str}); const metrics = try measure_ctx.call(js.Object, "measureText", .{glyph_str});
errdefer metrics.deinit(); errdefer metrics.deinit();
const width: u32 = @floatToInt(u32, @ceil(width: { const width: u32 = @intFromFloat(u32, @ceil(width: {
// We prefer the bounding box since it is tighter but certain // We prefer the bounding box since it is tighter but certain
// text such as emoji do not have a bounding box set so we use // text such as emoji do not have a bounding box set so we use
// the full run width instead. // the full run width instead.
@ -389,7 +389,7 @@ pub const Face = struct {
const broken_bbox = asc + desc < 0.001; const broken_bbox = asc + desc < 0.001;
// Height is our ascender + descender for this char // Height is our ascender + descender for this char
const height = if (!broken_bbox) @floatToInt(u32, @ceil(asc + desc)) + 1 else width; const height = if (!broken_bbox) @intFromFloat(u32, @ceil(asc + desc)) + 1 else width;
// Note: width and height both get "+ 1" added to them above. This // Note: width and height both get "+ 1" added to them above. This
// is important so that there is a 1px border around the glyph to avoid // is important so that there is a 1px border around the glyph to avoid
@ -435,7 +435,7 @@ pub const Face = struct {
try ctx.call(void, "fillText", .{ try ctx.call(void, "fillText", .{
glyph_str, glyph_str,
left + 1, left + 1,
if (!broken_bbox) asc + 1 else @intToFloat(f32, height), if (!broken_bbox) asc + 1 else @floatFromInt(f32, height),
}); });
// Read the image data and get it into a []u8 on our side // Read the image data and get it into a []u8 on our side
@ -501,7 +501,7 @@ pub const Wasm = struct {
alloc, alloc,
ptr[0..len], ptr[0..len],
.{ .points = pts }, .{ .points = pts },
@intToEnum(font.Presentation, presentation), @enumFromInt(font.Presentation, presentation),
); );
errdefer face.deinit(); errdefer face.deinit();

View File

@ -32,7 +32,7 @@ pub const Sprite = enum(u32) {
test { test {
const testing = std.testing; const testing = std.testing;
try testing.expectEqual(start, @enumToInt(Sprite.underline)); try testing.expectEqual(start, @intFromEnum(Sprite.underline));
} }
}; };

View File

@ -75,7 +75,7 @@ pub fn renderGlyph(
.offset_y = offset_y, .offset_y = offset_y,
.atlas_x = region.x, .atlas_x = region.x,
.atlas_y = region.y, .atlas_y = region.y,
.advance_x = @intToFloat(f32, self.width), .advance_x = @floatFromInt(f32, self.width),
}; };
} }
@ -308,9 +308,9 @@ fn draw(self: Box, alloc: Allocator, canvas: *font.sprite.Canvas, cp: u32) !void
// Not official box characters but special characters we hide // Not official box characters but special characters we hide
// in the high bits of a unicode codepoint. // in the high bits of a unicode codepoint.
@enumToInt(Sprite.cursor_rect) => self.draw_cursor_rect(canvas), @intFromEnum(Sprite.cursor_rect) => self.draw_cursor_rect(canvas),
@enumToInt(Sprite.cursor_hollow_rect) => self.draw_cursor_hollow_rect(canvas), @intFromEnum(Sprite.cursor_hollow_rect) => self.draw_cursor_hollow_rect(canvas),
@enumToInt(Sprite.cursor_bar) => self.draw_cursor_bar(canvas), @intFromEnum(Sprite.cursor_bar) => self.draw_cursor_bar(canvas),
else => return error.InvalidCodepoint, else => return error.InvalidCodepoint,
} }
@ -1068,23 +1068,23 @@ fn draw_light_diagonal_upper_right_to_lower_left(self: Box, canvas: *font.sprite
.bottom = @intCast(i32, self.height), .bottom = @intCast(i32, self.height),
.left = .{ .left = .{
.p1 = .{ .p1 = .{
.x = @floatToInt(i32, @intToFloat(f64, self.width) - @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, @floatFromInt(f64, self.width) - @floatFromInt(f64, thick_px) / 2),
.y = 0, .y = 0,
}, },
.p2 = .{ .p2 = .{
.x = @floatToInt(i32, 0 - @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2),
.y = @intCast(i32, self.height), .y = @intCast(i32, self.height),
}, },
}, },
.right = .{ .right = .{
.p1 = .{ .p1 = .{
.x = @floatToInt(i32, @intToFloat(f64, self.width) + @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, @floatFromInt(f64, self.width) + @floatFromInt(f64, thick_px) / 2),
.y = 0, .y = 0,
}, },
.p2 = .{ .p2 = .{
.x = @floatToInt(i32, 0 + @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2),
.y = @intCast(i32, self.height), .y = @intCast(i32, self.height),
}, },
}, },
@ -1098,23 +1098,23 @@ fn draw_light_diagonal_upper_left_to_lower_right(self: Box, canvas: *font.sprite
.bottom = @intCast(i32, self.height), .bottom = @intCast(i32, self.height),
.left = .{ .left = .{
.p1 = .{ .p1 = .{
.x = @floatToInt(i32, 0 - @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, 0 - @floatFromInt(f64, thick_px) / 2),
.y = 0, .y = 0,
}, },
.p2 = .{ .p2 = .{
.x = @floatToInt(i32, @intToFloat(f64, self.width) - @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, @floatFromInt(f64, self.width) - @floatFromInt(f64, thick_px) / 2),
.y = @intCast(i32, self.height), .y = @intCast(i32, self.height),
}, },
}, },
.right = .{ .right = .{
.p1 = .{ .p1 = .{
.x = @floatToInt(i32, 0 + @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, 0 + @floatFromInt(f64, thick_px) / 2),
.y = 0, .y = 0,
}, },
.p2 = .{ .p2 = .{
.x = @floatToInt(i32, @intToFloat(f64, self.width) + @intToFloat(f64, thick_px) / 2), .x = @intFromFloat(i32, @floatFromInt(f64, self.width) + @floatFromInt(f64, thick_px) / 2),
.y = @intCast(i32, self.height), .y = @intCast(i32, self.height),
}, },
}, },
@ -1194,7 +1194,7 @@ fn draw_lower_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
0, 0,
self.height - @floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 8)), self.height - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 8)),
self.width, self.width,
self.height, self.height,
); );
@ -1204,7 +1204,7 @@ fn draw_lower_half_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
0, 0,
self.height - @floatToInt(u32, @round(@intToFloat(f64, self.height) / 2)), self.height - @intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 2)),
self.width, self.width,
self.height, self.height,
); );
@ -1214,7 +1214,7 @@ fn draw_lower_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
0, 0,
self.height - @floatToInt(u32, @round(5 * @intToFloat(f64, self.height) / 8)), self.height - @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.height) / 8)),
self.width, self.width,
self.height, self.height,
); );
@ -1224,7 +1224,7 @@ fn draw_lower_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void
self.rect( self.rect(
canvas, canvas,
0, 0,
self.height - @floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 4)), self.height - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 4)),
self.width, self.width,
self.height, self.height,
); );
@ -1234,7 +1234,7 @@ fn draw_lower_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
0, 0,
self.height - @floatToInt(u32, @round(7 * @intToFloat(f64, self.height) / 8)), self.height - @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.height) / 8)),
self.width, self.width,
self.height, self.height,
); );
@ -1246,7 +1246,7 @@ fn draw_upper_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
0, 0,
0, 0,
self.width, self.width,
@floatToInt(u32, @round(@intToFloat(f64, self.height) / 4)), @intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 4)),
); );
} }
@ -1256,7 +1256,7 @@ fn draw_upper_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
0, 0,
0, 0,
self.width, self.width,
@floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 8)), @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 8)),
); );
} }
@ -1266,7 +1266,7 @@ fn draw_upper_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
0, 0,
0, 0,
self.width, self.width,
@floatToInt(u32, @round(5 * @intToFloat(f64, self.height) / 8)), @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.height) / 8)),
); );
} }
@ -1276,7 +1276,7 @@ fn draw_upper_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void
0, 0,
0, 0,
self.width, self.width,
@floatToInt(u32, @round(3 * @intToFloat(f64, self.height) / 4)), @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.height) / 4)),
); );
} }
@ -1286,7 +1286,7 @@ fn draw_upper_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
0, 0,
0, 0,
self.width, self.width,
@floatToInt(u32, @round(7 * @intToFloat(f64, self.height) / 8)), @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.height) / 8)),
); );
} }
@ -1299,7 +1299,7 @@ fn draw_left_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
canvas, canvas,
0, 0,
0, 0,
@floatToInt(u32, @round(7 * @intToFloat(f64, self.width) / 8)), @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.width) / 8)),
self.height, self.height,
); );
} }
@ -1309,7 +1309,7 @@ fn draw_left_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void {
canvas, canvas,
0, 0,
0, 0,
@floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 4)), @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 4)),
self.height, self.height,
); );
} }
@ -1319,7 +1319,7 @@ fn draw_left_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
canvas, canvas,
0, 0,
0, 0,
@floatToInt(u32, @round(5 * @intToFloat(f64, self.width) / 8)), @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.width) / 8)),
self.height, self.height,
); );
} }
@ -1329,7 +1329,7 @@ fn draw_left_half_block(self: Box, canvas: *font.sprite.Canvas) void {
canvas, canvas,
0, 0,
0, 0,
@floatToInt(u32, @round(@intToFloat(f64, self.width) / 2)), @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)),
self.height, self.height,
); );
} }
@ -1339,7 +1339,7 @@ fn draw_left_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
canvas, canvas,
0, 0,
0, 0,
@floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 8)), @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 8)),
self.height, self.height,
); );
} }
@ -1349,14 +1349,14 @@ fn draw_left_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
canvas, canvas,
0, 0,
0, 0,
@floatToInt(u32, @round(@intToFloat(f64, self.width) / 4)), @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 4)),
self.height, self.height,
); );
} }
fn draw_vertical_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void { fn draw_vertical_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void {
const x = @floatToInt(u32, @round(@intToFloat(f64, n) * @intToFloat(f64, self.width) / 8)); const x = @intFromFloat(u32, @round(@floatFromInt(f64, n) * @floatFromInt(f64, self.width) / 8));
const w = @floatToInt(u32, @round(@intToFloat(f64, self.width) / 8)); const w = @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 8));
self.rect(canvas, x, 0, x + w, self.height); self.rect(canvas, x, 0, x + w, self.height);
} }
@ -1367,7 +1367,7 @@ fn draw_left_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void {
fn draw_right_half_block(self: Box, canvas: *font.sprite.Canvas) void { fn draw_right_half_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
@floatToInt(u32, @round(@intToFloat(f64, self.width) / 2)), @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)),
0, 0,
self.width, self.width,
self.height, self.height,
@ -1380,7 +1380,7 @@ fn draw_pixman_shade(self: Box, canvas: *font.sprite.Canvas, v: u16) void {
.y1 = 0, .y1 = 0,
.x2 = @intCast(i32, self.width), .x2 = @intCast(i32, self.width),
.y2 = @intCast(i32, self.height), .y2 = @intCast(i32, self.height),
}).rect(), @intToEnum(font.sprite.Color, v)); }).rect(), @enumFromInt(font.sprite.Color, v));
} }
fn draw_light_shade(self: Box, canvas: *font.sprite.Canvas) void { fn draw_light_shade(self: Box, canvas: *font.sprite.Canvas) void {
@ -1396,8 +1396,8 @@ fn draw_dark_shade(self: Box, canvas: *font.sprite.Canvas) void {
} }
fn draw_horizontal_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void { fn draw_horizontal_one_eighth_block_n(self: Box, canvas: *font.sprite.Canvas, n: u32) void {
const y = @floatToInt(u32, @round(@intToFloat(f64, n) * @intToFloat(f64, self.height) / 8)); const y = @intFromFloat(u32, @round(@floatFromInt(f64, n) * @floatFromInt(f64, self.height) / 8));
const h = @floatToInt(u32, @round(@intToFloat(f64, self.height) / 8)); const h = @intFromFloat(u32, @round(@floatFromInt(f64, self.height) / 8));
self.rect(canvas, 0, y, self.width, y + h); self.rect(canvas, 0, y, self.width, y + h);
} }
@ -1408,7 +1408,7 @@ fn draw_upper_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void {
fn draw_right_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void { fn draw_right_one_eighth_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
self.width - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 8)), self.width - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 8)),
0, 0,
self.width, self.width,
self.height, self.height,
@ -1450,7 +1450,7 @@ fn draw_horizontal_one_eighth_1358_block(self: Box, canvas: *font.sprite.Canvas)
fn draw_right_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void { fn draw_right_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
self.width - @floatToInt(u32, @round(@intToFloat(f64, self.width) / 4)), self.width - @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 4)),
0, 0,
self.width, self.width,
self.height, self.height,
@ -1460,7 +1460,7 @@ fn draw_right_one_quarter_block(self: Box, canvas: *font.sprite.Canvas) void {
fn draw_right_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void { fn draw_right_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
self.width - @floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 4)), self.width - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 4)),
0, 0,
self.width, self.width,
self.height, self.height,
@ -1470,7 +1470,7 @@ fn draw_right_three_quarters_block(self: Box, canvas: *font.sprite.Canvas) void
fn draw_right_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { fn draw_right_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
self.width - @floatToInt(u32, @round(3 * @intToFloat(f64, self.width) / 8)), self.width - @intFromFloat(u32, @round(3 * @floatFromInt(f64, self.width) / 8)),
0, 0,
self.width, self.width,
self.height, self.height,
@ -1480,7 +1480,7 @@ fn draw_right_three_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
fn draw_right_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { fn draw_right_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
self.width - @floatToInt(u32, @round(5 * @intToFloat(f64, self.width) / 8)), self.width - @intFromFloat(u32, @round(5 * @floatFromInt(f64, self.width) / 8)),
0, 0,
self.width, self.width,
self.height, self.height,
@ -1490,7 +1490,7 @@ fn draw_right_five_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
fn draw_right_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void { fn draw_right_seven_eighths_block(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
self.width - @floatToInt(u32, @round(7 * @intToFloat(f64, self.width) / 8)), self.width - @intFromFloat(u32, @round(7 * @floatFromInt(f64, self.width) / 8)),
0, 0,
self.width, self.width,
self.height, self.height,
@ -1502,18 +1502,18 @@ fn quad_upper_left(self: Box, canvas: *font.sprite.Canvas) void {
canvas, canvas,
0, 0,
0, 0,
@floatToInt(u32, @ceil(@intToFloat(f64, self.width) / 2)), @intFromFloat(u32, @ceil(@floatFromInt(f64, self.width) / 2)),
@floatToInt(u32, @ceil(@intToFloat(f64, self.height) / 2)), @intFromFloat(u32, @ceil(@floatFromInt(f64, self.height) / 2)),
); );
} }
fn quad_upper_right(self: Box, canvas: *font.sprite.Canvas) void { fn quad_upper_right(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
@floatToInt(u32, @floor(@intToFloat(f64, self.width) / 2)), @intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)),
0, 0,
self.width, self.width,
@floatToInt(u32, @ceil(@intToFloat(f64, self.height) / 2)), @intFromFloat(u32, @ceil(@floatFromInt(f64, self.height) / 2)),
); );
} }
@ -1521,8 +1521,8 @@ fn quad_lower_left(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
0, 0,
@floatToInt(u32, @floor(@intToFloat(f64, self.height) / 2)), @intFromFloat(u32, @floor(@floatFromInt(f64, self.height) / 2)),
@floatToInt(u32, @ceil(@intToFloat(f64, self.width) / 2)), @intFromFloat(u32, @ceil(@floatFromInt(f64, self.width) / 2)),
self.height, self.height,
); );
} }
@ -1530,8 +1530,8 @@ fn quad_lower_left(self: Box, canvas: *font.sprite.Canvas) void {
fn quad_lower_right(self: Box, canvas: *font.sprite.Canvas) void { fn quad_lower_right(self: Box, canvas: *font.sprite.Canvas) void {
self.rect( self.rect(
canvas, canvas,
@floatToInt(u32, @floor(@intToFloat(f64, self.width) / 2)), @intFromFloat(u32, @floor(@floatFromInt(f64, self.width) / 2)),
@floatToInt(u32, @floor(@intToFloat(f64, self.height) / 2)), @intFromFloat(u32, @floor(@floatFromInt(f64, self.height) / 2)),
self.width, self.width,
self.height, self.height,
); );
@ -1755,8 +1755,8 @@ fn draw_sextant(self: Box, canvas: *font.sprite.Canvas, cp: u32) void {
fn xHalfs(self: Box) [2]u32 { fn xHalfs(self: Box) [2]u32 {
return .{ return .{
@floatToInt(u32, @round(@intToFloat(f64, self.width) / 2)), @intFromFloat(u32, @round(@floatFromInt(f64, self.width) / 2)),
@floatToInt(u32, @intToFloat(f64, self.width) / 2), @intFromFloat(u32, @floatFromInt(f64, self.width) / 2),
}; };
} }
@ -2191,7 +2191,7 @@ fn draw_light_arc(
// thickness/2.) whose centers are on its edge. This means to get the // thickness/2.) whose centers are on its edge. This means to get the
// radius of the quartercircle, we add the exact half thickness to the // radius of the quartercircle, we add the exact half thickness to the
// radius of the inner circle. // radius of the inner circle.
var c_r: f64 = @intToFloat(f64, circle_inner_edge) + @intToFloat(f64, thick_pixels) / 2; var c_r: f64 = @floatFromInt(f64, circle_inner_edge) + @floatFromInt(f64, thick_pixels) / 2;
// We need to draw short lines from the end of the quartercircle to the // We need to draw short lines from the end of the quartercircle to the
// box-edges, store one endpoint (the other is the edge of the // box-edges, store one endpoint (the other is the edge of the
@ -2305,16 +2305,16 @@ fn draw_light_arc(
// As the quartercircle ends (vertically) in the middle of a pixel, an // As the quartercircle ends (vertically) in the middle of a pixel, an
// uneven number helps hit that exactly. // uneven number helps hit that exactly.
{ {
var i: f64 = @intToFloat(f64, y_min) * 16; var i: f64 = @floatFromInt(f64, y_min) * 16;
while (i <= @intToFloat(f64, y_max) * 16) : (i += 1) { while (i <= @floatFromInt(f64, y_max) * 16) : (i += 1) {
const y = i / 16; const y = i / 16;
const x = x: { const x = x: {
// circle_hemisphere * sqrt(c_r2 - (y - c_y) * (y - c_y)) + c_x; // circle_hemisphere * sqrt(c_r2 - (y - c_y) * (y - c_y)) + c_x;
const hemi = @intToFloat(f64, circle_hemisphere); const hemi = @floatFromInt(f64, circle_hemisphere);
const y_part = y - @intToFloat(f64, c_y); const y_part = y - @floatFromInt(f64, c_y);
const y_squared = y_part * y_part; const y_squared = y_part * y_part;
const sqrt = @sqrt(c_r2 - y_squared); const sqrt = @sqrt(c_r2 - y_squared);
const f_c_x = @intToFloat(f64, c_x); const f_c_x = @floatFromInt(f64, c_x);
// We need to detect overflows and just skip this i // We need to detect overflows and just skip this i
const a = hemi * sqrt; const a = hemi * sqrt;
@ -2326,8 +2326,8 @@ fn draw_light_arc(
break :x b; break :x b;
}; };
const row = @floatToInt(i32, @round(y)); const row = @intFromFloat(i32, @round(y));
const col = @floatToInt(i32, @round(x)); const col = @intFromFloat(i32, @round(x));
if (col < 0) continue; if (col < 0) continue;
// rectangle big enough to fit entire circle with radius thick/2. // rectangle big enough to fit entire circle with radius thick/2.
@ -2350,12 +2350,12 @@ fn draw_light_arc(
var r: i32 = @max(row_start, 0); var r: i32 = @max(row_start, 0);
const r_end = @max(@min(row_end, @intCast(i32, height)), 0); const r_end = @max(@min(row_end, @intCast(i32, height)), 0);
while (r < r_end) : (r += 1) { while (r < r_end) : (r += 1) {
const r_midpoint = @intToFloat(f64, r) + 0.5; const r_midpoint = @floatFromInt(f64, r) + 0.5;
var c: i32 = @max(col_start, 0); var c: i32 = @max(col_start, 0);
const c_end = @max(@min(col_end, @intCast(i32, width)), 0); const c_end = @max(@min(col_end, @intCast(i32, width)), 0);
while (c < c_end) : (c += 1) { while (c < c_end) : (c += 1) {
const c_midpoint = @intToFloat(f64, c) + 0.5; const c_midpoint = @floatFromInt(f64, c) + 0.5;
// vector from point on quartercircle to midpoint of the current pixel. // vector from point on quartercircle to midpoint of the current pixel.
const center_midpoint_x = c_midpoint - x; const center_midpoint_x = c_midpoint - x;
@ -2364,7 +2364,7 @@ fn draw_light_arc(
// distance from current point to circle-center. // distance from current point to circle-center.
const dist = @sqrt(center_midpoint_x * center_midpoint_x + center_midpoint_y * center_midpoint_y); const dist = @sqrt(center_midpoint_x * center_midpoint_x + center_midpoint_y * center_midpoint_y);
// skip if midpoint of pixel is outside the circle. // skip if midpoint of pixel is outside the circle.
if (dist > @intToFloat(f64, thick) / 2) continue; if (dist > @floatFromInt(f64, thick) / 2) continue;
// Set our pixel // Set our pixel
const idx = @intCast(usize, r * @intCast(i32, width) + c); const idx = @intCast(usize, r * @intCast(i32, width) + c);
@ -2398,7 +2398,7 @@ fn draw_light_arc(
.width = 1, .width = 1,
.height = 1, .height = 1,
}, },
@intToEnum(font.sprite.Color, average), @enumFromInt(font.sprite.Color, average),
); );
} }
} }

View File

@ -72,7 +72,7 @@ pub fn renderGlyph(
.underline => try underline.renderGlyph( .underline => try underline.renderGlyph(
alloc, alloc,
atlas, atlas,
@intToEnum(Sprite, cp), @enumFromInt(Sprite, cp),
self.width, self.width,
self.height, self.height,
self.underline_position, self.underline_position,
@ -88,7 +88,7 @@ const Kind = enum {
pub fn init(cp: u32) ?Kind { pub fn init(cp: u32) ?Kind {
return switch (cp) { return switch (cp) {
Sprite.start...Sprite.end => switch (@intToEnum(Sprite, cp)) { Sprite.start...Sprite.end => switch (@enumFromInt(Sprite, cp)) {
.underline, .underline,
.underline_double, .underline_double,
.underline_dotted, .underline_dotted,

View File

@ -68,16 +68,16 @@ pub const Color = enum(u8) {
fn pixmanColor(self: Color) pixman.Color { fn pixmanColor(self: Color) pixman.Color {
// pixman uses u16 for color while our color value is u8 so we // pixman uses u16 for color while our color value is u8 so we
// scale it up proportionally. // scale it up proportionally.
const max = @intToFloat(f32, std.math.maxInt(u8)); const max = @floatFromInt(f32, std.math.maxInt(u8));
const max_u16 = @intToFloat(f32, std.math.maxInt(u16)); const max_u16 = @floatFromInt(f32, std.math.maxInt(u16));
const unscaled = @intToFloat(f32, @enumToInt(self)); const unscaled = @floatFromInt(f32, @intFromEnum(self));
const scaled = @floatToInt(u16, (unscaled * max_u16) / max); const scaled = @intFromFloat(u16, (unscaled * max_u16) / max);
return .{ .red = 0, .green = 0, .blue = 0, .alpha = scaled }; return .{ .red = 0, .green = 0, .blue = 0, .alpha = scaled };
} }
fn cssColor(self: Color, buf: []u8) ![]u8 { fn cssColor(self: Color, buf: []u8) ![]u8 {
return try std.fmt.bufPrint(buf, "rgba(0, 0, 0, {:.2})", .{ return try std.fmt.bufPrint(buf, "rgba(0, 0, 0, {:.2})", .{
@intToFloat(f32, @enumToInt(self)) / 255, @floatFromInt(f32, @intFromEnum(self)) / 255,
}); });
} }
}; };

View File

@ -52,7 +52,7 @@ pub fn renderGlyph(
.offset_y = offset_y, .offset_y = offset_y,
.atlas_x = region.x, .atlas_x = region.x,
.atlas_y = region.y, .atlas_y = region.y,
.advance_x = @intToFloat(f32, width), .advance_x = @floatFromInt(f32, width),
}; };
} }
@ -178,16 +178,16 @@ const Draw = struct {
// The full heightof the wave can be from the bottom to the // The full heightof the wave can be from the bottom to the
// underline position. We also calculate our starting y which is // underline position. We also calculate our starting y which is
// slightly below our descender since our wave will move about that. // slightly below our descender since our wave will move about that.
const wave_height = @intToFloat(f64, y_max - pos); const wave_height = @floatFromInt(f64, y_max - pos);
const half_height = wave_height / 4; const half_height = wave_height / 4;
const y = pos + @floatToInt(u32, half_height); const y = pos + @intFromFloat(u32, half_height);
const x_factor = (2 * std.math.pi) / @intToFloat(f64, self.width); const x_factor = (2 * std.math.pi) / @floatFromInt(f64, self.width);
var x: u32 = 0; var x: u32 = 0;
while (x < self.width) : (x += 1) { while (x < self.width) : (x += 1) {
const vertical = @floatToInt( const vertical = @intFromFloat(
u32, u32,
(-1 * half_height) * @sin(@intToFloat(f64, x) * x_factor) + half_height, (-1 * half_height) * @sin(@floatFromInt(f64, x) * x_factor) + half_height,
); );
var row: u32 = 0; var row: u32 = 0;

View File

@ -20,7 +20,7 @@ pub fn fixMaxFiles() void {
// setrlimit() now returns with errno set to EINVAL in places that historically succeeded. // setrlimit() now returns with errno set to EINVAL in places that historically succeeded.
// It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE. // It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.
// Use "rlim_cur = min(OPEN_MAX, rlim_max)". // Use "rlim_cur = min(OPEN_MAX, rlim_max)".
lim.max = std.math.min(std.os.darwin.OPEN_MAX, lim.max); lim.max = @min(std.os.darwin.OPEN_MAX, lim.max);
} }
// If we're already at the max, we're done. // If we're already at the max, we're done.

View File

@ -164,7 +164,7 @@ pub const FlatpakHostCommand = struct {
"(uub)", "(uub)",
pid, pid,
sig, sig,
@intCast(c_int, @boolToInt(pg)), @intCast(c_int, @intFromBool(pg)),
), ),
c.G_VARIANT_TYPE("()"), c.G_VARIANT_TYPE("()"),
c.G_DBUS_CALL_FLAGS_NONE, c.G_DBUS_CALL_FLAGS_NONE,

View File

@ -16,7 +16,7 @@ pub fn clickInterval() ?u32 {
// Get the interval and convert to ms // Get the interval and convert to ms
const interval = NSEvent.msgSend(f64, objc.sel("doubleClickInterval"), .{}); const interval = NSEvent.msgSend(f64, objc.sel("doubleClickInterval"), .{});
const ms = @floatToInt(u32, @ceil(interval * 1000)); const ms = @intFromFloat(u32, @ceil(interval * 1000));
return ms; return ms;
} }

View File

@ -70,7 +70,7 @@ pub fn toHostOwned(ptr: anytype) ![*]u8 {
const info = @typeInfo(@TypeOf(ptr)).Pointer; const info = @typeInfo(@TypeOf(ptr)).Pointer;
const T = info.child; const T = info.child;
const size = @sizeOf(T); const size = @sizeOf(T);
const casted = @intToPtr([*]u8, @ptrToInt(ptr)); const casted = @ptrFromInt([*]u8, @intFromPtr(ptr));
// Store the information about it // Store the information about it
try allocs.putNoClobber(alloc, casted, size); try allocs.putNoClobber(alloc, casted, size);
@ -81,14 +81,14 @@ pub fn toHostOwned(ptr: anytype) ![*]u8 {
/// Returns true if the value is host owned. /// Returns true if the value is host owned.
pub fn isHostOwned(ptr: anytype) bool { pub fn isHostOwned(ptr: anytype) bool {
const casted = @intToPtr([*]u8, @ptrToInt(ptr)); const casted = @ptrFromInt([*]u8, @intFromPtr(ptr));
return allocs.contains(casted); return allocs.contains(casted);
} }
/// Convert a pointer back to a module-owned value. The caller is expected /// Convert a pointer back to a module-owned value. The caller is expected
/// to cast or have the valid pointer for alloc calls. /// to cast or have the valid pointer for alloc calls.
pub fn toModuleOwned(ptr: anytype) void { pub fn toModuleOwned(ptr: anytype) void {
const casted = @intToPtr([*]u8, @ptrToInt(ptr)); const casted = @ptrFromInt([*]u8, @intFromPtr(ptr));
_ = allocs.remove(casted); _ = allocs.remove(casted);
} }

View File

@ -11,7 +11,7 @@ pub const Target = enum {
/// Our specific target platform. /// Our specific target platform.
pub const target: ?Target = if (!builtin.target.isWasm()) null else target: { pub const target: ?Target = if (!builtin.target.isWasm()) null else target: {
const result = @intToEnum(Target, @enumToInt(options.wasm_target)); const result = @enumFromInt(Target, @intFromEnum(options.wasm_target));
// This maybe isn't necessary but I don't know if enums without a specific // This maybe isn't necessary but I don't know if enums without a specific
// tag type and value are guaranteed to be the same between build.zig // tag type and value are guaranteed to be the same between build.zig
// compilation and our own source compilation so I have this just in case. // compilation and our own source compilation so I have this just in case.

View File

@ -213,10 +213,10 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
// Set the sprite font up // Set the sprite font up
options.font_group.group.sprite = font.sprite.Face{ options.font_group.group.sprite = font.sprite.Face{
.width = @floatToInt(u32, metrics.cell_width), .width = @intFromFloat(u32, metrics.cell_width),
.height = @floatToInt(u32, metrics.cell_height), .height = @intFromFloat(u32, metrics.cell_height),
.thickness = 2, .thickness = 2,
.underline_position = @floatToInt(u32, metrics.underline_position), .underline_position = @intFromFloat(u32, metrics.underline_position),
}; };
// Create the font shaper. We initially create a shaper that can support // Create the font shaper. We initially create a shaper that can support
@ -480,10 +480,10 @@ pub fn setFontSize(self: *Metal, size: font.face.DesiredSize) !void {
// Set the sprite font up // Set the sprite font up
self.font_group.group.sprite = font.sprite.Face{ self.font_group.group.sprite = font.sprite.Face{
.width = @floatToInt(u32, self.cell_size.width), .width = @intFromFloat(u32, self.cell_size.width),
.height = @floatToInt(u32, self.cell_size.height), .height = @intFromFloat(u32, self.cell_size.height),
.thickness = 2, .thickness = 2,
.underline_position = @floatToInt(u32, metrics.underline_position), .underline_position = @intFromFloat(u32, metrics.underline_position),
}; };
// Notify the window that the cell size changed. // Notify the window that the cell size changed.
@ -618,13 +618,13 @@ pub fn render(
// which ironically doesn't implement CAMetalDrawable as a // which ironically doesn't implement CAMetalDrawable as a
// property so we just send a message. // property so we just send a message.
const texture = drawable.msgSend(objc.c.id, objc.sel("texture"), .{}); const texture = drawable.msgSend(objc.c.id, objc.sel("texture"), .{});
attachment.setProperty("loadAction", @enumToInt(MTLLoadAction.clear)); attachment.setProperty("loadAction", @intFromEnum(MTLLoadAction.clear));
attachment.setProperty("storeAction", @enumToInt(MTLStoreAction.store)); attachment.setProperty("storeAction", @intFromEnum(MTLStoreAction.store));
attachment.setProperty("texture", texture); attachment.setProperty("texture", texture);
attachment.setProperty("clearColor", MTLClearColor{ attachment.setProperty("clearColor", MTLClearColor{
.red = @intToFloat(f32, critical.bg.r) / 255, .red = @floatFromInt(f32, critical.bg.r) / 255,
.green = @intToFloat(f32, critical.bg.g) / 255, .green = @floatFromInt(f32, critical.bg.g) / 255,
.blue = @intToFloat(f32, critical.bg.b) / 255, .blue = @floatFromInt(f32, critical.bg.b) / 255,
.alpha = 1.0, .alpha = 1.0,
}); });
} }
@ -728,9 +728,9 @@ fn drawCells(
void, void,
objc.sel("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:"), objc.sel("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:"),
.{ .{
@enumToInt(MTLPrimitiveType.triangle), @intFromEnum(MTLPrimitiveType.triangle),
@as(c_ulong, 6), @as(c_ulong, 6),
@enumToInt(MTLIndexType.uint16), @intFromEnum(MTLIndexType.uint16),
self.buf_instance.value, self.buf_instance.value,
@as(c_ulong, 0), @as(c_ulong, 0),
@as(c_ulong, cells.items.len), @as(c_ulong, cells.items.len),
@ -771,8 +771,8 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void {
// Set the size of the drawable surface to the bounds // Set the size of the drawable surface to the bounds
self.swapchain.setProperty("drawableSize", macos.graphics.Size{ self.swapchain.setProperty("drawableSize", macos.graphics.Size{
.width = @intToFloat(f64, dim.width), .width = @floatFromInt(f64, dim.width),
.height = @intToFloat(f64, dim.height), .height = @floatFromInt(f64, dim.height),
}); });
// Setup our uniforms // Setup our uniforms
@ -780,8 +780,8 @@ pub fn setScreenSize(self: *Metal, dim: renderer.ScreenSize) !void {
self.uniforms = .{ self.uniforms = .{
.projection_matrix = math.ortho2d( .projection_matrix = math.ortho2d(
-1 * padding.left, -1 * padding.left,
@intToFloat(f32, padded_dim.width) + padding.right, @floatFromInt(f32, padded_dim.width) + padding.right,
@intToFloat(f32, padded_dim.height) + padding.bottom, @floatFromInt(f32, padded_dim.height) + padding.bottom,
-1 * padding.top, -1 * padding.top,
), ),
.cell_size = .{ self.cell_size.width, self.cell_size.height }, .cell_size = .{ self.cell_size.width, self.cell_size.height },
@ -836,7 +836,7 @@ fn rebuildCells(
y == screen.cursor.y) y == screen.cursor.y)
{ {
for (self.cells.items[start_i..]) |cell| { for (self.cells.items[start_i..]) |cell| {
if (cell.grid_pos[0] == @intToFloat(f32, screen.cursor.x) and if (cell.grid_pos[0] == @floatFromInt(f32, screen.cursor.x) and
cell.mode == .fg) cell.mode == .fg)
{ {
cursor_cell = cell; cursor_cell = cell;
@ -986,7 +986,7 @@ pub fn updateCell(
if (colors.bg) |rgb| { if (colors.bg) |rgb| {
self.cells_bg.appendAssumeCapacity(.{ self.cells_bg.appendAssumeCapacity(.{
.mode = .bg, .mode = .bg,
.grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
.cell_width = cell.widthLegacy(), .cell_width = cell.widthLegacy(),
.color = .{ rgb.r, rgb.g, rgb.b, alpha }, .color = .{ rgb.r, rgb.g, rgb.b, alpha },
}); });
@ -999,7 +999,7 @@ pub fn updateCell(
self.alloc, self.alloc,
shaper_run.font_index, shaper_run.font_index,
shaper_cell.glyph_index, shaper_cell.glyph_index,
@floatToInt(u16, @ceil(self.cell_size.height)), @intFromFloat(u16, @ceil(self.cell_size.height)),
); );
// If we're rendering a color font, we use the color atlas // If we're rendering a color font, we use the color atlas
@ -1011,7 +1011,7 @@ pub fn updateCell(
self.cells.appendAssumeCapacity(.{ self.cells.appendAssumeCapacity(.{
.mode = mode, .mode = mode,
.grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
.cell_width = cell.widthLegacy(), .cell_width = cell.widthLegacy(),
.color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha }, .color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
.glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y },
@ -1033,7 +1033,7 @@ pub fn updateCell(
const glyph = try self.font_group.renderGlyph( const glyph = try self.font_group.renderGlyph(
self.alloc, self.alloc,
font.sprite_index, font.sprite_index,
@enumToInt(sprite), @intFromEnum(sprite),
null, null,
); );
@ -1041,7 +1041,7 @@ pub fn updateCell(
self.cells.appendAssumeCapacity(.{ self.cells.appendAssumeCapacity(.{
.mode = .fg, .mode = .fg,
.grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
.cell_width = cell.widthLegacy(), .cell_width = cell.widthLegacy(),
.color = .{ color.r, color.g, color.b, alpha }, .color = .{ color.r, color.g, color.b, alpha },
.glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y },
@ -1053,7 +1053,7 @@ pub fn updateCell(
if (cell.attrs.strikethrough) { if (cell.attrs.strikethrough) {
self.cells.appendAssumeCapacity(.{ self.cells.appendAssumeCapacity(.{
.mode = .strikethrough, .mode = .strikethrough,
.grid_pos = .{ @intToFloat(f32, x), @intToFloat(f32, y) }, .grid_pos = .{ @floatFromInt(f32, x), @floatFromInt(f32, y) },
.cell_width = cell.widthLegacy(), .cell_width = cell.widthLegacy(),
.color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha }, .color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
}); });
@ -1085,7 +1085,7 @@ fn addCursor(self: *Metal, screen: *terminal.Screen) void {
const glyph = self.font_group.renderGlyph( const glyph = self.font_group.renderGlyph(
self.alloc, self.alloc,
font.sprite_index, font.sprite_index,
@enumToInt(sprite), @intFromEnum(sprite),
null, null,
) catch |err| { ) catch |err| {
log.warn("error rendering cursor glyph err={}", .{err}); log.warn("error rendering cursor glyph err={}", .{err});
@ -1095,8 +1095,8 @@ fn addCursor(self: *Metal, screen: *terminal.Screen) void {
self.cells.appendAssumeCapacity(.{ self.cells.appendAssumeCapacity(.{
.mode = .fg, .mode = .fg,
.grid_pos = .{ .grid_pos = .{
@intToFloat(f32, screen.cursor.x), @floatFromInt(f32, screen.cursor.x),
@intToFloat(f32, screen.cursor.y), @floatFromInt(f32, screen.cursor.y),
}, },
.cell_width = if (cell.attrs.wide) 2 else 1, .cell_width = if (cell.attrs.wide) 2 else 1,
.color = .{ color.r, color.g, color.b, 0xFF }, .color = .{ color.r, color.g, color.b, 0xFF },
@ -1285,7 +1285,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
.{@as(c_ulong, 0)}, .{@as(c_ulong, 0)},
); );
attr.setProperty("format", @enumToInt(MTLVertexFormat.uchar)); attr.setProperty("format", @intFromEnum(MTLVertexFormat.uchar));
attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "mode"))); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "mode")));
attr.setProperty("bufferIndex", @as(c_ulong, 0)); attr.setProperty("bufferIndex", @as(c_ulong, 0));
} }
@ -1296,7 +1296,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
.{@as(c_ulong, 1)}, .{@as(c_ulong, 1)},
); );
attr.setProperty("format", @enumToInt(MTLVertexFormat.float2)); attr.setProperty("format", @intFromEnum(MTLVertexFormat.float2));
attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "grid_pos"))); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "grid_pos")));
attr.setProperty("bufferIndex", @as(c_ulong, 0)); attr.setProperty("bufferIndex", @as(c_ulong, 0));
} }
@ -1307,7 +1307,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
.{@as(c_ulong, 2)}, .{@as(c_ulong, 2)},
); );
attr.setProperty("format", @enumToInt(MTLVertexFormat.uint2)); attr.setProperty("format", @intFromEnum(MTLVertexFormat.uint2));
attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_pos"))); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_pos")));
attr.setProperty("bufferIndex", @as(c_ulong, 0)); attr.setProperty("bufferIndex", @as(c_ulong, 0));
} }
@ -1318,7 +1318,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
.{@as(c_ulong, 3)}, .{@as(c_ulong, 3)},
); );
attr.setProperty("format", @enumToInt(MTLVertexFormat.uint2)); attr.setProperty("format", @intFromEnum(MTLVertexFormat.uint2));
attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_size"))); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_size")));
attr.setProperty("bufferIndex", @as(c_ulong, 0)); attr.setProperty("bufferIndex", @as(c_ulong, 0));
} }
@ -1329,7 +1329,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
.{@as(c_ulong, 4)}, .{@as(c_ulong, 4)},
); );
attr.setProperty("format", @enumToInt(MTLVertexFormat.int2)); attr.setProperty("format", @intFromEnum(MTLVertexFormat.int2));
attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_offset"))); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "glyph_offset")));
attr.setProperty("bufferIndex", @as(c_ulong, 0)); attr.setProperty("bufferIndex", @as(c_ulong, 0));
} }
@ -1340,7 +1340,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
.{@as(c_ulong, 5)}, .{@as(c_ulong, 5)},
); );
attr.setProperty("format", @enumToInt(MTLVertexFormat.uchar4)); attr.setProperty("format", @intFromEnum(MTLVertexFormat.uchar4));
attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "color"))); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "color")));
attr.setProperty("bufferIndex", @as(c_ulong, 0)); attr.setProperty("bufferIndex", @as(c_ulong, 0));
} }
@ -1351,7 +1351,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
.{@as(c_ulong, 6)}, .{@as(c_ulong, 6)},
); );
attr.setProperty("format", @enumToInt(MTLVertexFormat.uchar)); attr.setProperty("format", @intFromEnum(MTLVertexFormat.uchar));
attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "cell_width"))); attr.setProperty("offset", @as(c_ulong, @offsetOf(GPUCell, "cell_width")));
attr.setProperty("bufferIndex", @as(c_ulong, 0)); attr.setProperty("bufferIndex", @as(c_ulong, 0));
} }
@ -1366,7 +1366,7 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
); );
// Access each GPUCell per instance, not per vertex. // Access each GPUCell per instance, not per vertex.
layout.setProperty("stepFunction", @enumToInt(MTLVertexStepFunction.per_instance)); layout.setProperty("stepFunction", @intFromEnum(MTLVertexStepFunction.per_instance));
layout.setProperty("stride", @as(c_ulong, @sizeOf(GPUCell))); layout.setProperty("stride", @as(c_ulong, @sizeOf(GPUCell)));
} }
@ -1401,12 +1401,12 @@ fn initPipelineState(device: objc.Object, library: objc.Object) !objc.Object {
// Blending. This is required so that our text we render on top // Blending. This is required so that our text we render on top
// of our drawable properly blends into the bg. // of our drawable properly blends into the bg.
attachment.setProperty("blendingEnabled", true); attachment.setProperty("blendingEnabled", true);
attachment.setProperty("rgbBlendOperation", @enumToInt(MTLBlendOperation.add)); attachment.setProperty("rgbBlendOperation", @intFromEnum(MTLBlendOperation.add));
attachment.setProperty("alphaBlendOperation", @enumToInt(MTLBlendOperation.add)); attachment.setProperty("alphaBlendOperation", @intFromEnum(MTLBlendOperation.add));
attachment.setProperty("sourceRGBBlendFactor", @enumToInt(MTLBlendFactor.one)); attachment.setProperty("sourceRGBBlendFactor", @intFromEnum(MTLBlendFactor.one));
attachment.setProperty("sourceAlphaBlendFactor", @enumToInt(MTLBlendFactor.one)); attachment.setProperty("sourceAlphaBlendFactor", @intFromEnum(MTLBlendFactor.one));
attachment.setProperty("destinationRGBBlendFactor", @enumToInt(MTLBlendFactor.one_minus_source_alpha)); attachment.setProperty("destinationRGBBlendFactor", @intFromEnum(MTLBlendFactor.one_minus_source_alpha));
attachment.setProperty("destinationAlphaBlendFactor", @enumToInt(MTLBlendFactor.one_minus_source_alpha)); attachment.setProperty("destinationAlphaBlendFactor", @intFromEnum(MTLBlendFactor.one_minus_source_alpha));
} }
// Make our state // Make our state
@ -1439,7 +1439,7 @@ fn initAtlasTexture(device: objc.Object, atlas: *const font.Atlas) !objc.Object
}; };
// Set our properties // Set our properties
desc.setProperty("pixelFormat", @enumToInt(pixel_format)); desc.setProperty("pixelFormat", @intFromEnum(pixel_format));
desc.setProperty("width", @intCast(c_ulong, atlas.size)); desc.setProperty("width", @intCast(c_ulong, atlas.size));
desc.setProperty("height", @intCast(c_ulong, atlas.size)); desc.setProperty("height", @intCast(c_ulong, atlas.size));
@ -1569,7 +1569,7 @@ const MTLBlendOperation = enum(c_ulong) {
/// https://developer.apple.com/documentation/metal/mtlresourceoptions?language=objc /// https://developer.apple.com/documentation/metal/mtlresourceoptions?language=objc
/// (incomplete, we only use this mode so we just hardcode it) /// (incomplete, we only use this mode so we just hardcode it)
const MTLResourceStorageModeShared: c_ulong = @enumToInt(MTLStorageMode.shared) << 4; const MTLResourceStorageModeShared: c_ulong = @intFromEnum(MTLStorageMode.shared) << 4;
const MTLClearColor = extern struct { const MTLClearColor = extern struct {
red: f64, red: f64,

View File

@ -147,8 +147,8 @@ const SetScreenSize = struct {
// 2D orthographic projection with the full w/h // 2D orthographic projection with the full w/h
math.ortho2d( math.ortho2d(
-1 * padding.left, -1 * padding.left,
@intToFloat(f32, padded_size.width) + padding.right, @floatFromInt(f32, padded_size.width) + padding.right,
@intToFloat(f32, padded_size.height) + padding.bottom, @floatFromInt(f32, padded_size.height) + padding.bottom,
-1 * padding.top, -1 * padding.top,
), ),
); );
@ -218,9 +218,9 @@ const GPUCellMode = enum(u8) {
/// Apply a mask to the mode. /// Apply a mask to the mode.
pub fn mask(self: GPUCellMode, m: GPUCellMode) GPUCellMode { pub fn mask(self: GPUCellMode, m: GPUCellMode) GPUCellMode {
return @intToEnum( return @enumFromInt(
GPUCellMode, GPUCellMode,
@enumToInt(self) | @enumToInt(m), @intFromEnum(self) | @intFromEnum(m),
); );
} }
}; };
@ -661,10 +661,10 @@ fn resetFontMetrics(
// Set details for our sprite font // Set details for our sprite font
font_group.group.sprite = font.sprite.Face{ font_group.group.sprite = font.sprite.Face{
.width = @floatToInt(u32, metrics.cell_width), .width = @intFromFloat(u32, metrics.cell_width),
.height = @floatToInt(u32, metrics.cell_height), .height = @intFromFloat(u32, metrics.cell_height),
.thickness = 2, .thickness = 2,
.underline_position = @floatToInt(u32, metrics.underline_position), .underline_position = @intFromFloat(u32, metrics.underline_position),
}; };
return metrics; return metrics;
@ -993,7 +993,7 @@ fn addCursor(self: *OpenGL, screen: *terminal.Screen) void {
const glyph = self.font_group.renderGlyph( const glyph = self.font_group.renderGlyph(
self.alloc, self.alloc,
font.sprite_index, font.sprite_index,
@enumToInt(sprite), @intFromEnum(sprite),
null, null,
) catch |err| { ) catch |err| {
log.warn("error rendering cursor glyph err={}", .{err}); log.warn("error rendering cursor glyph err={}", .{err});
@ -1147,7 +1147,7 @@ pub fn updateCell(
self.alloc, self.alloc,
shaper_run.font_index, shaper_run.font_index,
shaper_cell.glyph_index, shaper_cell.glyph_index,
@floatToInt(u16, @ceil(self.cell_size.height)), @intFromFloat(u16, @ceil(self.cell_size.height)),
); );
// If we're rendering a color font, we use the color atlas // If we're rendering a color font, we use the color atlas
@ -1192,7 +1192,7 @@ pub fn updateCell(
const underline_glyph = try self.font_group.renderGlyph( const underline_glyph = try self.font_group.renderGlyph(
self.alloc, self.alloc,
font.sprite_index, font.sprite_index,
@enumToInt(sprite), @intFromEnum(sprite),
null, null,
); );
@ -1388,9 +1388,9 @@ pub fn draw(self: *OpenGL) !void {
// Clear the surface // Clear the surface
gl.clearColor( gl.clearColor(
@intToFloat(f32, self.draw_background.r) / 255, @floatFromInt(f32, self.draw_background.r) / 255,
@intToFloat(f32, self.draw_background.g) / 255, @floatFromInt(f32, self.draw_background.g) / 255,
@intToFloat(f32, self.draw_background.b) / 255, @floatFromInt(f32, self.draw_background.b) / 255,
1.0, 1.0,
); );
gl.clear(gl.c.GL_COLOR_BUFFER_BIT); gl.clear(gl.c.GL_COLOR_BUFFER_BIT);

View File

@ -42,7 +42,7 @@ pub const Binding = struct {
usage: Usage, usage: Usage,
) !void { ) !void {
const info = dataInfo(&data); const info = dataInfo(&data);
glad.context.BufferData.?(@enumToInt(b.target), info.size, info.ptr, @enumToInt(usage)); glad.context.BufferData.?(@intFromEnum(b.target), info.size, info.ptr, @intFromEnum(usage));
try errors.getError(); try errors.getError();
} }
@ -54,7 +54,7 @@ pub const Binding = struct {
data: anytype, data: anytype,
) !void { ) !void {
const info = dataInfo(data); const info = dataInfo(data);
glad.context.BufferSubData.?(@enumToInt(b.target), @intCast(c_long, offset), info.size, info.ptr); glad.context.BufferSubData.?(@intFromEnum(b.target), @intCast(c_long, offset), info.size, info.ptr);
try errors.getError(); try errors.getError();
} }
@ -66,7 +66,7 @@ pub const Binding = struct {
comptime T: type, comptime T: type,
usage: Usage, usage: Usage,
) !void { ) !void {
glad.context.BufferData.?(@enumToInt(b.target), @sizeOf(T), null, @enumToInt(usage)); glad.context.BufferData.?(@intFromEnum(b.target), @sizeOf(T), null, @intFromEnum(usage));
try errors.getError(); try errors.getError();
} }
@ -76,7 +76,7 @@ pub const Binding = struct {
size: usize, size: usize,
usage: Usage, usage: Usage,
) !void { ) !void {
glad.context.BufferData.?(@enumToInt(b.target), @intCast(c_long, size), null, @enumToInt(usage)); glad.context.BufferData.?(@intFromEnum(b.target), @intCast(c_long, size), null, @intFromEnum(usage));
try errors.getError(); try errors.getError();
} }
@ -169,7 +169,7 @@ pub const Binding = struct {
) !void { ) !void {
const normalized_c: c.GLboolean = if (normalized) c.GL_TRUE else c.GL_FALSE; const normalized_c: c.GLboolean = if (normalized) c.GL_TRUE else c.GL_FALSE;
const offsetPtr = if (offset > 0) const offsetPtr = if (offset > 0)
@intToPtr(*const anyopaque, offset) @ptrFromInt(*const anyopaque, offset)
else else
null; null;
@ -186,7 +186,7 @@ pub const Binding = struct {
offset: usize, offset: usize,
) !void { ) !void {
const offsetPtr = if (offset > 0) const offsetPtr = if (offset > 0)
@intToPtr(*const anyopaque, offset) @ptrFromInt(*const anyopaque, offset)
else else
null; null;
@ -195,7 +195,7 @@ pub const Binding = struct {
} }
pub inline fn unbind(b: *Binding) void { pub inline fn unbind(b: *Binding) void {
glad.context.BindBuffer.?(@enumToInt(b.target), 0); glad.context.BindBuffer.?(@intFromEnum(b.target), 0);
b.* = undefined; b.* = undefined;
} }
}; };
@ -209,7 +209,7 @@ pub inline fn create() !Buffer {
/// glBindBuffer /// glBindBuffer
pub inline fn bind(v: Buffer, target: Target) !Binding { pub inline fn bind(v: Buffer, target: Target) !Binding {
glad.context.BindBuffer.?(@enumToInt(target), v.id); glad.context.BindBuffer.?(@intFromEnum(target), v.id);
return Binding{ .target = target }; return Binding{ .target = target };
} }

View File

@ -76,19 +76,19 @@ pub const Binding = struct {
target: Target, target: Target,
pub inline fn unbind(b: *Binding) void { pub inline fn unbind(b: *Binding) void {
glad.context.BindTexture.?(@enumToInt(b.target), 0); glad.context.BindTexture.?(@intFromEnum(b.target), 0);
b.* = undefined; b.* = undefined;
} }
pub fn generateMipmap(b: Binding) void { pub fn generateMipmap(b: Binding) void {
glad.context.GenerateMipmap.?(@enumToInt(b.target)); glad.context.GenerateMipmap.?(@intFromEnum(b.target));
} }
pub fn parameter(b: Binding, name: Parameter, value: anytype) !void { pub fn parameter(b: Binding, name: Parameter, value: anytype) !void {
switch (@TypeOf(value)) { switch (@TypeOf(value)) {
c.GLint => glad.context.TexParameteri.?( c.GLint => glad.context.TexParameteri.?(
@enumToInt(b.target), @intFromEnum(b.target),
@enumToInt(name), @intFromEnum(name),
value, value,
), ),
else => unreachable, else => unreachable,
@ -107,14 +107,14 @@ pub const Binding = struct {
data: ?*const anyopaque, data: ?*const anyopaque,
) !void { ) !void {
glad.context.TexImage2D.?( glad.context.TexImage2D.?(
@enumToInt(b.target), @intFromEnum(b.target),
level, level,
@enumToInt(internal_format), @intFromEnum(internal_format),
width, width,
height, height,
border, border,
@enumToInt(format), @intFromEnum(format),
@enumToInt(typ), @intFromEnum(typ),
data, data,
); );
} }
@ -131,14 +131,14 @@ pub const Binding = struct {
data: ?*const anyopaque, data: ?*const anyopaque,
) !void { ) !void {
glad.context.TexSubImage2D.?( glad.context.TexSubImage2D.?(
@enumToInt(b.target), @intFromEnum(b.target),
level, level,
xoffset, xoffset,
yoffset, yoffset,
width, width,
height, height,
@enumToInt(format), @intFromEnum(format),
@enumToInt(typ), @intFromEnum(typ),
data, data,
); );
} }
@ -153,7 +153,7 @@ pub inline fn create() !Texture {
/// glBindTexture /// glBindTexture
pub inline fn bind(v: Texture, target: Target) !Binding { pub inline fn bind(v: Texture, target: Target) !Binding {
glad.context.BindTexture.?(@enumToInt(target), v.id); glad.context.BindTexture.?(@intFromEnum(target), v.id);
try errors.getError(); try errors.getError();
return Binding{ .target = target }; return Binding{ .target = target };
} }

View File

@ -16,7 +16,7 @@ pub fn drawArrays(mode: c.GLenum, first: c.GLint, count: c.GLsizei) !void {
} }
pub fn drawElements(mode: c.GLenum, count: c.GLsizei, typ: c.GLenum, offset: usize) !void { pub fn drawElements(mode: c.GLenum, count: c.GLsizei, typ: c.GLenum, offset: usize) !void {
const offsetPtr = if (offset == 0) null else @intToPtr(*const anyopaque, offset); const offsetPtr = if (offset == 0) null else @ptrFromInt(*const anyopaque, offset);
glad.context.DrawElements.?(mode, count, typ, offsetPtr); glad.context.DrawElements.?(mode, count, typ, offsetPtr);
try errors.getError(); try errors.getError();
} }

View File

@ -48,8 +48,8 @@ pub const ScreenSize = struct {
/// Subtract padding from the screen size. /// Subtract padding from the screen size.
pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize { pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize {
return .{ return .{
.width = self.width -| @floatToInt(u32, padding.left + padding.right), .width = self.width -| @intFromFloat(u32, padding.left + padding.right),
.height = self.height -| @floatToInt(u32, padding.top + padding.bottom), .height = self.height -| @intFromFloat(u32, padding.top + padding.bottom),
}; };
} }
}; };
@ -71,8 +71,8 @@ pub const GridSize = struct {
/// Update the columns/rows for the grid based on the given screen and /// Update the columns/rows for the grid based on the given screen and
/// cell size. /// cell size.
pub fn update(self: *GridSize, screen: ScreenSize, cell: CellSize) void { pub fn update(self: *GridSize, screen: ScreenSize, cell: CellSize) void {
self.columns = @max(1, @floatToInt(Unit, @intToFloat(f32, screen.width) / cell.width)); self.columns = @max(1, @intFromFloat(Unit, @floatFromInt(f32, screen.width) / cell.width));
self.rows = @max(1, @floatToInt(Unit, @intToFloat(f32, screen.height) / cell.height)); self.rows = @max(1, @intFromFloat(Unit, @floatFromInt(f32, screen.height) / cell.height));
} }
}; };
@ -87,12 +87,12 @@ pub const Padding = struct {
/// for the given grid and cell sizes. /// for the given grid and cell sizes.
pub fn balanced(screen: ScreenSize, grid: GridSize, cell: CellSize) Padding { pub fn balanced(screen: ScreenSize, grid: GridSize, cell: CellSize) Padding {
// The size of our full grid // The size of our full grid
const grid_width = @intToFloat(f32, grid.columns) * cell.width; const grid_width = @floatFromInt(f32, grid.columns) * cell.width;
const grid_height = @intToFloat(f32, grid.rows) * cell.height; const grid_height = @floatFromInt(f32, grid.rows) * cell.height;
// The empty space to the right of a line and bottom of the last row // The empty space to the right of a line and bottom of the last row
const space_right = @intToFloat(f32, screen.width) - grid_width; const space_right = @floatFromInt(f32, screen.width) - grid_width;
const space_bot = @intToFloat(f32, screen.height) - grid_height; const space_bot = @floatFromInt(f32, screen.height) - grid_height;
// The left/right padding is just an equal split. // The left/right padding is just an equal split.
const padding_right = @floor(space_right / 2); const padding_right = @floor(space_right / 2);

View File

@ -171,7 +171,7 @@ pub const Action = union(enum) {
try writer.writeAll(" }"); try writer.writeAll(" }");
} else { } else {
try format(writer, "@{x}", .{@ptrToInt(&self)}); try format(writer, "@{x}", .{@intFromPtr(&self)});
} }
} }
}; };
@ -224,7 +224,7 @@ pub fn next(self: *Parser, c: u8) [3]?Action {
return .{ self.next_utf8(c), null, null }; return .{ self.next_utf8(c), null, null };
} }
const effect = table[c][@enumToInt(self.state)]; const effect = table[c][@intFromEnum(self.state)];
// log.info("next: {x}", .{c}); // log.info("next: {x}", .{c});
@ -348,8 +348,8 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
// If this is our first time seeing a parameter, we track // If this is our first time seeing a parameter, we track
// the separator used so that we can't mix separators later. // the separator used so that we can't mix separators later.
if (self.params_idx == 0) self.params_sep = @intToEnum(ParamSepState, c); if (self.params_idx == 0) self.params_sep = @enumFromInt(ParamSepState, c);
if (@intToEnum(ParamSepState, c) != self.params_sep) self.params_sep = .mixed; if (@enumFromInt(ParamSepState, c) != self.params_sep) self.params_sep = .mixed;
// Set param final value // Set param final value
self.params[self.params_idx] = self.param_acc; self.params[self.params_idx] = self.param_acc;

View File

@ -1048,7 +1048,7 @@ pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usi
const dst = buf; const dst = buf;
const src_offset = count * (self.cols + 1); const src_offset = count * (self.cols + 1);
const src = buf[src_offset..]; const src = buf[src_offset..];
assert(@ptrToInt(dst.ptr) < @ptrToInt(src.ptr)); assert(@intFromPtr(dst.ptr) < @intFromPtr(src.ptr));
fastmem.move(StorageCell, dst, src); fastmem.move(StorageCell, dst, src);
} }
@ -1093,7 +1093,7 @@ pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usi
// Source starts in the top... so we can copy some from there. // Source starts in the top... so we can copy some from there.
const dst = slices[0]; const dst = slices[0];
const src = slices[0][src_offset..]; const src = slices[0][src_offset..];
assert(@ptrToInt(dst.ptr) < @ptrToInt(src.ptr)); assert(@intFromPtr(dst.ptr) < @intFromPtr(src.ptr));
fastmem.move(StorageCell, dst, src); fastmem.move(StorageCell, dst, src);
remaining = total_copy - src.len; remaining = total_copy - src.len;
if (remaining == 0) break :zero_offset .{ src.len, 0 }; if (remaining == 0) break :zero_offset .{ src.len, 0 };

View File

@ -527,12 +527,12 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
.@"8_fg" => |n| { .@"8_fg" => |n| {
self.screen.cursor.pen.attrs.has_fg = true; self.screen.cursor.pen.attrs.has_fg = true;
self.screen.cursor.pen.fg = self.color_palette[@enumToInt(n)]; self.screen.cursor.pen.fg = self.color_palette[@intFromEnum(n)];
}, },
.@"8_bg" => |n| { .@"8_bg" => |n| {
self.screen.cursor.pen.attrs.has_bg = true; self.screen.cursor.pen.attrs.has_bg = true;
self.screen.cursor.pen.bg = self.color_palette[@enumToInt(n)]; self.screen.cursor.pen.bg = self.color_palette[@intFromEnum(n)];
}, },
.reset_fg => self.screen.cursor.pen.attrs.has_fg = false, .reset_fg => self.screen.cursor.pen.attrs.has_fg = false,
@ -541,12 +541,12 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
.@"8_bright_fg" => |n| { .@"8_bright_fg" => |n| {
self.screen.cursor.pen.attrs.has_fg = true; self.screen.cursor.pen.attrs.has_fg = true;
self.screen.cursor.pen.fg = self.color_palette[@enumToInt(n)]; self.screen.cursor.pen.fg = self.color_palette[@intFromEnum(n)];
}, },
.@"8_bright_bg" => |n| { .@"8_bright_bg" => |n| {
self.screen.cursor.pen.attrs.has_bg = true; self.screen.cursor.pen.attrs.has_bg = true;
self.screen.cursor.pen.bg = self.color_palette[@enumToInt(n)]; self.screen.cursor.pen.bg = self.color_palette[@intFromEnum(n)];
}, },
.@"256_fg" => |idx| { .@"256_fg" => |idx| {

View File

@ -8,7 +8,7 @@ pub const default: Palette = default: {
// Named values // Named values
var i: u8 = 0; var i: u8 = 0;
while (i < 16) : (i += 1) { while (i < 16) : (i += 1) {
result[i] = Name.default(@intToEnum(Name, i)) catch unreachable; result[i] = Name.default(@enumFromInt(Name, i)) catch unreachable;
} }
// Cube // Cube
@ -111,6 +111,6 @@ test "palette: default" {
// Safety check // Safety check
var i: u8 = 0; var i: u8 = 0;
while (i < 16) : (i += 1) { while (i < 16) : (i += 1) {
try testing.expectEqual(Name.default(@intToEnum(Name, i)), default[i]); try testing.expectEqual(Name.default(@enumFromInt(Name, i)), default[i]);
} }
} }

View File

@ -61,7 +61,7 @@ fn genTable() Table {
// anywhere transitions // anywhere transitions
const stateInfo = @typeInfo(State); const stateInfo = @typeInfo(State);
inline for (stateInfo.Enum.fields) |field| { inline for (stateInfo.Enum.fields) |field| {
const source = @intToEnum(State, field.value); const source = @enumFromInt(State, field.value);
// anywhere => ground // anywhere => ground
single(&result, 0x18, source, .ground, .execute); single(&result, 0x18, source, .ground, .execute);
@ -357,7 +357,7 @@ fn genTable() Table {
var final: Table = undefined; var final: Table = undefined;
for (0..final.len) |i| { for (0..final.len) |i| {
for (0..final[0].len) |j| { for (0..final[0].len) |j| {
final[i][j] = result[i][j] orelse transition(@intToEnum(State, j), .none); final[i][j] = result[i][j] orelse transition(@enumFromInt(State, j), .none);
} }
} }
@ -365,7 +365,7 @@ fn genTable() Table {
} }
fn single(t: *OptionalTable, c: u8, s0: State, s1: State, a: Action) void { fn single(t: *OptionalTable, c: u8, s0: State, s1: State, a: Action) void {
const s0_int = @enumToInt(s0); const s0_int = @intFromEnum(s0);
// TODO: enable this but it thinks we're in runtime right now // TODO: enable this but it thinks we're in runtime right now
// if (t[c][s0_int]) |existing| { // if (t[c][s0_int]) |existing| {

View File

@ -186,7 +186,7 @@ pub const Parser = struct {
29 => return Attribute{ .reset_strikethrough = {} }, 29 => return Attribute{ .reset_strikethrough = {} },
30...37 => return Attribute{ 30...37 => return Attribute{
.@"8_fg" = @intToEnum(color.Name, slice[0] - 30), .@"8_fg" = @enumFromInt(color.Name, slice[0] - 30),
}, },
38 => if (slice.len >= 5 and slice[1] == 2) { 38 => if (slice.len >= 5 and slice[1] == 2) {
@ -214,7 +214,7 @@ pub const Parser = struct {
39 => return Attribute{ .reset_fg = {} }, 39 => return Attribute{ .reset_fg = {} },
40...47 => return Attribute{ 40...47 => return Attribute{
.@"8_bg" = @intToEnum(color.Name, slice[0] - 40), .@"8_bg" = @enumFromInt(color.Name, slice[0] - 40),
}, },
48 => if (slice.len >= 5 and slice[1] == 2) { 48 => if (slice.len >= 5 and slice[1] == 2) {
@ -270,11 +270,11 @@ pub const Parser = struct {
90...97 => return Attribute{ 90...97 => return Attribute{
// 82 instead of 90 to offset to "bright" colors // 82 instead of 90 to offset to "bright" colors
.@"8_bright_fg" = @intToEnum(color.Name, slice[0] - 82), .@"8_bright_fg" = @enumFromInt(color.Name, slice[0] - 82),
}, },
100...107 => return Attribute{ 100...107 => return Attribute{
.@"8_bright_bg" = @intToEnum(color.Name, slice[0] - 92), .@"8_bright_bg" = @enumFromInt(color.Name, slice[0] - 92),
}, },
else => {}, else => {},

View File

@ -73,7 +73,7 @@ pub fn Stream(comptime Handler: type) type {
tracy.value(@intCast(u64, c)); tracy.value(@intCast(u64, c));
defer tracy.end(); defer tracy.end();
switch (@intToEnum(ansi.C0, c)) { switch (@enumFromInt(ansi.C0, c)) {
.NUL => {}, .NUL => {},
.ENQ => if (@hasDecl(T, "enquiry")) .ENQ => if (@hasDecl(T, "enquiry"))
@ -229,7 +229,7 @@ pub fn Stream(comptime Handler: type) type {
return; return;
} }
break :mode @intToEnum( break :mode @enumFromInt(
csi.EraseDisplay, csi.EraseDisplay,
action.params[0], action.params[0],
); );
@ -252,7 +252,7 @@ pub fn Stream(comptime Handler: type) type {
return; return;
} }
break :mode @intToEnum( break :mode @enumFromInt(
csi.EraseLine, csi.EraseLine,
action.params[0], action.params[0],
); );
@ -422,7 +422,7 @@ pub fn Stream(comptime Handler: type) type {
// TODO: test // TODO: test
'g' => if (@hasDecl(T, "tabClear")) try self.handler.tabClear( 'g' => if (@hasDecl(T, "tabClear")) try self.handler.tabClear(
switch (action.params.len) { switch (action.params.len) {
1 => @intToEnum(csi.TabClear, action.params[0]), 1 => @enumFromInt(csi.TabClear, action.params[0]),
else => { else => {
log.warn("invalid tab clear command: {}", .{action}); log.warn("invalid tab clear command: {}", .{action});
return; return;
@ -433,13 +433,13 @@ pub fn Stream(comptime Handler: type) type {
// SM - Set Mode // SM - Set Mode
'h' => if (@hasDecl(T, "setMode")) { 'h' => if (@hasDecl(T, "setMode")) {
for (action.params) |mode| for (action.params) |mode|
try self.handler.setMode(@intToEnum(ansi.Mode, mode), true); try self.handler.setMode(@enumFromInt(ansi.Mode, mode), true);
} else log.warn("unimplemented CSI callback: {}", .{action}), } else log.warn("unimplemented CSI callback: {}", .{action}),
// RM - Reset Mode // RM - Reset Mode
'l' => if (@hasDecl(T, "setMode")) { 'l' => if (@hasDecl(T, "setMode")) {
for (action.params) |mode| for (action.params) |mode|
try self.handler.setMode(@intToEnum(ansi.Mode, mode), false); try self.handler.setMode(@enumFromInt(ansi.Mode, mode), false);
} else log.warn("unimplemented CSI callback: {}", .{action}), } else log.warn("unimplemented CSI callback: {}", .{action}),
// SGR - Select Graphic Rendition // SGR - Select Graphic Rendition
@ -455,7 +455,7 @@ pub fn Stream(comptime Handler: type) type {
// TODO: test // TODO: test
'n' => if (@hasDecl(T, "deviceStatusReport")) try self.handler.deviceStatusReport( 'n' => if (@hasDecl(T, "deviceStatusReport")) try self.handler.deviceStatusReport(
switch (action.params.len) { switch (action.params.len) {
1 => @intToEnum(ansi.DeviceStatusReq, action.params[0]), 1 => @enumFromInt(ansi.DeviceStatusReq, action.params[0]),
else => { else => {
log.warn("invalid erase characters command: {}", .{action}); log.warn("invalid erase characters command: {}", .{action});
return; return;
@ -468,7 +468,7 @@ pub fn Stream(comptime Handler: type) type {
'q' => if (@hasDecl(T, "setCursorStyle")) try self.handler.setCursorStyle( 'q' => if (@hasDecl(T, "setCursorStyle")) try self.handler.setCursorStyle(
switch (action.params.len) { switch (action.params.len) {
0 => ansi.CursorStyle.default, 0 => ansi.CursorStyle.default,
1 => @intToEnum(ansi.CursorStyle, action.params[0]), 1 => @enumFromInt(ansi.CursorStyle, action.params[0]),
else => { else => {
log.warn("invalid set curor style command: {}", .{action}); log.warn("invalid set curor style command: {}", .{action});
return; return;
@ -505,7 +505,7 @@ pub fn Stream(comptime Handler: type) type {
break :decsasd false; break :decsasd false;
try self.handler.setActiveStatusDisplay( try self.handler.setActiveStatusDisplay(
@intToEnum(ansi.StatusDisplay, action.params[0]), @enumFromInt(ansi.StatusDisplay, action.params[0]),
); );
break :decsasd true; break :decsasd true;
}; };
@ -799,10 +799,10 @@ test "stream: cursor right (CUF)" {
test "stream: set mode (SM) and reset mode (RM)" { test "stream: set mode (SM) and reset mode (RM)" {
const H = struct { const H = struct {
mode: ansi.Mode = @intToEnum(ansi.Mode, 0), mode: ansi.Mode = @enumFromInt(ansi.Mode, 0),
pub fn setMode(self: *@This(), mode: ansi.Mode, v: bool) !void { pub fn setMode(self: *@This(), mode: ansi.Mode, v: bool) !void {
self.mode = @intToEnum(ansi.Mode, 0); self.mode = @enumFromInt(ansi.Mode, 0);
if (v) self.mode = mode; if (v) self.mode = mode;
} }
}; };
@ -812,5 +812,5 @@ test "stream: set mode (SM) and reset mode (RM)" {
try testing.expectEqual(@as(ansi.Mode, .origin), s.handler.mode); try testing.expectEqual(@as(ansi.Mode, .origin), s.handler.mode);
try s.nextSlice("\x1B[?6l"); try s.nextSlice("\x1B[?6l");
try testing.expectEqual(@intToEnum(ansi.Mode, 0), s.handler.mode); try testing.expectEqual(@enumFromInt(ansi.Mode, 0), s.handler.mode);
} }

View File

@ -881,7 +881,7 @@ const ReadThread = struct {
const end = buf.len; const end = buf.len;
if (ev.terminal_stream.parser.state == .ground) { if (ev.terminal_stream.parser.state == .ground) {
for (buf[i..end]) |ch| { for (buf[i..end]) |ch| {
switch (terminal.parse_table.table[ch][@enumToInt(terminal.Parser.State.ground)].action) { switch (terminal.parse_table.table[ch][@intFromEnum(terminal.Parser.State.ground)].action) {
// Print, call directly. // Print, call directly.
.print => ev.terminal_stream.handler.print(@intCast(u21, ch)) catch |err| .print => ev.terminal_stream.handler.print(@intCast(u21, ch)) catch |err|
log.err("error processing terminal data: {}", .{err}), log.err("error processing terminal data: {}", .{err}),

2
vendor/libxev vendored

@ -1 +1 @@
Subproject commit 9024a57ef9133382f95927eaf4b6c2b1662598e0 Subproject commit b17acd118d3442b5e937f509cfbc95e17bed47ba

2
vendor/mach-glfw vendored

@ -1 +1 @@
Subproject commit 936bfeafa317314a1141e8f4521b1cb1f9743d4d Subproject commit 1bc121e0b1fcc0d367b750eb12893febd887d3a9