Browse Source

Type C wrapper functions with zero ended slices

master
Kenneth Bruen 9 months ago
parent
commit
f94b6e20e7
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 20
      src/departure.zig
  2. 28
      src/raylib.zig

20
src/departure.zig

@ -124,7 +124,7 @@ fn draw_db1(state: *AppState) !void {
const station_name = std.fmt.allocPrintZ(allocator, "{s}", .{first.get("stop").?.object.get("name").?.string}) catch break :station_name_blk;
defer allocator.free(station_name);
rl.SetWindowTitle(station_name.ptr);
raylib.DrawRightAlignedTextEx(state.font, station_name.ptr, @floatFromInt(rl.GetScreenWidth() - 4), 4, 14, 0.8, rl.WHITE);
raylib.DrawRightAlignedTextEx(state.font, station_name, @floatFromInt(rl.GetScreenWidth() - 4), 4, 14, 0.8, rl.WHITE);
}
var with_santinel: [200]u8 = .{0} ** 200;
@ -158,7 +158,7 @@ fn draw_db1(state: *AppState) !void {
const destination = try std.fmt.allocPrintZ(allocator, "{s}", .{first.get("direction").?.string});
defer allocator.free(destination);
var next_y = y;
next_y += @intFromFloat(raylib.DrawAndMeasureTextEx(state.font, line.ptr, 16, @floatFromInt(y), 32, 1, rl.WHITE).y);
next_y += @intFromFloat(raylib.DrawAndMeasureTextEx(state.font, line, 16, @floatFromInt(y), 32, 1, rl.WHITE).y);
next_y += 8;
if (ds.platform.items.len == 0) blk: {
if (first.get("platform")) |platform_raw| {
@ -180,7 +180,7 @@ fn draw_db1(state: *AppState) !void {
if (is_changed) {
rl.DrawRectangle(rl.GetScreenWidth() - platform_width - 16 - 8, y, platform_width + 16, 40, rl.WHITE);
}
raylib.DrawRightAlignedTextEx(state.font, platform.ptr, @floatFromInt(rl.GetScreenWidth() - 16), @floatFromInt(y), 40, 1, if (is_changed) db_blue else rl.WHITE);
raylib.DrawRightAlignedTextEx(state.font, platform, @floatFromInt(rl.GetScreenWidth() - 16), @floatFromInt(y), 40, 1, if (is_changed) db_blue else rl.WHITE);
},
else => {},
}
@ -190,7 +190,7 @@ fn draw_db1(state: *AppState) !void {
const time_measure = raylib.DrawAndMeasureTextEx(
state.font,
time.ptr,
time,
16,
@floatFromInt(y),
48,
@ -209,7 +209,7 @@ fn draw_db1(state: *AppState) !void {
);
raylib.DrawTextEx(
state.font,
rt.ptr,
rt,
16 * 3 + time_measure.x,
@floatFromInt(y),
48,
@ -221,7 +221,7 @@ fn draw_db1(state: *AppState) !void {
y += @intFromFloat(raylib.DrawAndMeasureTextEx(
state.font,
destination.ptr,
destination,
16,
@floatFromInt(y),
56,
@ -368,7 +368,7 @@ fn draw_db1(state: *AppState) !void {
}
const platform = std.fmt.allocPrintZ(allocator, "{s}", .{p}) catch break :blk;
defer allocator.free(platform);
raylib.DrawRightAlignedTextEx(state.font, platform.ptr, @floatFromInt(rl.GetScreenWidth() - 16), @floatFromInt(y), @floatFromInt(font_size), 1, if (is_changed) rl.WHITE else db_blue);
raylib.DrawRightAlignedTextEx(state.font, platform, @floatFromInt(rl.GetScreenWidth() - 16), @floatFromInt(y), @floatFromInt(font_size), 1, if (is_changed) rl.WHITE else db_blue);
},
else => {},
}
@ -457,7 +457,7 @@ fn draw_ns(state: *AppState) !void {
};
const time_str = std.fmt.allocPrintZ(allocator, "{:0>2}:{:0>2}", .{ time.hour, time.minute }) catch break :blk;
defer allocator.free(time_str);
raylib.DrawTextEx(state.font, time_str.ptr, 8, y, station_fs, 1, if (cancelled) ns_fg2 else ns_fg1);
raylib.DrawTextEx(state.font, time_str, 8, y, station_fs, 1, if (cancelled) ns_fg2 else ns_fg1);
}
const direction = try std.fmt.allocPrintZ(
allocator,
@ -467,7 +467,7 @@ fn draw_ns(state: *AppState) !void {
},
);
defer allocator.free(direction);
raylib.DrawTextEx(state.font, direction.ptr, 8 + col1w + 8, y, station_fs, 1, if (cancelled) ns_fg2 else ns_fg1);
raylib.DrawTextEx(state.font, direction, 8 + col1w + 8, y, station_fs, 1, if (cancelled) ns_fg2 else ns_fg1);
// Draw platform square
const square_side = total_height - 4;
@ -487,7 +487,7 @@ fn draw_ns(state: *AppState) !void {
const text_size = rl.MeasureTextEx(state.font, platform.ptr, platform_fs, 1);
raylib.DrawTextEx(
state.font,
if (cancelled) "-" else platform.ptr,
if (cancelled) "-" else platform,
@as(f32, @floatFromInt(sw - 200)) + @divTrunc(square_side, 2) - (text_size.x / 2),
y + 2 + @divTrunc(square_side, 2) - (text_size.y / 2),
platform_fs,

28
src/raylib.zig

@ -24,32 +24,32 @@ pub fn ColorIntA(whole: u32) rl.Color {
};
}
pub fn DrawAndMeasureText(
text: [*c]const u8,
text: [:0]const u8,
pos_x: c_int,
pos_y: c_int,
font_size: c_int,
color: rl.Color,
) struct { width: c_int, height: c_int } {
rl.DrawText(text, pos_x, pos_y, font_size, color);
rl.DrawText(text.ptr, pos_x, pos_y, font_size, color);
return .{
.width = rl.MeasureText(text, font_size),
.height = 10,
.width = rl.MeasureText(text.ptr, font_size),
.height = font_size,
};
}
pub fn DrawTextEx(
font: rl.Font,
text: [*c]const u8,
text: [:0]const u8,
pos_x: f32,
pos_y: f32,
font_size: f32,
spacing: f32,
color: rl.Color,
) void {
rl.DrawTextEx(font, text, rl.Vector2{ .x = pos_x, .y = pos_y }, font_size, spacing, color);
rl.DrawTextEx(font, text.ptr, rl.Vector2{ .x = pos_x, .y = pos_y }, font_size, spacing, color);
}
pub fn DrawAndMeasureTextEx(
font: rl.Font,
text: [*c]const u8,
text: [:0]const u8,
pos_x: f32,
pos_y: f32,
font_size: f32,
@ -57,29 +57,29 @@ pub fn DrawAndMeasureTextEx(
color: rl.Color,
) rl.Vector2 {
rl.DrawTextEx(font, text, rl.Vector2{ .x = pos_x, .y = pos_y }, font_size, spacing, color);
return rl.MeasureTextEx(font, text, font_size, spacing);
return rl.MeasureTextEx(font, text.ptr, font_size, spacing);
}
pub fn DrawRightAlignedText(
text: [*c]const u8,
text: [:0]const u8,
pos_x: c_int,
pos_y: c_int,
font_size: c_int,
color: rl.Color,
) void {
const width = rl.MeasureText(text, font_size);
rl.DrawText(text, pos_x - width, pos_y, font_size, color);
const width = rl.MeasureText(text.ptr, font_size);
rl.DrawText(text.ptr, pos_x - width, pos_y, font_size, color);
}
pub fn DrawRightAlignedTextEx(
font: rl.Font,
text: [*c]const u8,
text: [:0]const u8,
pos_x: f32,
pos_y: f32,
font_size: f32,
spacing: f32,
color: rl.Color,
) void {
const width = rl.MeasureTextEx(font, text, font_size, spacing).x;
rl.DrawTextEx(font, text, .{ .x = pos_x - width, .y = pos_y }, font_size, spacing, color);
const width = rl.MeasureTextEx(font, text.ptr, font_size, spacing).x;
rl.DrawTextEx(font, text.ptr, .{ .x = pos_x - width, .y = pos_y }, font_size, spacing, color);
}
pub fn GetKeyPressed() ?c_int {
const result = rl.GetKeyPressed();

Loading…
Cancel
Save