Controllers: Horizon-style menus' controls are focus targets too

Ui::interact records every enabled control (sidebar items, switches,
sliders, segments) as a D-pad focus target, apart from the labelled
button list horizon-ctl clicks by name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-14 18:32:58 +02:00
parent cbf4b53b0c
commit b58e96436a
3 changed files with 30 additions and 0 deletions
@@ -65,6 +65,11 @@ impl Game<'_> {
.iter()
.filter(|w| w.enabled)
.map(|w| (w.x + w.w / 2.0, w.y + w.h / 2.0))
.chain(
widgets::last_targets()
.into_iter()
.map(|[x, y, w, h]| (x + w / 2.0, y + h / 2.0)),
)
.collect();
if self.title.is_some() {
return targets;
+6
View File
@@ -521,6 +521,12 @@ impl<'a> Ui<'a> {
/// Register an interactive rectangle; returns its hover layer (0..1,
/// eased over `QUICK` like the launcher's `hover_layer`).
pub fn interact(&mut self, id: u64, x: f32, y: f32, w: f32, h: f32, enabled: bool) -> f32 {
if enabled && self.real {
// Where a controller's D-pad can move focus, in GUI pixels.
let k = self.density / self.scale;
let (ox, oy) = self.offset;
crate::widgets::target([(x + ox) * k, (y + oy) * k, w * k, h * k]);
}
if enabled {
let (ox, oy) = self.offset;
self.hits.push(Hit {
+19
View File
@@ -17,6 +17,24 @@ pub struct Widget {
thread_local! {
/// Buttons drawn since the last `end_frame`, and the last frame's.
static WIDGETS: RefCell<(Vec<Widget>, Vec<Widget>, u64)> = const { RefCell::new((Vec::new(), Vec::new(), 0)) };
/// Every interactive rectangle of Horizon-style menus (sidebar items,
/// switches, sliders, segments), labelled or not: where a controller's
/// D-pad can move focus. Drawn since `end_frame`, and the last frame's.
static TARGETS: RefCell<(Vec<[f32; 4]>, Vec<[f32; 4]>)> = const { RefCell::new((Vec::new(), Vec::new())) };
}
/// An interactive rectangle (GUI pixels) a controller can focus.
pub fn target(rect: [f32; 4]) {
TARGETS.with_borrow_mut(|(current, _)| {
if current.len() < 1024 {
current.push(rect);
}
});
}
/// The focus targets of the last drawn frame.
pub fn last_targets() -> Vec<[f32; 4]> {
TARGETS.with_borrow(|(_, last)| last.clone())
}
/// Called by the button drawers.
@@ -46,6 +64,7 @@ pub fn end_frame(frames: u64) {
if *seen != frames {
*seen = frames;
*last = std::mem::take(current);
TARGETS.with_borrow_mut(|(current, last)| *last = std::mem::take(current));
}
});
}