-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.zig
43 lines (38 loc) · 1.33 KB
/
example.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const std = @import("std");
const zw = @import("zig-window");
fn handleEvent(_: ?*anyopaque, event: zw.Event) void {
switch (event) {
.Destroy => std.log.info("Window destroyed", .{}),
.FocusIn => std.log.info("Focus in", .{}),
.FocusOut => std.log.info("Focus out", .{}),
.Resize => |size| {
const width, const height = size;
std.log.info("Resize: {}, {}", .{ width, height });
},
.KeyPress => |value| std.log.info("Key pressed: {}", .{value}),
.KeyRelease => |value| std.log.info("Key released: {}", .{value}),
.MouseScrollV => |value| std.log.info("Mouse scroll vertical: {}", .{value}),
.MousePress => |value| std.log.info("{} pressed", .{value}),
.MouseRelease => |value| std.log.info("{} released", .{value}),
else => {},
}
}
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
try zw.init(gpa.allocator());
defer zw.deinit();
const window = try zw.createWindow(.{
.name = "Example window",
.width = 1920,
.height = 1080,
.event_handler = .{
.handle = null,
.handle_event_fn = @ptrCast(&handleEvent),
},
});
defer window.destroy();
while (window.isOpen()) {
zw.pollEvents();
}
}