| 2826 | |
| 2827 | #[test] |
| 2828 | fn test_focused_query() { |
| 2829 | let mut ply = Ply::<()>::new_headless(Dimensions::new(800.0, 600.0)); |
| 2830 | |
| 2831 | let id_a = Id::from("a").id; |
| 2832 | |
| 2833 | // Frame 1: layout + set focus |
| 2834 | { |
| 2835 | let mut ui = ply.begin(); |
| 2836 | ui.element() |
| 2837 | .id("a") |
| 2838 | .width(fixed!(100.0)) |
| 2839 | .height(fixed!(50.0)) |
| 2840 | .accessibility(|a| a.button("A")) |
| 2841 | .empty(); |
| 2842 | ui.eval(); |
| 2843 | } |
| 2844 | |
| 2845 | ply.context.set_focus(id_a); |
| 2846 | |
| 2847 | // Frame 2: check focused() during layout |
| 2848 | { |
| 2849 | let mut ui = ply.begin(); |
| 2850 | ui.element() |
| 2851 | .id("a") |
| 2852 | .width(fixed!(100.0)) |
| 2853 | .height(fixed!(50.0)) |
| 2854 | .accessibility(|a| a.button("A")) |
| 2855 | .children(|ui| { |
| 2856 | assert!(ui.focused(), "element should report as focused"); |
| 2857 | }); |
| 2858 | ui.eval(); |
| 2859 | } |
| 2860 | } |
| 2861 | |
| 2862 | #[test] |
| 2863 | fn test_on_focus_callback_fires_on_tab() { |