summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 23:07:39 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitbc6fe168278957ad15cf87826c8410e7358e0849 (patch)
tree7b6ec8e9f3030ba77344c24f8ce387daca287ed5
parent87e8d3dee3bd57d28c42672d35ae214bbc058b9a (diff)
downloadsketchbook-bc6fe168278957ad15cf87826c8410e7358e0849.tar.gz
sketchbook-bc6fe168278957ad15cf87826c8410e7358e0849.zip
anim: Event.key, and the talk example runs in a window
An Event says its key (abi.Event.key), which the player and the talk example each spelled out by hand; `zig build talk` shows examples/talk.zig in a window on the generic host, its state under .zig-cache, and `zig build talk-lib --watch` beside it reloads every edit in place. Co-Authored-By: Claude Fable 5.2 <[email protected]>
-rw-r--r--build.zig5
-rw-r--r--examples/talk.zig2
-rw-r--r--src/abi.zig5
-rw-r--r--src/anim/player.zig6
4 files changed, 12 insertions, 6 deletions
diff --git a/build.zig b/build.zig
index 3739bcf..cb47d8a 100644
--- a/build.zig
+++ b/build.zig
@@ -267,6 +267,11 @@ pub fn build(b: *Build) void {
talk_check.run.addArg("--define");
talk_check.run.addPrefixedDirectoryArg(b.fmt("{s}=", .{define}), talk.addExport(talk_exe, .{ .fps = 30, .frames = frames, .size = .{ 640, 360 } }).frames);
}
+ // `zig build talk` shows it in a window; `zig build talk-lib --watch`
+ // beside it reloads every edit in place.
+ const talk_lib = talk.addLibrary();
+ b.step("talk", "Run the talk example in a window (reload edits with `zig build talk-lib --watch`)").dependOn(&talk.addRun(talk_lib, .{ .state = ".zig-cache/talk.state" }).step);
+ b.step("talk-lib", "Build and install the talk example's hot-reloadable library").dependOn(&b.addInstallArtifact(talk_lib, .{}).step);
const test_talk = b.step("test-talk", "Play the talk example: steps, back, slides, its slider, a reload mid-wait and its export");
test_talk.dependOn(&talk_check.run.step);
test_step.dependOn(&talk_check.run.step);
diff --git a/examples/talk.zig b/examples/talk.zig
index f2a2d9c..2ad3d70 100644
--- a/examples/talk.zig
+++ b/examples/talk.zig
@@ -53,7 +53,7 @@ pub fn update(s: *State, in: *const sk.Input) void {
for (in.events) |e| switch (e.kind) {
// Every click is the presenter's, unless the talk takes it.
.mouse_up => ask.next = true,
- .key_down => switch (@as(sk.Key, @fromBackingInt(@intCast(@as(u8, @truncate(e.code)))))) {
+ .key_down => switch (e.key()) {
.space, .right, .page_down => ask.next = true,
.left, .page_up => ask.back = true,
.right_bracket => ask.next_slide = true,
diff --git a/src/abi.zig b/src/abi.zig
index 7177f14..af106af 100644
--- a/src/abi.zig
+++ b/src/abi.zig
@@ -114,6 +114,11 @@ pub const Event = extern struct {
/// `flags` bit for a held key's auto-repeat.
pub const repeat: u8 = 1;
+ /// The key of a `key_down` or `key_up`.
+ pub fn key(e: Event) Key {
+ return @fromBackingInt(@intCast(@as(u8, @truncate(e.code))));
+ }
+
/// For mouse and wheel events: the modifier keys held as it happened,
/// as `Key.Mod` bits. Read this rather than `Input.held`, which is the
/// state after the frame's events, and misses modifiers that come with
diff --git a/src/anim/player.zig b/src/anim/player.zig
index 3b0662d..b329714 100644
--- a/src/anim/player.zig
+++ b/src/anim/player.zig
@@ -71,7 +71,7 @@ pub fn update(s: *State, in: *const sk.Input) void {
var ask: anim.Ask = .{};
var mark: enum { none, previous, next } = .none;
for (in.events) |e| switch (e.kind) {
- .key_down => if (e.flags & sk.Event.repeat == 0 or key(e) == .left or key(e) == .right or key(e) == .comma or key(e) == .period) switch (key(e)) {
+ .key_down => if (e.flags & sk.Event.repeat == 0 or e.key() == .left or e.key() == .right or e.key() == .comma or e.key() == .period) switch (e.key()) {
.space => if (talking) {
ask.next = true;
} else {
@@ -126,10 +126,6 @@ pub fn update(s: *State, in: *const sk.Input) void {
d.update(in, ask, talk, .{});
}
-fn key(e: sk.Event) sk.Key {
- return @fromBackingInt(@intCast(@as(u8, @truncate(e.code))));
-}
-
/// The scene at the deck's `t`: a live one through the deck, with its gates.
fn shotNow(s: *const State, arena: std.mem.Allocator, in: *const sk.Input, mouse: [2]f32) !anim.Shot {
if (@hasDecl(scene, "frame")) return s.deck.shot(arena, in, mouse, scene.frame, .{});