Fix for stage-2. fn -> *const fn & fix castings

This commit is contained in:
Dendy 2022-09-26 09:08:59 +02:00
parent 9271fa1cae
commit a3b1e5171e
4 changed files with 9 additions and 10 deletions

View File

@ -13,5 +13,5 @@ pub fn init(scancode: SDL.Scancode, callback: *const anyopaque) Self {
};
}
pub fn call(self: Self, state: anytype) void {
@call(.{}, @ptrCast(fn (@TypeOf(state)) void, self.callback), .{state});
@call(.{}, @ptrCast(*const fn (@TypeOf(state)) void, self.callback), .{state});
}

View File

@ -86,7 +86,6 @@ pub fn getTab(self: Self) MenuTab {
}
pub fn tick(self: *Self) State {
if (self.state != State.main_menu) {
// If we are returnining
self.state = State.main_menu;

View File

@ -3,9 +3,9 @@ const MainMenu = @import("../MainMenu.zig");
const Self = @This();
name: []const u8,
action: fn (*MainMenu) void,
action: *const fn (*MainMenu) void,
pub fn init(name: []const u8, action: fn (*MainMenu) void) Self {
pub fn init(name: []const u8, action: *const fn (*MainMenu) void) Self {
return Self{
.name = name,
.action = action,

View File

@ -40,8 +40,8 @@ pub fn render(self: Self, main_menu: MainMenu) void {
const curr_tab = main_menu.tab_list[u_tab];
// Auxiliary variables to claculate the center of the screen
const total_spacing = (tabs.len - 1) * x_spacing;
const total_width = tabs.len * width;
const total_spacing: i32 = (tabs.len - 1) * x_spacing;
const total_width: i32 = tabs.len * width;
// Current selection vertical offset
const sel_y_offset = y_spacing * 12;
@ -51,9 +51,9 @@ pub fn render(self: Self, main_menu: MainMenu) void {
const n_sel_above = @intCast(usize, @divExact((sel_y_offset), (height + y_spacing)));
// Move it from the left to the center
const centering : i32 = @divExact((screen_width - (total_width + total_spacing)), 2);
const centering = @divExact((screen_width - (total_width + total_spacing)), 2);
const x = @intCast(i32, tab_i * (width + x_spacing) + centering);
const x = tab_i * (width + x_spacing) + centering;
// Transparency depending on tab at the middle
var alpha: u8 = 255;
@ -87,7 +87,7 @@ pub fn render(self: Self, main_menu: MainMenu) void {
{
for (range(n_sel_above)) |_, i| {
const aux_sel: i32 = - @intCast(i32, i + 1);
const aux_sel: i32 = -@intCast(i32, i + 1);
const curr_sel: usize = main_menu.getSelIdx(aux_sel);
const y = @intCast(i32, sel_y_offset + ((y_spacing + height) * (aux_sel)));
self.renderMenu(x, y, curr_tab, curr_sel, alpha, false);
@ -101,7 +101,7 @@ pub fn render(self: Self, main_menu: MainMenu) void {
self.renderer.setColor(0, 0, 0, 127);
self.renderer.fillRectangleEx(-150, 0, @divTrunc(wsize.width, 3), wsize.height, skew);
self.renderer.fillRectangleEx(screen_width - 300, 0, @divTrunc(wsize.width, 3), wsize.height, skew);
self.renderer.fillRectangleEx(@intCast(i32, screen_width) - 300, 0, @divTrunc(wsize.width, 3), wsize.height, skew);
}
fn renderMenu(self: Self, x: i32, y: i32, tab: MenuTab, sel: usize, a: u8, selected: bool) void {