git.lucas.co / cce-gallery
widget gallery and compositor test bench

commit6799ded7b978ee6629b58f3eb586d0df32b9077c
parent3aa7549a15
authorLucas Galante <lsgalante12@gmail.com>
date2026-10-08 23:39
fix: focus the ramp child by id

The Ramp's fields are no longer registered by pointer (cce-ui owning
registry, phase 4), so the gallery focuses the Ramp itself through its
handle's id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

 src/main.rs | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 130bea4..6cd15fa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -987,22 +987,20 @@ impl cce_ui::engine::Application for State {
         };
 
         let main = state.roster.get_dyn_mut(&mut state.ui_context, 1);
-        if let Some(ramp) = main.as_any_mut().downcast_mut::<Ramp>().filter(|_| is_child) {
+        if main.as_any_mut().downcast_mut::<Ramp>().is_some() && is_child {
             // Only a `--type Ramp` child hosts a Ramp in slot 1: it opens with the
-            // preset dropdown focused so the keyboard drives it at once. Every other
-            // child kind (ColorRamp, or the description Label of the Toplevel /
-            // Popup / Layer* windows) starts with nothing focused — the key sweep
-            // in handle_key reaches every visible child slot anyway, and a click
-            // focuses whatever it lands on. This used to downcast unconditionally
-            // and panic for those kinds ("child ramp widget"), which is why Create
-            // Window on the Windows page spawned children that died at startup.
-            let preset_ptr = ramp.preset_dropdown.as_ptr_mut();
+            // preset dropdown focused so the keyboard drives it at once — the ramp
+            // takes the window's focus and gives its first field, the preset
+            // dropdown, the keyboard. Every other child kind (ColorRamp, or the
+            // description Label of the Toplevel / Popup / Layer* windows) starts with
+            // nothing focused — the key sweep in handle_key reaches every visible
+            // child slot anyway, and a click focuses whatever it lands on. This used
+            // to downcast unconditionally and panic for those kinds ("child ramp
+            // widget"), which is why Create Window on the Windows page spawned
+            // children that died at startup.
             state.focused_widget = Some(1);
-            // SAFETY: `preset_ptr` was just taken from the live dropdown above.
-            unsafe {
-                state.ui_context.set_focused_ptr(preset_ptr);
-                (*preset_ptr).focus();
-            }
+            let ramp_id = state.roster.id(1);
+            state.ui_context.set_focused_id(ramp_id);
         }
 
         state.relayout();