| 2942 | |
| 2943 | #[test] |
| 2944 | fn test_focus_ring_render_command() { |
| 2945 | use render_commands::RenderCommandConfig; |
| 2946 | |
| 2947 | let mut ply = Ply::<()>::new_headless(Dimensions::new(800.0, 600.0)); |
| 2948 | let id_a = Id::from("a").id; |
| 2949 | |
| 2950 | // Frame 1: layout |
| 2951 | { |
| 2952 | let mut ui = ply.begin(); |
| 2953 | ui.element() |
| 2954 | .id("a") |
| 2955 | .width(fixed!(100.0)) |
| 2956 | .height(fixed!(50.0)) |
| 2957 | .corner_radius(8.0) |
| 2958 | .accessibility(|a| a.button("A")) |
| 2959 | .empty(); |
| 2960 | ui.eval(); |
| 2961 | } |
| 2962 | |
| 2963 | // Set focus via keyboard |
| 2964 | ply.context.focus_from_keyboard = true; |
| 2965 | ply.context.set_focus(id_a); |
| 2966 | |
| 2967 | // Frame 2: eval to get render commands with focus ring |
| 2968 | { |
| 2969 | let mut ui = ply.begin(); |
| 2970 | ui.element() |
| 2971 | .id("a") |
| 2972 | .width(fixed!(100.0)) |
| 2973 | .height(fixed!(50.0)) |
| 2974 | .corner_radius(8.0) |
| 2975 | .accessibility(|a| a.button("A")) |
| 2976 | .empty(); |
| 2977 | let items = ui.eval(); |
| 2978 | |
| 2979 | // Look for a border render command with z_index 32764 (the focus ring) |
| 2980 | let focus_ring = items.iter().find(|cmd| { |
| 2981 | cmd.z_index == 32764 && matches!(cmd.config, RenderCommandConfig::Border(_)) |
| 2982 | }); |
| 2983 | assert!(focus_ring.is_some(), "Focus ring border should be in render commands"); |
| 2984 | |
| 2985 | let ring = focus_ring.unwrap(); |
| 2986 | // Focus ring should be expanded by 2px per side |
| 2987 | assert!(ring.bounding_box.width > 100.0, "Focus ring should be wider than element"); |
| 2988 | assert!(ring.bounding_box.height > 50.0, "Focus ring should be taller than element"); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | #[test] |
| 2993 | fn test_overflow_scrollbar_renders_and_moves_with_set_scroll_position() { |