From b58e96436af2f9e0917f0d1936d19cac807a0987 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 14 Oct 2026 18:32:58 +0200 Subject: [PATCH] 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 --- crates/horizon-client/src/game/pad_menu.rs | 5 +++++ crates/horizon-client/src/ui_theme.rs | 6 ++++++ crates/horizon-client/src/widgets.rs | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/crates/horizon-client/src/game/pad_menu.rs b/crates/horizon-client/src/game/pad_menu.rs index 40a3b8860..f6afe37ba 100644 --- a/crates/horizon-client/src/game/pad_menu.rs +++ b/crates/horizon-client/src/game/pad_menu.rs @@ -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; diff --git a/crates/horizon-client/src/ui_theme.rs b/crates/horizon-client/src/ui_theme.rs index bcbc31a69..9d0851b00 100644 --- a/crates/horizon-client/src/ui_theme.rs +++ b/crates/horizon-client/src/ui_theme.rs @@ -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 { diff --git a/crates/horizon-client/src/widgets.rs b/crates/horizon-client/src/widgets.rs index 75366dcba..beaa12a1d 100644 --- a/crates/horizon-client/src/widgets.rs +++ b/crates/horizon-client/src/widgets.rs @@ -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, Vec, 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)); } }); }