Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion graphcode-windows/src/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9647,10 +9647,17 @@ pub const App = struct {
const key = std.fmt.allocPrint(self.allocator, "{s}:{s}", .{ graph.project.path, node.id }) catch return;
defer self.allocator.free(key);
self.appendAccessibilityElement(&elements, &owned_identities, "overview-card", key, node.title, 4, .{ .logical = bounds }, false, false) catch return;
if (GraphCanvas.overviewNodeRole(&self.canvas, graph_index, node_index) == .unwired) {
const role = GraphCanvas.overviewNodeRole(&self.canvas, graph_index, node_index);
if (role == .unwired) {
const actions = GraphCanvas.unwiredActionBounds(bounds, &self.canvas);
self.appendAccessibilityElement(&elements, &owned_identities, "overview-wire-node", key, "Wire it up", 4, .{ .logical = actions.wire }, false, true) catch return;
self.appendAccessibilityElement(&elements, &owned_identities, "overview-mark-entry", key, "Mark as entry", 4, .{ .logical = actions.mark_entry }, false, true) catch return;
} else if (GraphCanvas.attentionActionVisible(node, graph.nodes.items, graph.edges.items)) {
self.appendAccessibilityElement(&elements, &owned_identities, "attention-action", key, GraphCanvas.attentionActionLabel(node), 4, .{ .logical = GraphCanvas.attentionActionBounds(bounds, &self.canvas) }, false, true) catch return;
}
if (role == .cycle_only) {
self.appendAccessibilityElement(&elements, &owned_identities, "cycle-reason", key, "cycle · no entry point", 4, .{ .logical = GraphCanvas.cycleReasonBounds(bounds, &self.canvas) }, false, false) catch return;
elements.items[elements.items.len - 1].invokable = false;
}
}
},
Expand Down Expand Up @@ -11591,6 +11598,9 @@ fn onWindowMessage(
.overview => {
if (app.applyOverviewLaneAction(x, y, bounds)) {
_ = c.InvalidateRect(hwnd, null, 0);
} else if (GraphCanvas.hitTestOverviewAttentionAction(&app.model, x, y, &app.canvas, bounds)) |hit| {
const graph = app.model.graphs.items[hit.graph_index];
_ = app.activateLoop(graph.project.path, graph.nodes.items[hit.node_index].id);
} else if (GraphCanvas.hitTestOverviewUnwiredAction(&app.model, x, y, &app.canvas, bounds)) |hit| {
const graph = app.model.graphs.items[hit.graph_index];
if (app.selectProject(graph.project.path)) {
Expand Down Expand Up @@ -23977,6 +23987,71 @@ test "closed cycle UIA separates the footer reason from Inspect and preserves se
}
}

test "loop card overview attention UIA publication exposes action and cycle roles" {
const Sink = struct {
checked: bool = false,
action_seen: usize = 0,
reason_seen: usize = 0,
unwired_action_seen: usize = 0,
failure: ?anyerror = null,

fn syncCanvasBounds(_: *@This(), _: c.RECT) void {}

fn syncElements(self: *@This(), _: []const u8, elements: []const Accessibility.DynamicElement, _: WorktreeStatus.Policy, _: Accessibility.WorktreeCapabilities) void {
self.checked = true;
self.check(elements) catch |err| {
self.failure = err;
};
}

fn check(self: *@This(), elements: []const Accessibility.DynamicElement) !void {
var inspect_bottom: i32 = 0;
var reason_top: i32 = 0;
for (elements) |element| {
if (std.mem.eql(u8, element.identity, "attention-action:C:\\overview:question")) {
self.action_seen += 1;
try std.testing.expectEqualStrings("Reply", element.name);
try std.testing.expect(element.invokable);
} else if (std.mem.eql(u8, element.identity, "attention-action:C:\\overview:main")) {
self.action_seen += 1;
try std.testing.expectEqualStrings("Inspect", element.name);
try std.testing.expect(element.invokable);
inspect_bottom = element.bottom;
} else if (std.mem.eql(u8, element.identity, "cycle-reason:C:\\overview:main")) {
self.reason_seen += 1;
try std.testing.expectEqualStrings("cycle · no entry point", element.name);
try std.testing.expect(!element.invokable);
reason_top = element.top;
} else if (std.mem.eql(u8, element.identity, "attention-action:C:\\overview:unwired")) {
self.unwired_action_seen += 1;
}
}
try std.testing.expectEqual(@as(usize, 2), self.action_seen);
try std.testing.expectEqual(@as(usize, 1), self.reason_seen);
try std.testing.expectEqual(@as(usize, 0), self.unwired_action_seen);
try std.testing.expect(inspect_bottom > 0 and inspect_bottom <= reason_top);
}
};

var app = try overviewTestApp(96);
defer deinitOverviewTestApp(&app);
app.surface = .overview;
_ = try app.model.updateFromFrame(
\\{"version":2,"kind":"event","sequence":1,"event":{"graphChanged":{"project":{"path":"C:\\overview","name":"Overview"},"nodes":[{"id":"seed","title":"Seed","loopType":"sketch","state":"idle"},{"id":"question","title":"Question","loopType":"goalBased","state":"running","presence":"awaitingInput"},{"id":"main","title":"Main","loopType":"sketch","state":"blocked"},{"id":"peer","title":"Peer","loopType":"sketch","state":"blocked"},{"id":"unwired","title":"Unwired","loopType":"goalBased","state":"running","presence":"awaitingInput"}],"edges":[{"id":"seed-question","from":"seed","to":"question","kind":"handoff"},{"id":"main-peer","from":"main","to":"peer","kind":"handoff"},{"id":"peer-main","from":"peer","to":"main","kind":"handoff"}]}}}
);
try std.testing.expect(app.model.selectProject("C:\\overview"));
try std.testing.expect(app.refreshCanvasLayout(.{ .left = 0, .top = 0, .right = 1200, .bottom = 900 }));
var sink = Sink{};
app.syncAccessibilityTo(&sink, .{ .left = 0, .top = 0, .right = 1200, .bottom = 900 });
try std.testing.expect(sink.checked);
if (sink.failure) |err| return err;
try std.testing.expect(app.applyUiaDynamicInvoke(
Accessibility.worktreeIdentityPayload("attention-action:C:\\overview:question"),
));
try std.testing.expectEqual(GraphCanvas.Surface.workspace, app.surface);
try std.testing.expectEqualStrings("question", app.model.selected().?.id);
}

const WireRouteSheet = struct {
var owner: c.HWND = null;
var timer: c.UINT_PTR = 0;
Expand Down
77 changes: 77 additions & 0 deletions graphcode-windows/src/GraphCanvas.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,32 @@ pub fn hitTestOverview(
return null;
}

pub fn hitTestOverviewAttentionAction(
model: *const GraphModel.Model,
x: i32,
y: i32,
state: *const CanvasState,
graph_bounds: c.RECT,
) ?OverviewHit {
if (!insideGraph(x, y, graph_bounds)) return null;
var graph_index = model.graphs.items.len;
while (graph_index > 0) {
graph_index -= 1;
const graph = &model.graphs.items[graph_index];
const lane = cachedOverviewLane(state, graph_index) orelse continue;
var node_index = graph.nodes.items.len;
while (node_index > 0) {
node_index -= 1;
if (node_index >= lane.layout.roles.len or lane.layout.roles[node_index] == .unwired) continue;
if (!attentionActionVisible(graph.nodes.items[node_index], graph.nodes.items, graph.edges.items)) continue;
const bounds = overviewCardBounds(model, graph_index, node_index, graph_bounds, state);
if (insideGraph(x, y, attentionActionBounds(bounds, state)))
return .{ .graph_index = graph_index, .node_index = node_index };
}
}
return null;
}

pub fn hitTestOverviewUnwiredAction(
model: *const GraphModel.Model,
x: i32,
Expand Down Expand Up @@ -9697,6 +9723,57 @@ test "loop card parity existing action fills use hit bounds and never paint over
}
}

test "loop card overview attention action and cycle role use overview geometry" {
var model = GraphModel.Model.init(std.testing.allocator);
defer model.deinit();
_ = try model.updateFromFrame(
\\{"version":2,"kind":"event","sequence":1,"event":{"graphChanged":{"project":{"path":"C:\\overview","name":"Overview"},"nodes":[{"id":"seed","title":"Seed","loopType":"sketch","state":"idle"},{"id":"question","title":"Question","loopType":"goalBased","state":"running","presence":"awaitingInput"},{"id":"main","title":"Main","loopType":"sketch","state":"blocked"},{"id":"peer","title":"Peer","loopType":"sketch","state":"blocked"},{"id":"unwired","title":"Unwired","loopType":"goalBased","state":"running","presence":"awaitingInput"}],"edges":[{"id":"seed-question","from":"seed","to":"question","kind":"handoff"},{"id":"main-peer","from":"main","to":"peer","kind":"handoff"},{"id":"peer-main","from":"peer","to":"main","kind":"handoff"}]}}}
);
const graph = &model.graphs.items[0];
const bounds = rect(220, 34, 2600, 2000);
for ([_]f32{ 1, 1.25, 1.8 }) |zoom| {
var state = try modelTestState(&model, .{ .zoom = zoom }, bounds);
defer state.deinitLayout();
const question = overviewCardBounds(&model, 0, 1, bounds, &state);
const question_action = attentionActionBounds(question, &state);
try std.testing.expect(insideGraph(question_action.left + 1, question_action.top + 1, bounds));
const question_hit = hitTestOverviewAttentionAction(
&model,
question_action.left + 1,
question_action.top + 1,
&state,
bounds,
) orelse return error.OverviewAttentionQuestionMissing;
try std.testing.expectEqual(@as(usize, 0), question_hit.graph_index);
try std.testing.expectEqual(@as(usize, 1), question_hit.node_index);
try std.testing.expectEqual(AttentionAction.reply, primaryCardAction(graph.nodes.items[1]).?);

const cycle = overviewCardBounds(&model, 0, 2, bounds, &state);
const cycle_action = attentionActionBounds(cycle, &state);
try std.testing.expect(insideGraph(cycle_action.left + 1, cycle_action.top + 1, bounds));
const cycle_hit = hitTestOverviewAttentionAction(
&model,
cycle_action.left + 1,
cycle_action.top + 1,
&state,
bounds,
) orelse return error.OverviewAttentionCycleMissing;
try std.testing.expectEqual(@as(usize, 2), cycle_hit.node_index);
try std.testing.expectEqual(AttentionAction.inspect, primaryCardAction(graph.nodes.items[2]).?);
try std.testing.expectEqual(@as(?NodeRole, .cycle_only), overviewNodeRole(&state, 0, 2));

const unwired = overviewCardBounds(&model, 0, 4, bounds, &state);
const unwired_action = attentionActionBounds(unwired, &state);
try std.testing.expect(hitTestOverviewAttentionAction(
&model,
unwired_action.left + 1,
unwired_action.top + 1,
&state,
bounds,
) == null);
}
}

test "minimum zoom keeps compact rows separated inside a 96 point card" {
var state = try cardTestState(.{ .zoom = 0.55 });
defer state.deinitLayout();
Expand Down
Loading