From cd0c445d1ef6ec62ff6dc94b0f81a5910ef4e1ec Mon Sep 17 00:00:00 2001 From: Gota7 Date: Thu, 23 Oct 2025 22:08:43 -0400 Subject: [PATCH] Return Tuples When Appropriate --- README.md | 2 +- build.zig | 2 +- build.zig.zon | 2 +- src/assert.zig | 14 ++++---- src/audio.zig | 38 ++++++++++----------- src/camera.zig | 10 +++--- src/events.zig | 78 +++++++++++++++++++++---------------------- src/gamepad.zig | 4 +-- src/gpu.zig | 20 +++++------ src/image.zig | 8 ++--- src/joystick.zig | 26 +++++++-------- src/keyboard.zig | 10 +++--- src/log.zig | 14 ++++---- src/mouse.zig | 30 ++++++++--------- src/process.zig | 14 ++++---- src/render.zig | 36 ++++++++++---------- src/time.zig | 14 ++++---- src/ttf.zig | 36 ++++++++++---------- src/video.zig | 48 +++++++++++++------------- template/src/main.zig | 14 ++++---- 20 files changed, 211 insertions(+), 209 deletions(-) diff --git a/README.md b/README.md index 9e84235..7a7faea 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The master branch of zig is not currently supported. Choose the command that matches your desired zig-sdl3 version and run it in your project's root directory: * For the latest tagged release: ```sh -zig fetch --save git+https://github.com/Gota7/zig-sdl3#v0.1.4 +zig fetch --save git+https://github.com/Gota7/zig-sdl3#v0.1.5 ``` * For in progress updates (nightly): ```sh diff --git a/build.zig b/build.zig index 07c27d8..573b250 100644 --- a/build.zig +++ b/build.zig @@ -23,7 +23,7 @@ pub fn build(b: *std.Build) !void { .version = .{ .major = 0, .minor = 1, - .patch = 4, + .patch = 5, }, }; diff --git a/build.zig.zon b/build.zig.zon index c7c40d9..427026b 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = .sdl3, - .version = "0.1.4", + .version = "0.1.5", .minimum_zig_version = "0.15.1", .dependencies = .{ .sdl = .{ diff --git a/src/assert.zig b/src/assert.zig index f765ab8..aac88f6 100644 --- a/src/assert.zig +++ b/src/assert.zig @@ -131,10 +131,10 @@ pub fn getDefaultHandler() HandlerC { /// /// ## Version /// This function is available since SDL 3.2.0. -pub fn getHandler() struct { handler: HandlerC, user_data: ?*anyopaque } { +pub fn getHandler() struct { HandlerC, ?*anyopaque } { var user_data: ?*anyopaque = undefined; const handler = c.SDL_GetAssertionHandler(&user_data).?; - return .{ .handler = handler, .user_data = user_data }; + return .{ handler, user_data }; } /// Get a list of all assertion failures. @@ -241,7 +241,7 @@ pub fn setHandler( ) void { const Cb = struct { pub fn run(assert_data_c: [*c]const c.SDL_AssertData, user_data_c: ?*anyopaque) callconv(.c) c.SDL_AssertState { - return @intFromEnum(handler.?(@bitCast(assert_data_c.*), @alignCast(@ptrCast(user_data_c)))); + return @intFromEnum(handler.?(@bitCast(assert_data_c.*), @ptrCast(@alignCast(user_data_c)))); } }; c.SDL_SetAssertionHandler(if (handler != null) Cb.run else null, user_data); @@ -260,9 +260,9 @@ fn testAssertCallback(assert_data: AssertData, user_data: ?*TestHandlerCallbackD test "Assert" { std.testing.refAllDeclsRecursive(@This()); - const handler = getHandler(); - try std.testing.expectEqual(getDefaultHandler(), handler.handler); - try std.testing.expectEqual(null, handler.user_data); + const handler, const user_data = getHandler(); + try std.testing.expectEqual(getDefaultHandler(), handler); + try std.testing.expectEqual(null, user_data); var data = TestHandlerCallbackData{}; setHandler(TestHandlerCallbackData, testAssertCallback, &data); @@ -288,5 +288,5 @@ test "Assert" { try std.testing.expectEqual(null, getReport()); setHandler(void, null, null); - try std.testing.expectEqual(getDefaultHandler(), getHandler().handler); + try std.testing.expectEqual(getDefaultHandler(), getHandler()[0]); } diff --git a/src/audio.zig b/src/audio.zig index b30f944..bf4b909 100644 --- a/src/audio.zig +++ b/src/audio.zig @@ -499,7 +499,7 @@ pub const Device = packed struct { /// * `self`: The device instance to query. /// /// ## Return Value - /// Returns the audio specification of the device as long as the buffer size in sample frames. + /// Returns the audio specification of the device as well as the buffer size in sample frames. /// /// ## Remarks /// For an opened device, this will report the format the device is currently using. @@ -523,7 +523,7 @@ pub const Device = packed struct { /// This function is available since SDL 3.2.0. pub fn getFormat( self: Device, - ) !struct { spec: Spec, buffer_size_frames: usize } { + ) !struct { Spec, usize } { var spec: c.SDL_AudioSpec = undefined; var buffer_size_frames: c_int = undefined; const ret = c.SDL_GetAudioDeviceFormat( @@ -532,7 +532,7 @@ pub const Device = packed struct { &buffer_size_frames, ); try errors.wrapCallBool(ret); - return .{ .spec = Spec.fromSdl(spec), .buffer_size_frames = @intCast(buffer_size_frames) }; + return .{ Spec.fromSdl(spec), @intCast(buffer_size_frames) }; } /// Get the current channel map of an audio device. @@ -825,7 +825,7 @@ pub const Device = packed struct { additional_amount_c: c_int, total_amount_c: c_int, ) callconv(.c) void { - callback.?(@alignCast(@ptrCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c)); + callback.?(@ptrCast(@alignCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c)); } }; const spec_sdl: c.SDL_AudioSpec = if (spec) |val| val.toSdl() else undefined; @@ -985,7 +985,7 @@ pub const Device = packed struct { ) !void { const Cb = struct { pub fn run(user_data_c: ?*anyopaque, spec_c: [*c]const c.SDL_AudioSpec, buffer_c: [*c]f32, buffer_len_c: c_int) callconv(.c) void { - callback.?(@alignCast(@ptrCast(user_data_c)), Spec.fromSdl(spec_c.*), buffer_c[0..@intCast(buffer_len_c)]); + callback.?(@ptrCast(@alignCast(user_data_c)), Spec.fromSdl(spec_c.*), buffer_c[0..@intCast(buffer_len_c)]); } }; return errors.wrapCallBool(c.SDL_SetAudioPostmixCallback(self.value, Cb.run orelse null, user_data)); @@ -1162,7 +1162,7 @@ pub const Stream = packed struct { /// * `self`: The stream to query. /// /// ## Return Value - /// Returns the input and output formats of the stream. + /// Returns the input and output formats of the stream in that order. /// /// ## Thread Safety /// It is safe to call this function from any thread, as it holds a stream-specific mutex while running. @@ -1171,13 +1171,13 @@ pub const Stream = packed struct { /// This function is available since SDL 3.2.0. pub fn getFormat( self: Stream, - ) !struct { input_format: Spec, output_format: Spec } { + ) !struct { Spec, Spec } { var input_format: c.SDL_AudioSpec = undefined; var output_format: c.SDL_AudioSpec = undefined; try errors.wrapCallBool(c.SDL_GetAudioStreamFormat(self.value, &input_format, &output_format)); return .{ - .input_format = Spec.fromSdl(input_format), - .output_format = Spec.fromSdl(output_format), + Spec.fromSdl(input_format), + Spec.fromSdl(output_format), }; } @@ -1598,7 +1598,7 @@ pub const Stream = packed struct { additional_amount_c: c_int, total_amount_c: c_int, ) callconv(.c) void { - callback.?(@alignCast(@ptrCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c)); + callback.?(@ptrCast(@alignCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c)); } }; _ = c.SDL_SetAudioStreamGetCallback( @@ -1747,7 +1747,7 @@ pub const Stream = packed struct { additional_amount_c: c_int, total_amount_c: c_int, ) callconv(.c) void { - callback.?(@alignCast(@ptrCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c)); + callback.?(@ptrCast(@alignCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c)); } }; _ = c.SDL_SetAudioStreamPutCallback( @@ -2050,7 +2050,7 @@ pub fn getRecordingDevices() ![]Device { /// * `path`: The file path for the WAV to open. /// /// ## Return Value -/// Returns the audio spec of the WAV along with its data. +/// Returns the audio spec of the WAV along with its data in that order. /// The `data` must be freed with `free()`. /// /// ## Remarks @@ -2064,7 +2064,7 @@ pub fn getRecordingDevices() ![]Device { /// This function is available since SDL 3.2.0. pub fn loadWav( path: [:0]const u8, -) !struct { spec: Spec, data: []u8 } { +) !struct { Spec, []u8 } { var data: [*c]u8 = undefined; var len: u32 = undefined; var spec: c.SDL_AudioSpec = undefined; @@ -2075,8 +2075,8 @@ pub fn loadWav( &len, )); return .{ - .spec = Spec.fromSdl(spec), - .data = data[0..@intCast(len)], + Spec.fromSdl(spec), + data[0..@intCast(len)], }; } @@ -2087,7 +2087,7 @@ pub fn loadWav( /// * `close_io`: Will close the `src` before returning, even on error. /// /// ## Return Value -/// Returns the audio spec of the WAV along with its data. +/// Returns the audio spec of the WAV along with its data in that order. /// The `data` must be freed with `free()`. /// /// ## Remarks @@ -2121,7 +2121,7 @@ pub fn loadWav( pub fn loadWavIo( src: io_stream.Stream, close_io: bool, -) !struct { spec: Spec, data: []u8 } { +) !struct { Spec, []u8 } { var data: [*c]u8 = undefined; var len: u32 = undefined; var spec: c.SDL_AudioSpec = undefined; @@ -2133,8 +2133,8 @@ pub fn loadWavIo( &len, )); return .{ - .spec = Spec.fromSdl(spec), - .data = data[0..@intCast(len)], + Spec.fromSdl(spec), + data[0..@intCast(len)], }; } diff --git a/src/camera.zig b/src/camera.zig index d1bf2de..52650a5 100644 --- a/src/camera.zig +++ b/src/camera.zig @@ -157,7 +157,7 @@ pub const Camera = packed struct { /// /// ## Return Value /// Returns a new frame of video on success, `null` if none is currently available. - /// Also returns frame's timestamp, or `null` on error. + /// Also returns frame's timestamp in nanoseconds, or `null` on error. /// /// ## Remarks /// The frame is a memory pointer to the image data, whose size and format are given by the spec requested when opening the device. @@ -185,13 +185,13 @@ pub const Camera = packed struct { /// This function is available since SDL 3.2.0. pub fn acquireFrame( self: Camera, - ) struct { frame: ?surface.Surface, timestamp_nanoseconds: ?u64 } { + ) struct { ?surface.Surface, ?u64 } { var timestamp_nanoseconds: u64 = undefined; const ret = c.SDL_AcquireCameraFrame( self.value, ×tamp_nanoseconds, ); - return .{ .frame = if (ret != null) .{ .value = ret } else null, .timestamp_nanoseconds = if (timestamp_nanoseconds == 0) null else timestamp_nanoseconds }; + return .{ if (ret != null) .{ .value = ret } else null, if (timestamp_nanoseconds == 0) null else timestamp_nanoseconds }; } /// Use this function to shut down camera processing and close the camera device. @@ -571,8 +571,8 @@ test "Camera" { _ = cam.getFormat() catch {}; _ = cam.getPermissionState(); _ = cam.getProperties() catch {}; - const frame = cam.acquireFrame(); - if (frame.frame) |frame_surface| cam.releaseFrame(frame_surface); + const frame, _ = cam.acquireFrame(); + if (frame) |frame_surface| cam.releaseFrame(frame_surface); } } } diff --git a/src/events.zig b/src/events.zig index 6f0f69a..7433dca 100644 --- a/src/events.zig +++ b/src/events.zig @@ -164,8 +164,8 @@ pub const Group = enum { event_type: Type, ) bool { const raw: c.SDL_EventType = @intFromEnum(event_type); - const minmax = self.minMax(); - return raw >= minmax.min and raw <= minmax.max; + const min, const max = self.minMax(); + return raw >= min and raw <= max; } /// Create an iterator for every type in the group. @@ -184,10 +184,10 @@ pub const Group = enum { pub fn iterator( self: Group, ) Iterator { - const minmax = self.minMax(); + const min, const max = self.minMax(); return Iterator{ - .curr = minmax.min, - .max = minmax.max, + .curr = min, + .max = max, }; } @@ -206,27 +206,27 @@ pub const Group = enum { /// Provided by zig-sdl3. pub fn minMax( self: Group, - ) struct { min: c.SDL_EventType, max: c.SDL_EventType } { + ) struct { c.SDL_EventType, c.SDL_EventType } { return switch (self) { - .all => .{ .min = 0, .max = std.math.maxInt(c.SDL_EventType) }, - .application => .{ .min = c.SDL_EVENT_QUIT, .max = c.SDL_EVENT_SYSTEM_THEME_CHANGED }, - .display => .{ .min = c.SDL_EVENT_DISPLAY_FIRST, .max = c.SDL_EVENT_DISPLAY_LAST }, - .window => .{ .min = c.SDL_EVENT_WINDOW_FIRST, .max = c.SDL_EVENT_WINDOW_LAST }, - .keyboard => .{ .min = c.SDL_EVENT_KEY_DOWN, .max = c.SDL_EVENT_TEXT_EDITING_CANDIDATES }, - .mouse => .{ .min = c.SDL_EVENT_MOUSE_MOTION, .max = c.SDL_EVENT_MOUSE_REMOVED }, - .joystick => .{ .min = c.SDL_EVENT_JOYSTICK_AXIS_MOTION, .max = c.SDL_EVENT_JOYSTICK_UPDATE_COMPLETE }, - .gamepad => .{ .min = c.SDL_EVENT_GAMEPAD_AXIS_MOTION, .max = c.SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED }, - .touch => .{ .min = c.SDL_EVENT_FINGER_DOWN, .max = c.SDL_EVENT_FINGER_CANCELED }, - .clipboard => .{ .min = c.SDL_EVENT_CLIPBOARD_UPDATE, .max = c.SDL_EVENT_CLIPBOARD_UPDATE }, - .drag_and_drop => .{ .min = c.SDL_EVENT_DROP_FILE, .max = c.SDL_EVENT_DROP_POSITION }, - .audio => .{ .min = c.SDL_EVENT_AUDIO_DEVICE_ADDED, .max = c.SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED }, - .sensor => .{ .min = c.SDL_EVENT_SENSOR_UPDATE, .max = c.SDL_EVENT_SENSOR_UPDATE }, - .pen => .{ .min = c.SDL_EVENT_PEN_PROXIMITY_IN, .max = c.SDL_EVENT_PEN_AXIS }, - .camera => .{ .min = c.SDL_EVENT_CAMERA_DEVICE_ADDED, .max = c.SDL_EVENT_CAMERA_DEVICE_DENIED }, - .render => .{ .min = c.SDL_EVENT_RENDER_TARGETS_RESET, .max = c.SDL_EVENT_RENDER_DEVICE_LOST }, - .reserved => .{ .min = c.SDL_EVENT_PRIVATE0, .max = c.SDL_EVENT_PRIVATE3 }, - .internal => .{ .min = c.SDL_EVENT_POLL_SENTINEL, .max = c.SDL_EVENT_POLL_SENTINEL }, - .user => .{ .min = c.SDL_EVENT_USER, .max = c.SDL_EVENT_LAST }, + .all => .{ 0, std.math.maxInt(c.SDL_EventType) }, + .application => .{ c.SDL_EVENT_QUIT, c.SDL_EVENT_SYSTEM_THEME_CHANGED }, + .display => .{ c.SDL_EVENT_DISPLAY_FIRST, c.SDL_EVENT_DISPLAY_LAST }, + .window => .{ c.SDL_EVENT_WINDOW_FIRST, c.SDL_EVENT_WINDOW_LAST }, + .keyboard => .{ c.SDL_EVENT_KEY_DOWN, c.SDL_EVENT_TEXT_EDITING_CANDIDATES }, + .mouse => .{ c.SDL_EVENT_MOUSE_MOTION, c.SDL_EVENT_MOUSE_REMOVED }, + .joystick => .{ c.SDL_EVENT_JOYSTICK_AXIS_MOTION, c.SDL_EVENT_JOYSTICK_UPDATE_COMPLETE }, + .gamepad => .{ c.SDL_EVENT_GAMEPAD_AXIS_MOTION, c.SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED }, + .touch => .{ c.SDL_EVENT_FINGER_DOWN, c.SDL_EVENT_FINGER_CANCELED }, + .clipboard => .{ c.SDL_EVENT_CLIPBOARD_UPDATE, c.SDL_EVENT_CLIPBOARD_UPDATE }, + .drag_and_drop => .{ c.SDL_EVENT_DROP_FILE, c.SDL_EVENT_DROP_POSITION }, + .audio => .{ c.SDL_EVENT_AUDIO_DEVICE_ADDED, c.SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED }, + .sensor => .{ c.SDL_EVENT_SENSOR_UPDATE, c.SDL_EVENT_SENSOR_UPDATE }, + .pen => .{ c.SDL_EVENT_PEN_PROXIMITY_IN, c.SDL_EVENT_PEN_AXIS }, + .camera => .{ c.SDL_EVENT_CAMERA_DEVICE_ADDED, c.SDL_EVENT_CAMERA_DEVICE_DENIED }, + .render => .{ c.SDL_EVENT_RENDER_TARGETS_RESET, c.SDL_EVENT_RENDER_DEVICE_LOST }, + .reserved => .{ c.SDL_EVENT_PRIVATE0, c.SDL_EVENT_PRIVATE3 }, + .internal => .{ c.SDL_EVENT_POLL_SENTINEL, c.SDL_EVENT_POLL_SENTINEL }, + .user => .{ c.SDL_EVENT_USER, c.SDL_EVENT_LAST }, }; } }; @@ -2831,7 +2831,7 @@ pub fn addWatch( const Cb = struct { pub fn run(user_data_c: ?*anyopaque, event_c: [*c]c.SDL_Event) callconv(.c) bool { var event = Event.fromSdl(event_c.*); - const ret = event_filter(@alignCast(@ptrCast(user_data_c)), &event); + const ret = event_filter(@ptrCast(@alignCast(user_data_c)), &event); event_c.* = event.toSdl(); return ret; } @@ -2900,7 +2900,7 @@ pub fn filter( const Cb = struct { pub fn run(user_data_c: ?*anyopaque, event_c: [*c]c.SDL_Event) callconv(.c) bool { var event = Event.fromSdl(event_c.*); - const ret = event_filter(@alignCast(@ptrCast(user_data_c)), &event); + const ret = event_filter(@ptrCast(@alignCast(user_data_c)), &event); event_c.* = event.toSdl(); return ret; } @@ -2958,8 +2958,8 @@ pub fn flush( pub fn flushGroup( group: Group, ) void { - const minmax = group.minMax(); - c.SDL_FlushEvents(minmax.min, minmax.max); + const min, const max = group.minMax(); + c.SDL_FlushEvents(min, max); } /// Query the current event filter. @@ -2975,13 +2975,13 @@ pub fn flushGroup( /// It is safe to call this function from any thread. /// /// This function is available since SDL 3.2.0. -pub fn getFilter() ?struct { event_filter: FilterC, user_data: ?*anyopaque } { +pub fn getFilter() ?struct { FilterC, ?*anyopaque } { var event_filter: c.SDL_FunctionPointer = undefined; var user_data: ?*anyopaque = undefined; const ret = c.SDL_GetEventFilter(&event_filter, &user_data); if (!ret) return null; - return .{ .event_filter = @ptrCast(event_filter), .user_data = user_data }; + return .{ @ptrCast(event_filter), user_data }; } /// Check for the existence of a certain event type in the event queue. @@ -3022,8 +3022,8 @@ pub fn has( pub fn hasGroup( group: Group, ) bool { - const minmax = group.minMax(); - return c.SDL_HasEvents(minmax.min, minmax.max); + const min, const max = group.minMax(); + return c.SDL_HasEvents(min, max); } /// Check the event queue for messages and optionally return them. @@ -3050,9 +3050,9 @@ pub fn peep( action: Action, group: Group, ) !usize { - const minmax = group.minMax(); + const min, const max = group.minMax(); const raw: [*]c.SDL_Event = @ptrCast(events.ptr); // Hacky! We ensure in unit tests our enum is the same size so we can do this, then convert in-place. - const ret = c.SDL_PeepEvents(raw, @intCast(events.len), @intFromEnum(action), minmax.min, minmax.max); + const ret = c.SDL_PeepEvents(raw, @intCast(events.len), @intFromEnum(action), min, max); for (0..@intCast(ret)) |ind| { _ = Event.fromSdlInPlace(&raw[ind]); } @@ -3083,8 +3083,8 @@ pub fn peepSize( action: Action, group: Group, ) !usize { - const minmax = group.minMax(); - const ret = c.SDL_PeepEvents(null, @intCast(num_events), @intFromEnum(action), minmax.min, minmax.max); + const min, const max = group.minMax(); + const ret = c.SDL_PeepEvents(null, @intCast(num_events), @intFromEnum(action), min, max); return @intCast(try errors.wrapCall(c_int, ret, -1)); } @@ -3276,7 +3276,7 @@ pub fn setFilter( const Cb = struct { pub fn run(user_data_c: ?*anyopaque, event_c: [*c]c.SDL_Event) callconv(.c) bool { var event = Event.fromSdl(event_c.*); - const ret = event_filter(@alignCast(@ptrCast(user_data_c)), &event); + const ret = event_filter(@ptrCast(@alignCast(user_data_c)), &event); event_c.* = event.toSdl(); return ret; } @@ -3422,7 +3422,7 @@ test "Events" { filter(void, dummyFilter, null); const curr_filter = setFilter(void, dummyFilter, null); - try std.testing.expectEqual(@intFromPtr(curr_filter), @intFromPtr(getFilter().?.event_filter)); + try std.testing.expectEqual(@intFromPtr(curr_filter), @intFromPtr(getFilter().?[0])); const watch = try addWatch(void, dummyFilter, null); removeWatch(watch, null); diff --git a/src/gamepad.zig b/src/gamepad.zig index a4fbdb5..307f7b7 100644 --- a/src/gamepad.zig +++ b/src/gamepad.zig @@ -831,13 +831,13 @@ pub const Gamepad = struct { /// This function is available since SDL 3.2.0. pub fn getPowerInfo( self: Gamepad, - ) !struct { state: power.PowerState, percent: ?u7 } { + ) !struct { power.PowerState, ?u7 } { var percent: c_int = undefined; const ret = c.SDL_GetGamepadPowerInfo( self.value, &percent, ); - return .{ .state = @enumFromInt(try errors.wrapCall(c_int, ret, c.SDL_POWERSTATE_ERROR)), .percent = if (percent == -1) null else @intCast(percent) }; + return .{ @enumFromInt(try errors.wrapCall(c_int, ret, c.SDL_POWERSTATE_ERROR)), if (percent == -1) null else @intCast(percent) }; } /// Get the USB product ID of an opened gamepad, if available. diff --git a/src/gpu.zig b/src/gpu.zig index 63d63c3..b1924c3 100644 --- a/src/gpu.zig +++ b/src/gpu.zig @@ -594,7 +594,7 @@ pub const CommandBuffer = packed struct { /// * `window`: A window that has been claimed. /// /// ## Return Value - /// Returns the swapchain texture along with its width and height. + /// Returns the swapchain texture along with its width and height in that order. /// /// ## Remarks /// When a swapchain texture is acquired on a command buffer, it will automatically be submitted for presentation when the command buffer is submitted. @@ -618,15 +618,15 @@ pub const CommandBuffer = packed struct { pub fn acquireSwapchainTexture( self: CommandBuffer, window: video.Window, - ) !struct { texture: ?Texture, width: u32, height: u32 } { + ) !struct { ?Texture, u32, u32 } { var width: u32 = undefined; var height: u32 = undefined; var texture: ?*c.SDL_GPUTexture = undefined; try errors.wrapCallBool(c.SDL_AcquireGPUSwapchainTexture(self.value, window.value, &texture, &width, &height)); return .{ - .texture = if (texture) |val| .{ .value = val } else null, - .width = width, - .height = height, + if (texture) |val| .{ .value = val } else null, + width, + height, }; } @@ -994,7 +994,7 @@ pub const CommandBuffer = packed struct { /// * `self`: A command buffer. /// /// ## Return Value - /// Returns the swapchain texture along with its width and height. + /// Returns the swapchain texture along with its width and height in that order. /// /// ## Remarks /// When a swapchain texture is acquired on a command buffer, it will automatically be submitted for presentation when the command buffer is submitted. @@ -1017,15 +1017,15 @@ pub const CommandBuffer = packed struct { pub fn waitAndAcquireSwapchainTexture( self: CommandBuffer, window: video.Window, - ) !struct { texture: ?Texture, width: u32, height: u32 } { + ) !struct { ?Texture, u32, u32 } { var width: u32 = undefined; var height: u32 = undefined; var texture: ?*c.SDL_GPUTexture = undefined; try errors.wrapCallBool(c.SDL_WaitAndAcquireGPUSwapchainTexture(self.value, window.value, &texture, &width, &height)); return .{ - .texture = if (texture) |val| .{ .value = val } else null, - .width = width, - .height = height, + if (texture) |val| .{ .value = val } else null, + width, + height, }; } }; diff --git a/src/image.zig b/src/image.zig index 5b2e618..8d8ce17 100644 --- a/src/image.zig +++ b/src/image.zig @@ -41,19 +41,19 @@ pub const Animation = struct { /// * `index`: The index of the frame. /// /// ## Return Value - /// Returns the animation frame surface and delay, or `null` if out of bounds. + /// Returns the animation frame surface and delay in that order, or `null` if out of bounds. /// /// ## Version /// This function is provided by zig-sdl3. pub fn getFrame( self: Animation, index: usize, - ) ?struct { frame: surface.Surface, delay: usize } { + ) ?struct { surface.Surface, usize } { if (index >= self.getNumFrames()) return null; return .{ - .frame = .{ .value = self.value.frames[index] }, - .delay = @intCast(self.value.delays[index]), + .{ .value = self.value.frames[index] }, + @intCast(self.value.delays[index]), }; } diff --git a/src/joystick.zig b/src/joystick.zig index 9d60ef5..ab39535 100644 --- a/src/joystick.zig +++ b/src/joystick.zig @@ -582,7 +582,7 @@ pub const Joystick = struct { /// * `index`: The ball index to query; ball indices start at index `0`. /// /// ## Return Value - /// Returns the difference in x and y position since the last poll. + /// Returns the difference in x and y position since the last poll in that order. /// /// ## Remarks /// Trackballs can only return relative motion since the last call to this, these motion deltas are returned. @@ -594,12 +594,12 @@ pub const Joystick = struct { pub fn getBall( self: Joystick, index: usize, - ) !struct { dx: isize, dy: isize } { + ) !struct { isize, isize } { var dx: c_int = undefined; var dy: c_int = undefined; const ret = c.SDL_GetJoystickBall(self.value, @intCast(index), &dx, &dy); try errors.wrapCallBool(ret); - return .{ .dx = @intCast(dx), .dy = @intCast(dy) }; + return .{ @intCast(dx), @intCast(dy) }; } /// Get the current state of a button on a joystick. @@ -890,13 +890,13 @@ pub const Joystick = struct { /// This function is available since SDL 3.2.0. pub fn getPowerInfo( self: Joystick, - ) !struct { state: power.PowerState, percent: ?u7 } { + ) !struct { power.PowerState, ?u7 } { var percent: c_int = undefined; const ret = c.SDL_GetJoystickPowerInfo( self.value, &percent, ); - return .{ .state = @enumFromInt(try errors.wrapCall(c_int, ret, c.SDL_POWERSTATE_ERROR)), .percent = if (percent == -1) null else @intCast(percent) }; + return .{ @enumFromInt(try errors.wrapCall(c_int, ret, c.SDL_POWERSTATE_ERROR)), if (percent == -1) null else @intCast(percent) }; } /// Get the USB product ID of an opened joystick, if available. @@ -1473,32 +1473,32 @@ pub fn VirtualJoystickDescription(comptime UserData: type) type { pub fn toSdl(self: VirtualJoystickDescription(UserData)) c.SDL_VirtualJoystickDesc { const Cb = struct { fn update(user_data_c: ?*anyopaque) callconv(.c) void { - self.update.?(@alignCast(@ptrCast(user_data_c))); + self.update.?(@ptrCast(@alignCast(user_data_c))); } fn set_player_index(user_data_c: ?*anyopaque, player_index: c_int) callconv(.c) void { - self.set_player_index.?(@alignCast(@ptrCast(user_data_c)), @intCast(player_index)); + self.set_player_index.?(@ptrCast(@alignCast(user_data_c)), @intCast(player_index)); } fn rumble(user_data_c: ?*anyopaque, low_frequency_rumble: u16, high_frequency_rumble: u16) callconv(.c) bool { - return self.rumble.?(@alignCast(@ptrCast(user_data_c)), low_frequency_rumble, high_frequency_rumble); + return self.rumble.?(@ptrCast(@alignCast(user_data_c)), low_frequency_rumble, high_frequency_rumble); } fn rumble_triggers(user_data_c: ?*anyopaque, left_rumble: u16, right_rumble: u16) callconv(.c) bool { - self.rumble_triggers.?(@alignCast(@ptrCast(user_data_c)), left_rumble, right_rumble) catch return false; + self.rumble_triggers.?(@ptrCast(@alignCast(user_data_c)), left_rumble, right_rumble) catch return false; return true; } fn set_led(user_data_c: ?*anyopaque, red: u8, green: u8, blue: u8) callconv(.c) bool { - self.set_led.?(@alignCast(@ptrCast(user_data_c)), red, green, blue) catch return false; + self.set_led.?(@ptrCast(@alignCast(user_data_c)), red, green, blue) catch return false; return true; } fn send_effect(user_data_c: ?*anyopaque, data: ?*const anyopaque, size: c_int) callconv(.c) bool { - self.send_effect.?(@alignCast(@ptrCast(user_data_c)), @as([*]const u8, @alignCast(@ptrCast(data)))[0..@intCast(size)]) catch return false; + self.send_effect.?(@ptrCast(@alignCast(user_data_c)), @as([*]const u8, @ptrCast(@alignCast(data)))[0..@intCast(size)]) catch return false; return true; } fn set_sensors_enabled(user_data_c: ?*anyopaque, enabled: bool) callconv(.c) bool { - self.set_sensors_enabled.?(@alignCast(@ptrCast(user_data_c)), enabled) catch return false; + self.set_sensors_enabled.?(@ptrCast(@alignCast(user_data_c)), enabled) catch return false; return true; } fn cleanup(user_data_c: ?*anyopaque) callconv(.c) void { - self.cleanup.?(@alignCast(@ptrCast(user_data_c))); + self.cleanup.?(@ptrCast(@alignCast(user_data_c))); } }; return .{ diff --git a/src/keyboard.zig b/src/keyboard.zig index 1936596..4ace6c9 100644 --- a/src/keyboard.zig +++ b/src/keyboard.zig @@ -311,7 +311,7 @@ pub fn getModState() keycode.KeyModifier { /// /// ## Return Value /// Get the scancode corresponding to the given key code according to the current keyboard layout. -/// The `key_mod` is the first one that matches. +/// The key modifier is the first one that matches. /// /// ## Remarks /// Note that there may be multiple scancode+modifier states that can generate this keycode, this will just return the first one found. @@ -323,7 +323,7 @@ pub fn getModState() keycode.KeyModifier { /// This function is available since SDL 3.2.0. pub fn getScancodeFromKey( key: keycode.Keycode, -) ?struct { code: ?scancode.Scancode, key_mod: keycode.KeyModifier } { +) ?struct { ?scancode.Scancode, keycode.KeyModifier } { var key_mod: c.SDL_Keymod = undefined; const ret = c.SDL_GetScancodeFromKey( key.toSdl(), @@ -331,7 +331,7 @@ pub fn getScancodeFromKey( ); if (ret == c.SDL_SCANCODE_UNKNOWN) return null; - return .{ .code = scancode.Scancode.fromSdl(@intCast(ret)), .key_mod = keycode.KeyModifier.fromSdl(key_mod) }; + return .{ scancode.Scancode.fromSdl(@intCast(ret)), keycode.KeyModifier.fromSdl(key_mod) }; } /// Get a scancode from a human-readable name. @@ -438,7 +438,7 @@ pub fn getState() []const bool { /// This function is available since SDL 3.2.0. pub fn getTextInputArea( window: video.Window, -) !struct { input_area: rect.IRect, cursor_offset: i32 } { +) !struct { rect.IRect, i32 } { var input_area: c.SDL_Rect = undefined; var cursor_offset: c_int = undefined; const ret = c.SDL_GetTextInputArea( @@ -447,7 +447,7 @@ pub fn getTextInputArea( &cursor_offset, ); try errors.wrapCallBool(ret); - return .{ .input_area = rect.IRect.fromSdl(input_area), .cursor_offset = @intCast(cursor_offset) }; + return .{ rect.IRect.fromSdl(input_area), @intCast(cursor_offset) }; } /// Return whether a keyboard is currently connected. diff --git a/src/log.zig b/src/log.zig index 381e07c..09364ee 100644 --- a/src/log.zig +++ b/src/log.zig @@ -414,22 +414,22 @@ pub fn getDefaultLogOutputFunction() LogOutputFunctionC { /// Get the current log output function. /// /// ## Return Value -/// * `callback`: A `log.LogOutputFunction` filled in with the current log `callback`. -/// * `user_data`: A pointer filled in with the pointer that is passed to `callback`. +/// * `[0]`: A `log.LogOutputFunction` filled in with the current log `callback`. +/// * `[1]`: A pointer filled in with the pointer that is passed to `callback`. /// /// ## Thread Safety /// It is safe to call this function from any thread. /// /// ## Version /// This function is available since SDL 3.2.0. -pub fn getLogOutputFunction() struct { callback: LogOutputFunctionC, user_data: ?*anyopaque } { +pub fn getLogOutputFunction() struct { LogOutputFunctionC, ?*anyopaque } { var callback: c.SDL_LogOutputFunction = undefined; var user_data: ?*anyopaque = undefined; c.SDL_GetLogOutputFunction( &callback, &user_data, ); - return .{ .callback = callback.?, .user_data = user_data }; + return .{ callback.?, user_data }; } /// Log a message with `log.Category.application` and `log.Priority.info`. @@ -566,8 +566,8 @@ fn testGetLastMessage(data: TestLogCallbackData) []const u8 { test "Log" { std.testing.refAllDeclsRecursive(@This()); - const backup = getLogOutputFunction(); - try std.testing.expectEqual(getDefaultLogOutputFunction(), backup.callback); + const backup_callback, const backup_user_data = getLogOutputFunction(); + try std.testing.expectEqual(getDefaultLogOutputFunction(), backup_callback); var log_arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer log_arena.deinit(); @@ -640,5 +640,5 @@ test "Log" { resetAllPriorities(); try std.testing.expectEqual(.info, Category.application.getPriority()); - setLogOutputFunction(anyopaque, null, backup.user_data); + setLogOutputFunction(anyopaque, null, backup_user_data); } diff --git a/src/mouse.zig b/src/mouse.zig index 436da7b..01b78b7 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -469,7 +469,7 @@ pub fn getFocus() ?video.Window { /// Query the platform for the asynchronous mouse button state and the desktop-relative platform-cursor position. /// /// ## Return Value -/// Returns the mouse button state, as well as the x and y position from the desktop's top-left corner. +/// Returns the mouse button state, as well as the x and y position from the desktop's top-left corner in that order. /// /// ## Remarks /// This function immediately queries the platform for the most recent asynchronous state, @@ -487,14 +487,14 @@ pub fn getFocus() ?video.Window { /// /// ## Version /// This function is available since SDL 3.2.0. -pub fn getGlobalState() struct { flags: ButtonFlags, x: f32, y: f32 } { +pub fn getGlobalState() struct { ButtonFlags, f32, f32 } { var x: f32 = undefined; var y: f32 = undefined; const flags = c.SDL_GetGlobalMouseState(&x, &y); return .{ - .flags = ButtonFlags.fromSdl(flags), - .x = x, - .y = y, + ButtonFlags.fromSdl(flags), + x, + y, }; } @@ -523,7 +523,7 @@ pub fn getMice() ![]Id { /// Query SDL's cache for the synchronous mouse button state and accumulated mouse delta since last call. /// /// ## Return Value -/// Returns the mouse button state, as well as the x and y delta accumulated from the last call. +/// Returns the mouse button state, as well as the x and y delta accumulated from the last call in that order. /// /// ## Remarks /// This function returns the cached synchronous state as SDL understands it from the last pump of the event queue. @@ -542,21 +542,21 @@ pub fn getMice() ![]Id { /// /// ## Version /// This function is available since SDL 3.2.0. -pub fn getRelativeState() struct { flags: ButtonFlags, x: f32, y: f32 } { +pub fn getRelativeState() struct { ButtonFlags, f32, f32 } { var x: f32 = undefined; var y: f32 = undefined; const flags = c.SDL_GetRelativeMouseState(&x, &y); return .{ - .flags = ButtonFlags.fromSdl(flags), - .x = x, - .y = y, + ButtonFlags.fromSdl(flags), + x, + y, }; } /// Query SDL's cache for the synchronous mouse button state and the window-relative SDL-cursor position. /// /// ## Return Value -/// Returns the mouse button state, as well as the x and y position from the desktop's top-left corner. +/// Returns the mouse button state, as well as the x and y position from the desktop's top-left corner in that order. /// /// ## Remarks /// This function returns the cached synchronous state as SDL understands it from the last pump of the event queue. @@ -571,14 +571,14 @@ pub fn getRelativeState() struct { flags: ButtonFlags, x: f32, y: f32 } { /// /// ## Version /// This function is available since SDL 3.2.0. -pub fn getState() struct { flags: ButtonFlags, x: f32, y: f32 } { +pub fn getState() struct { ButtonFlags, f32, f32 } { var x: f32 = undefined; var y: f32 = undefined; const flags = c.SDL_GetMouseState(&x, &y); return .{ - .flags = ButtonFlags.fromSdl(flags), - .x = x, - .y = y, + ButtonFlags.fromSdl(flags), + x, + y, }; } diff --git a/src/process.zig b/src/process.zig index 8ed041c..595fdf4 100644 --- a/src/process.zig +++ b/src/process.zig @@ -79,7 +79,7 @@ pub const Process = packed struct { /// Convert to properties. pub fn toProperties(self: CreateProperties) !properties.Group { const ret = try properties.Group.init(); - try ret.set(c.SDL_PROP_PROCESS_CREATE_ARGS_POINTER, .{ .pointer = @constCast(@ptrCast(self.args.ptr)) }); + try ret.set(c.SDL_PROP_PROCESS_CREATE_ARGS_POINTER, .{ .pointer = @ptrCast(@constCast(self.args.ptr)) }); if (self.environment) |val| try ret.set(c.SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER, .{ .pointer = val.value }); if (self.stdin) |val| @@ -122,9 +122,9 @@ pub const Process = packed struct { pub fn fromSdl(value: properties.Group) Properties { return .{ .pid = if (value.get(c.SDL_PROP_PROCESS_PID_NUMBER)) |val| val.number else null, - .stdin = if (value.get(c.SDL_PROP_PROCESS_STDIN_POINTER)) |val| @alignCast(@ptrCast(val.pointer)) else null, - .stdout = if (value.get(c.SDL_PROP_PROCESS_STDOUT_POINTER)) |val| @alignCast(@ptrCast(val.pointer)) else null, - .stderr = if (value.get(c.SDL_PROP_PROCESS_STDERR_POINTER)) |val| @alignCast(@ptrCast(val.pointer)) else null, + .stdin = if (value.get(c.SDL_PROP_PROCESS_STDIN_POINTER)) |val| @ptrCast(@alignCast(val.pointer)) else null, + .stdout = if (value.get(c.SDL_PROP_PROCESS_STDOUT_POINTER)) |val| @ptrCast(@alignCast(val.pointer)) else null, + .stderr = if (value.get(c.SDL_PROP_PROCESS_STDERR_POINTER)) |val| @ptrCast(@alignCast(val.pointer)) else null, .background = if (value.get(c.SDL_PROP_PROCESS_BACKGROUND_BOOLEAN)) |val| val.boolean else null, }; } @@ -326,13 +326,13 @@ pub const Process = packed struct { /// This function is available since SDL 3.2.0. pub fn read( self: Process, - ) !struct { data: []u8, exit_code: c_int } { + ) !struct { []u8, c_int } { var size: usize = undefined; var exit_code: c_int = undefined; const ret = c.SDL_ReadProcess(self.value, &size, &exit_code); return .{ - .data = @as([*]u8, @alignCast(@ptrCast(try errors.wrapCallNull(*anyopaque, ret))))[0..@intCast(size)], - .exit_code = exit_code, + @as([*]u8, @ptrCast(@alignCast(try errors.wrapCallNull(*anyopaque, ret))))[0..@intCast(size)], + exit_code, }; } diff --git a/src/render.zig b/src/render.zig index 9a27bce..857887e 100644 --- a/src/render.zig +++ b/src/render.zig @@ -483,6 +483,7 @@ pub const Renderer = struct { /// /// ## Return Value /// The current output size in pixels of a rendering context. + /// Width and height are provided in that order. /// /// ## Remarks /// If a rendering target is active, this will return the size of the rendering target in pixels, otherwise return the value of `render.Renderer.getOutputSize()`. @@ -496,7 +497,7 @@ pub const Renderer = struct { /// This function is available since SDL 3.2.0. pub fn getCurrentOutputSize( self: Renderer, - ) !struct { width: usize, height: usize } { + ) !struct { usize, usize } { var w: c_int = undefined; var h: c_int = undefined; const ret = c.SDL_GetCurrentRenderOutputSize( @@ -505,7 +506,7 @@ pub const Renderer = struct { &h, ); try errors.wrapCallBool(ret); - return .{ .width = @intCast(w), .height = @intCast(h) }; + return .{ @intCast(w), @intCast(h) }; } // getDefaultTextureScalMode() is in SDL 3.4.0. @@ -603,7 +604,7 @@ pub const Renderer = struct { /// * `self`: The rendering context. /// /// ## Return Value - /// The logical presentation output size along with the presentation mode used. + /// The width and height with the logical presentation output size along with the presentation mode used in that order. /// /// ## Remarks /// This function gets the width and height of the logical rendering output, or the output size in pixels if a logical resolution is not enabled. @@ -618,7 +619,7 @@ pub const Renderer = struct { /// This function is available since SDL 3.2.0. pub fn getLogicalPresentation( self: Renderer, - ) !struct { width: usize, height: usize, presentation_mode: ?LogicalPresentation } { + ) !struct { usize, usize, ?LogicalPresentation } { var w: c_int = undefined; var h: c_int = undefined; var presentation_mode: c.SDL_RendererLogicalPresentation = undefined; @@ -629,7 +630,7 @@ pub const Renderer = struct { &presentation_mode, ); try errors.wrapCallBool(ret); - return .{ .width = @intCast(w), .height = @intCast(h), .presentation_mode = LogicalPresentation.fromSdl(presentation_mode) }; + return .{ @intCast(w), @intCast(h), LogicalPresentation.fromSdl(presentation_mode) }; } /// Get the final presentation rectangle for rendering. @@ -742,6 +743,7 @@ pub const Renderer = struct { /// /// ## Return Value /// The output size in pixels. + /// The width and height are provided in that order. /// /// ## Remarks /// This returns the true output size in pixels, ignoring any render targets or logical size and presentation. @@ -755,7 +757,7 @@ pub const Renderer = struct { /// This function is available since SDL 3.2.0. pub fn getOutputSize( self: Renderer, - ) !struct { width: usize, height: usize } { + ) !struct { usize, usize } { var w: c_int = undefined; var h: c_int = undefined; const ret = c.SDL_GetRenderOutputSize( @@ -764,7 +766,7 @@ pub const Renderer = struct { &h, ); try errors.wrapCallBool(ret); - return .{ .width = @intCast(w), .height = @intCast(h) }; + return .{ @intCast(w), @intCast(h) }; } /// Get the properties associated with a renderer. @@ -825,7 +827,7 @@ pub const Renderer = struct { /// * `self`: The rendering context. /// /// ## Return Value - /// The scaling factors. + /// The scaling factors for x and y in that order. /// /// ## Remarks /// Each render target has its own scale. @@ -838,7 +840,7 @@ pub const Renderer = struct { /// This function is available since SDL 3.2.0. pub fn getScale( self: Renderer, - ) !struct { x: f32, y: f32 } { + ) !struct { f32, f32 } { var x: f32 = undefined; var y: f32 = undefined; const ret = c.SDL_GetRenderScale( @@ -847,7 +849,7 @@ pub const Renderer = struct { &y, ); try errors.wrapCallBool(ret); - return .{ .x = x, .y = y }; + return .{ x, y }; } /// Get the current render target. @@ -1067,7 +1069,7 @@ pub const Renderer = struct { width: usize, height: usize, window_flags: video.Window.Flags, - ) !struct { window: video.Window, renderer: Renderer } { + ) !struct { video.Window, Renderer } { var window: ?*c.SDL_Window = undefined; var renderer: ?*c.SDL_Renderer = undefined; const ret = c.SDL_CreateWindowAndRenderer( @@ -1079,7 +1081,7 @@ pub const Renderer = struct { &renderer, ); try errors.wrapCallBool(ret); - return .{ .window = .{ .value = window.? }, .renderer = .{ .value = renderer.? } }; + return .{ .{ .value = window.? }, .{ .value = renderer.? } }; } /// Update the screen with any rendering performed since the previous call. @@ -2693,7 +2695,7 @@ pub const Texture = struct { /// * `self`: The texture to query. /// /// ## Return Value - /// The width and height of the texture in pixels. + /// The width and height of the texture in pixels in that order. /// /// ## Thread Safety /// This function should only be called on the main thread. @@ -2702,7 +2704,7 @@ pub const Texture = struct { /// This function is available since SDL 3.2.0. pub fn getSize( self: Texture, - ) !struct { width: f32, height: f32 } { + ) !struct { f32, f32 } { var w: f32 = undefined; var h: f32 = undefined; const ret = c.SDL_GetTextureSize( @@ -2711,7 +2713,7 @@ pub const Texture = struct { &h, ); try errors.wrapCallBool(ret); - return .{ .width = w, .height = h }; + return .{ w, h }; } /// Get the width of the texture. @@ -2840,7 +2842,7 @@ pub const Texture = struct { pub fn lock( self: Texture, update_area: ?rect.IRect, - ) !struct { pixels: [*]u8, pitch: usize } { + ) !struct { [*]u8, usize } { const update_area_sdl: c.SDL_Rect = if (update_area) |val| val.toSdl() else undefined; var data: ?*anyopaque = undefined; var pitch: c_int = undefined; @@ -2851,7 +2853,7 @@ pub const Texture = struct { &pitch, ); try errors.wrapCallBool(ret); - return .{ .pixels = @ptrCast(@alignCast(data)), .pitch = @intCast(pitch) }; + return .{ @ptrCast(@alignCast(data)), @intCast(pitch) }; } /// Lock a portion of the texture for write-only pixel access, and expose it as a SDL surface. diff --git a/src/time.zig b/src/time.zig index 35fe53b..102d5ca 100644 --- a/src/time.zig +++ b/src/time.zig @@ -216,7 +216,7 @@ pub const Time = struct { /// * `self`: The time to convert. /// /// ## Return Value - /// Returns the low and high 32-bit values of the Windows `FILETIME` structure. + /// Returns the low and high 32-bit values of the Windows `FILETIME` structure in that order. /// /// ## Remarks /// This function fills in the two 32-bit values of the `FILETIME` structure. @@ -225,7 +225,7 @@ pub const Time = struct { /// This function is available since SDL 3.2.0. pub fn toWindows( self: Time, - ) struct { low_date_time: u32, high_date_time: u32 } { + ) struct { u32, u32 } { var low_date_time: u32 = undefined; var high_date_time: u32 = undefined; c.SDL_TimeToWindows( @@ -233,7 +233,7 @@ pub const Time = struct { &low_date_time, &high_date_time, ); - return .{ .low_date_time = low_date_time, .high_date_time = high_date_time }; + return .{ low_date_time, high_date_time }; } }; @@ -321,7 +321,7 @@ pub fn getDaysInMonth( /// /// ## Version /// This function is available since SDL 3.2.0. -pub fn getLocalePreferences() !struct { date_format: DateFormat, time_format: TimeFormat } { +pub fn getLocalePreferences() !struct { DateFormat, TimeFormat } { var date_format: c.SDL_DateFormat = undefined; var time_format: c.SDL_TimeFormat = undefined; const ret = c.SDL_GetDateTimeLocalePreferences( @@ -329,7 +329,7 @@ pub fn getLocalePreferences() !struct { date_format: DateFormat, time_format: Ti &time_format, ); try errors.wrapCallBool(ret); - return .{ .date_format = @enumFromInt(date_format), .time_format = @enumFromInt(time_format) }; + return .{ @enumFromInt(date_format), @enumFromInt(time_format) }; } // Ensure time and date recognition works. @@ -354,7 +354,7 @@ test "Dates" { _ = try getLocalePreferences(); // Idk man idk why this is not equal, probably some weird conversion loss. - const windows_time = curr_time.toWindows(); - const conv_time = Time.fromWindows(windows_time.low_date_time, windows_time.high_date_time); + const low_date_time, const high_date_time = curr_time.toWindows(); + const conv_time = Time.fromWindows(low_date_time, high_date_time); try std.testing.expect(std.math.approxEqAbs(f64, @floatFromInt(curr_time.value), @floatFromInt(conv_time.value), 1000)); } diff --git a/src/ttf.zig b/src/ttf.zig index 9371fa5..7930bac 100644 --- a/src/ttf.zig +++ b/src/ttf.zig @@ -994,7 +994,7 @@ pub const Font = struct { /// Get font target resolutions, in dots per inch. /// /// ## Return Value - /// Returns a struct with the horizontal and vertical DPI. + /// Returns a struct with the horizontal and vertical DPI in that order. /// /// ## Thread Safety /// This function should be called on the thread that created the font. @@ -1003,7 +1003,7 @@ pub const Font = struct { /// This function is available since SDL_ttf 3.0.0. pub fn getDpi( self: Font, - ) !struct { hdpi: c_int, vdpi: c_int } { + ) !struct { c_int, c_int } { var hdpi: c_int = undefined; var vdpi: c_int = undefined; try errors.wrapCallBool(c.TTF_GetFontDPI( @@ -1011,7 +1011,7 @@ pub const Font = struct { &hdpi, &vdpi, )); - return .{ .hdpi = hdpi, .vdpi = vdpi }; + return .{ hdpi, vdpi }; } /// Set a font's current style. @@ -1674,7 +1674,7 @@ pub const Font = struct { pub fn getGlyphImage( self: Font, ch: u32, - ) !struct { image: surface.Surface, image_type: ImageType } { + ) !struct { surface.Surface, ImageType } { var image_type: c.TTF_ImageType = undefined; const surf = try errors.wrapCallNull(*c.SDL_Surface, c.TTF_GetGlyphImage( self.value, @@ -1682,8 +1682,8 @@ pub const Font = struct { &image_type, )); return .{ - .image = .{ .value = surf }, - .image_type = @enumFromInt( + .{ .value = surf }, + @enumFromInt( image_type, ), }; @@ -1709,7 +1709,7 @@ pub const Font = struct { pub fn getGlyphImageForIndex( self: Font, glyph_index: u32, - ) !struct { image: surface.Surface, image_type: ImageType } { + ) !struct { surface.Surface, ImageType } { var image_type: c.TTF_ImageType = undefined; const surf = try errors.wrapCallNull(*c.SDL_Surface, c.TTF_GetGlyphImageForIndex( self.value, @@ -1717,8 +1717,8 @@ pub const Font = struct { &image_type, )); return .{ - .image = .{ .value = surf }, - .image_type = @enumFromInt( + .{ .value = surf }, + @enumFromInt( image_type, ), }; @@ -1808,7 +1808,7 @@ pub const Font = struct { pub fn getStringSize( self: Font, text: []const u8, - ) !struct { w: c_int, h: c_int } { + ) !struct { c_int, c_int } { var w: c_int = undefined; var h: c_int = undefined; try errors.wrapCallBool(c.TTF_GetStringSize( @@ -1818,7 +1818,7 @@ pub const Font = struct { &w, &h, )); - return .{ .w = w, .h = h }; + return .{ w, h }; } /// Calculate the dimensions of a rendered string of UTF-8 text. @@ -1846,7 +1846,7 @@ pub const Font = struct { self: Font, text: []const u8, wrap_width: c_int, - ) !struct { w: c_int, h: c_int } { + ) !struct { c_int, c_int } { var w: c_int = undefined; var h: c_int = undefined; try errors.wrapCallBool(c.TTF_GetStringSizeWrapped( @@ -1882,7 +1882,7 @@ pub const Font = struct { self: Font, text: []const u8, max_width: c_int, - ) !struct { measured_width: c_int, measured_length: usize } { + ) !struct { c_int, usize } { var measured_width: c_int = undefined; var measured_length: usize = undefined; try errors.wrapCallBool(c.TTF_MeasureString( @@ -1893,7 +1893,7 @@ pub const Font = struct { &measured_width, &measured_length, )); - return .{ .measured_width = measured_width, .measured_length = measured_length }; + return .{ measured_width, measured_length }; } /// Render UTF-8 text at fast quality to a new 8-bit surface. @@ -3274,7 +3274,7 @@ pub const Text = struct { /// This function is available since SDL_ttf 3.0.0. pub fn getPosition( self: Text, - ) !struct { x: c_int, y: c_int } { + ) !struct { c_int, c_int } { var x: c_int = undefined; var y: c_int = undefined; try errors.wrapCallBool(c.TTF_GetTextPosition( @@ -3282,7 +3282,7 @@ pub const Text = struct { &x, &y, )); - return .{ .x = x, .y = y }; + return .{ x, y }; } /// Set whether wrapping is enabled on a text object. @@ -3499,7 +3499,7 @@ pub const Text = struct { /// This function is available since SDL_ttf 3.0.0. pub fn getSize( self: Text, - ) !struct { w: c_int, h: c_int } { + ) !struct { c_int, c_int } { var w: c_int = undefined; var h: c_int = undefined; try errors.wrapCallBool(c.TTF_GetTextSize( @@ -3507,7 +3507,7 @@ pub const Text = struct { &w, &h, )); - return .{ .w = w, .h = h }; + return .{ w, h }; } /// Get the substring of a text object that surrounds a text offset. diff --git a/src/video.zig b/src/video.zig index 04a48dc..b54c5ad 100644 --- a/src/video.zig +++ b/src/video.zig @@ -704,13 +704,13 @@ pub const egl = struct { ) void { const Cb = struct { pub fn platform_attrib(user_data_c: ?*anyopaque) callconv(.c) [*c]EglAttrib { - return platform_attrib_callback.?(@alignCast(@ptrCast(user_data_c))); + return platform_attrib_callback.?(@ptrCast(@alignCast(user_data_c))); } pub fn surface_attrib(user_data_c: ?*anyopaque, display_c: c.SDL_EGLDisplay, config_c: c.SDL_EGLConfig) callconv(.c) [*c]EglInt { - return surface_attrib_callback.?(@alignCast(@ptrCast(user_data_c)), display_c, config_c); + return surface_attrib_callback.?(@ptrCast(@alignCast(user_data_c)), display_c, config_c); } pub fn context_attrib(user_data_c: ?*anyopaque, display_c: c.SDL_EGLDisplay, config_c: c.SDL_EGLConfig) callconv(.c) [*c]EglInt { - return surface_attrib_callback.?(@alignCast(@ptrCast(user_data_c)), display_c, config_c); + return surface_attrib_callback.?(@ptrCast(@alignCast(user_data_c)), display_c, config_c); } }; c.SDL_EGL_SetAttributeCallbacks( @@ -1672,7 +1672,7 @@ pub const Window = packed struct { /// Convert from an SDL value. pub fn fromSdl(value: properties.Group) Properties { return .{ - .shape = if (value.get(c.SDL_PROP_WINDOW_SHAPE_POINTER)) |val| .{ .value = @alignCast(@ptrCast(val.pointer.?)) } else null, + .shape = if (value.get(c.SDL_PROP_WINDOW_SHAPE_POINTER)) |val| .{ .value = @ptrCast(@alignCast(val.pointer.?)) } else null, .hdr_enabled = if (value.get(c.SDL_PROP_WINDOW_HDR_ENABLED_BOOLEAN)) |val| val.boolean else null, .sdr_white_level = if (value.get(c.SDL_PROP_WINDOW_SDR_WHITE_LEVEL_FLOAT)) |val| val.float else null, .hdr_headroom = if (value.get(c.SDL_PROP_WINDOW_HDR_HEADROOM_FLOAT)) |val| val.float else null, @@ -1896,12 +1896,12 @@ pub const Window = packed struct { /// TODO: ADD EXAMPLE!!! pub fn initWithProperties( props: CreateProperties, - ) !struct { window: Window, properties: properties.Group } { + ) !struct { Window, properties.Group } { const group = try props.toProperties(); errdefer group.deinit(); const window = try errors.wrapCallNull(*c.SDL_Window, c.SDL_CreateWindowWithProperties(group.value)); - return .{ .window = .{ .value = window }, .properties = group }; + return .{ .{ .value = window }, group }; } /// Destroy a window. @@ -1991,7 +1991,7 @@ pub const Window = packed struct { /// This function is available since SDL 3.2.0. pub fn getAspectRatio( self: Window, - ) !struct { min_aspect: f32, max_aspect: f32 } { + ) !struct { f32, f32 } { var min_aspect: f32 = undefined; var max_aspect: f32 = undefined; const ret = c.SDL_GetWindowAspectRatio( @@ -2000,7 +2000,7 @@ pub const Window = packed struct { &max_aspect, ); try errors.wrapCallBool(ret); - return .{ .min_aspect = min_aspect, .max_aspect = max_aspect }; + return .{ min_aspect, max_aspect }; } /// Get the size of a window's borders (decorations) around the client area. @@ -2175,7 +2175,7 @@ pub const Window = packed struct { self: Window, ) ![]u8 { var size: usize = undefined; - const ret = @as([*]u8, @alignCast(@ptrCast(try errors.wrapCallNull(*anyopaque, c.SDL_GetWindowICCProfile(self.value, &size))))); + const ret = @as([*]u8, @ptrCast(@alignCast(try errors.wrapCallNull(*anyopaque, c.SDL_GetWindowICCProfile(self.value, &size))))); return ret[0..size]; } @@ -2224,7 +2224,7 @@ pub const Window = packed struct { /// * `self`: The window to query. /// /// ## Return Value - /// Returns the window's maximum size. + /// Returns the window's maximum size with width and height in that order. /// /// ## Thread Safety /// This function should only be called on the main thread. @@ -2233,12 +2233,12 @@ pub const Window = packed struct { /// This function is available since SDL 3.2.0. pub fn getMaximumSize( self: Window, - ) !struct { width: usize, height: usize } { + ) !struct { usize, usize } { var width: c_int = undefined; var height: c_int = undefined; const ret = c.SDL_GetWindowMaximumSize(self.value, &width, &height); try errors.wrapCallBool(ret); - return .{ .width = @intCast(width), .height = @intCast(height) }; + return .{ @intCast(width), @intCast(height) }; } /// Get the minimum size of a window's client area. @@ -2247,7 +2247,7 @@ pub const Window = packed struct { /// * `self`: The window to query. /// /// ## Return Value - /// Returns the window's maximum size. + /// Returns the window's maximum size, the width and height in order. /// /// ## Thread Safety /// This function should only be called on the main thread. @@ -2256,12 +2256,12 @@ pub const Window = packed struct { /// This function is available since SDL 3.2.0. pub fn getMinimumSize( self: Window, - ) !struct { width: usize, height: usize } { + ) !struct { usize, usize } { var width: c_int = undefined; var height: c_int = undefined; const ret = c.SDL_GetWindowMinimumSize(self.value, &width, &height); try errors.wrapCallBool(ret); - return .{ .width = @intCast(width), .height = @intCast(height) }; + return .{ @intCast(width), @intCast(height) }; } /// Get a window's mouse grab mode. @@ -2408,12 +2408,12 @@ pub const Window = packed struct { /// This function is available since SDL 3.2.0. pub fn getPosition( self: Window, - ) !struct { x: isize, y: isize } { + ) !struct { isize, isize } { var x: c_int = undefined; var y: c_int = undefined; const ret = c.SDL_GetWindowPosition(self.value, &x, &y); try errors.wrapCallBool(ret); - return .{ .x = @intCast(x), .y = @intCast(y) }; + return .{ @intCast(x), @intCast(y) }; } /// Get the properties associated with a window. @@ -2468,7 +2468,7 @@ pub const Window = packed struct { /// * `self`: The window to query. /// /// ## Return Value - /// Returns the size of the window's client area. + /// Returns the size of the window's client area, width and height in order. /// /// ## Remarks /// The window pixel size may differ from its window coordinate size if the window is on a high pixel density display. @@ -2481,12 +2481,12 @@ pub const Window = packed struct { /// This function is available since SDL 3.2.0. pub fn getSize( self: Window, - ) !struct { width: usize, height: usize } { + ) !struct { usize, usize } { var width: c_int = undefined; var height: c_int = undefined; const ret = c.SDL_GetWindowSize(self.value, &width, &height); try errors.wrapCallBool(ret); - return .{ .width = @intCast(width), .height = @intCast(height) }; + return .{ @intCast(width), @intCast(height) }; } /// Get the size of the window's client area in pixels. @@ -2495,7 +2495,7 @@ pub const Window = packed struct { /// * `self`: The window to query. /// /// ## Return Value - /// Returns the size of the window's client area in pixels. + /// Returns the size of the window's client area in pixels, the width and height in order. /// /// ## Remarks /// The window pixel size may differ from its window coordinate size if the window is on a high pixel density display. @@ -2508,12 +2508,12 @@ pub const Window = packed struct { /// This function is available since SDL 3.2.0. pub fn getSizeInPixels( self: Window, - ) !struct { width: usize, height: usize } { + ) !struct { usize, usize } { var width: c_int = undefined; var height: c_int = undefined; const ret = c.SDL_GetWindowSizeInPixels(self.value, &width, &height); try errors.wrapCallBool(ret); - return .{ .width = @intCast(width), .height = @intCast(height) }; + return .{ @intCast(width), @intCast(height) }; } /// Get the SDL surface associated with the window. @@ -2913,7 +2913,7 @@ pub const Window = packed struct { ) !void { const Cb = struct { pub fn run(win_c: ?*c.SDL_Window, area_c: [*c]const c.SDL_Point, user_data_c: ?*anyopaque) callconv(.c) c.SDL_HitTestResult { - return @intFromEnum(callback.?(.{ .value = win_c.? }, rect.IPoint.fromSdl(area_c), @alignCast(@ptrCast(user_data_c)))); + return @intFromEnum(callback.?(.{ .value = win_c.? }, rect.IPoint.fromSdl(area_c), @ptrCast(@alignCast(user_data_c)))); } }; return errors.wrapCallBool(c.SDL_SetWindowHitTest(self.value, if (callback != null) Cb.run else null, user_data)); diff --git a/template/src/main.zig b/template/src/main.zig index 0ed4d96..6d74e7e 100644 --- a/template/src/main.zig +++ b/template/src/main.zig @@ -64,22 +64,22 @@ pub fn init( errdefer allocator.destroy(state); // Setup initial data. - const window_renderer = try sdl3.render.Renderer.initWithWindow( + const window, const renderer = try sdl3.render.Renderer.initWithWindow( "Hello SDL3", window_width, window_height, .{}, ); - errdefer window_renderer.renderer.deinit(); - errdefer window_renderer.window.deinit(); + errdefer renderer.deinit(); + errdefer window.deinit(); var frame_capper = sdl3.extras.FramerateCapper(f32){ .mode = .{ .unlimited = {} } }; - window_renderer.renderer.setVSync(.{ .on_each_num_refresh = 1 }) catch { + renderer.setVSync(.{ .on_each_num_refresh = 1 }) catch { // We don't want to run at unlimited FPS, cap frame rate to the default FPS if vsync is not available so we don't burn CPU time. frame_capper.mode = .{ .limited = fps }; }; const tree_tex = try sdl3.image.loadTextureIo( - window_renderer.renderer, + renderer, try sdl3.io_stream.Stream.initFromConstMem(my_image), true, ); @@ -92,8 +92,8 @@ pub fn init( // Set app state. state.* = .{ .frame_capper = frame_capper, - .window = window_renderer.window, - .renderer = window_renderer.renderer, + .window = window, + .renderer = renderer, .tree_tex = tree_tex, }; app_state.* = state;