Controllers: focus follows scrolled lists, clipped targets, pad status shows focus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-15 01:20:14 +02:00
parent 9927d06049
commit 210a6f5ddd
14 changed files with 500 additions and 71 deletions
+32
View File
@@ -74,6 +74,27 @@ pub fn target_as(rect: [f32; 4], kind: Kind) {
});
}
/// How many targets the frame has so far, for [`clip_targets`].
pub fn targets_mark() -> usize {
TARGETS.with_borrow(|(current, _, _)| current.len())
}
/// Drop the targets registered since `mark` that aren't inside `y0..y1`
/// (GUI pixels): rows a scrolling list clipped away.
pub fn clip_targets(mark: usize, y0: f32, y1: f32) {
TARGETS.with_borrow_mut(|(current, _, _)| {
let mut i = mark.min(current.len());
while i < current.len() {
let [_, y, _, h] = current[i].rect;
if y < y0 - 0.5 || y + h > y1 + 0.5 {
current.remove(i);
} else {
i += 1;
}
}
});
}
/// The focus targets of the last drawn frame.
pub fn last_targets() -> Vec<Target> {
TARGETS.with_borrow(|(_, last, _)| last.clone())
@@ -198,5 +219,16 @@ mod tests {
assert_eq!(generation(), before + 1);
end_frame(2);
assert!(last().is_empty() && last_targets().is_empty());
target([0.0, 0.0, 5.0, 5.0]);
let mark = targets_mark();
target([0.0, 10.0, 5.0, 5.0]);
target([0.0, 40.0, 5.0, 5.0]);
clip_targets(mark, 8.0, 30.0);
end_frame(3);
assert_eq!(
last_targets().len(),
2,
"the clipped row is gone, earlier ones stay"
);
}
}