inspector: show chained bindings

This commit is contained in:
Mitchell Hashimoto
2025-12-22 20:34:23 -08:00
parent 76c0bdf559
commit dcbb3fe56f
2 changed files with 35 additions and 7 deletions

View File

@@ -2941,8 +2941,8 @@ fn maybeHandleBinding(
// actions perform.
var performed: bool = false;
for (actions) |action| {
if (self.performBindingAction(action)) |performed_| {
performed = performed or performed_;
if (self.performBindingAction(action)) |v| {
performed = performed or v;
} else |err| {
log.info(
"key binding action failed action={t} err={}",
@@ -2991,8 +2991,18 @@ fn maybeHandleBinding(
// Store our last trigger so we don't encode the release event
self.keyboard.last_trigger = event.bindingHash();
// TODO: Inspector must support chained events
if (insp_ev) |ev| ev.binding = actions[0];
if (insp_ev) |ev| {
ev.binding = self.alloc.dupe(
input.Binding.Action,
actions,
) catch |err| binding: {
log.warn(
"error allocating binding action for inspector err={}",
.{err},
);
break :binding &.{};
};
}
return .consumed;
}

View File

@@ -13,7 +13,8 @@ pub const Event = struct {
event: input.KeyEvent,
/// The binding that was triggered as a result of this event.
binding: ?input.Binding.Action = null,
/// Multiple bindings are possible if they are chained.
binding: []const input.Binding.Action = &.{},
/// The data sent to the pty as a result of this keyboard event.
/// This is allocated using the inspector allocator.
@@ -32,6 +33,7 @@ pub const Event = struct {
}
pub fn deinit(self: *const Event, alloc: Allocator) void {
alloc.free(self.binding);
if (self.event.utf8.len > 0) alloc.free(self.event.utf8);
if (self.pty.len > 0) alloc.free(self.pty);
}
@@ -79,12 +81,28 @@ pub const Event = struct {
);
defer cimgui.c.igEndTable();
if (self.binding) |binding| {
if (self.binding.len > 0) {
cimgui.c.igTableNextRow(cimgui.c.ImGuiTableRowFlags_None, 0);
_ = cimgui.c.igTableSetColumnIndex(0);
cimgui.c.igText("Triggered Binding");
_ = cimgui.c.igTableSetColumnIndex(1);
cimgui.c.igText("%s", @tagName(binding).ptr);
const height: f32 = height: {
const item_count: f32 = @floatFromInt(@min(self.binding.len, 5));
const padding = cimgui.c.igGetStyle().*.FramePadding.y * 2;
break :height cimgui.c.igGetTextLineHeightWithSpacing() * item_count + padding;
};
if (cimgui.c.igBeginListBox("##bindings", .{ .x = 0, .y = height })) {
defer cimgui.c.igEndListBox();
for (self.binding) |action| {
_ = cimgui.c.igSelectable_Bool(
@tagName(action).ptr,
false,
cimgui.c.ImGuiSelectableFlags_None,
.{ .x = 0, .y = 0 },
);
}
}
}
pty: {