diff --git a/crates/ui-egui/src/export_window.rs b/crates/ui-egui/src/export_window.rs index f8360ecb..316e4454 100644 --- a/crates/ui-egui/src/export_window.rs +++ b/crates/ui-egui/src/export_window.rs @@ -52,6 +52,8 @@ const LIST_ROW_HEIGHT: f32 = 24.0; const LIST_ROW_INDENT: f32 = 16.0; /// Width of the bottom bar's buttons, the same for all as in the reference const FOOTER_BUTTON_WIDTH: f32 = 126.0; +/// Width of the keyboard focus outline on the window's drawn controls +const FOCUS_OUTLINE_WIDTH: f32 = 2.0; /// The output sizes the Size list offers, in texels per side pub(crate) const SIZES: [u32; 7] = [128, 256, 512, 1024, 2048, 4096, 8192]; @@ -623,6 +625,15 @@ fn selected_texture_count(app: &mut TextureCraftApp) -> usize { count } +/// The keyboard focus outline of a drawn control: inside `response`'s rect, in the strong text +/// colour, so it differs from the accent of the selected one and the fill of the hovered one +fn paint_focus(ui: &Ui, response: &egui::Response) { + if response.has_focus() { + let stroke = egui::Stroke::new(FOCUS_OUTLINE_WIDTH, Tokens::get(ui.ctx()).text_strong); + ui.painter().rect_stroke(response.rect, 0.0, stroke, egui::StrokeKind::Inside); + } +} + /// A window tab: a box, lighter and with an accent line on top when open fn tab_button(ui: &mut Ui, label: &str, selected: bool) -> egui::Response { let tokens = Tokens::get(ui.ctx()); @@ -642,6 +653,7 @@ fn tab_button(ui: &mut Ui, label: &str, selected: bool) -> egui::Response { painter.rect_filled(egui::Rect::from_min_size(rect.min, vec2(rect.width(), TAB_ACCENT_HEIGHT)), 0.0, tokens.accent); } painter.galley(rect.min + TAB_PADDING, galley, color); + paint_focus(ui, &response); response } @@ -889,6 +901,7 @@ fn list_row(ui: &mut Ui, text: &str, selected: bool) -> egui::Response { } let font = semibold(egui::TextStyle::Body.resolve(ui.style()).size); painter.text(rect.left_center() + vec2(LIST_ROW_INDENT, 0.0), egui::Align2::LEFT_CENTER, text, font, tokens.text_strong); + paint_focus(ui, &response); response } @@ -1108,6 +1121,7 @@ fn list_tab(app: &mut TextureCraftApp, ui: &mut Ui) { let glyph_color = if response.hovered() { tk.text_strong } else { tk.text }; ui.painter().rect_filled(strip, 0.0, tk.chrome); ui.painter().text(strip.center(), egui::Align2::CENTER_CENTER, glyph, egui::TextStyle::Body.resolve(ui.style()), glyph_color); + paint_focus(ui, &response); let response = response.on_hover_text(tooltip); if !hidden && (response.hovered() || response.dragged()) { ui.ctx().set_cursor_icon(egui::CursorIcon::ResizeHorizontal); diff --git a/crates/ui-egui/tests/it/export_reference_texts.rs b/crates/ui-egui/tests/it/export_reference_texts.rs index 46dcd4b9..1c5d5c23 100644 --- a/crates/ui-egui/tests/it/export_reference_texts.rs +++ b/crates/ui-egui/tests/it/export_reference_texts.rs @@ -108,3 +108,32 @@ fn the_bottom_bar_buttons_share_one_width() { assert!(widths.windows(2).all(|pair| (pair[0] - pair[1]).abs() < 1.0), "{widths:?}"); } + +/// The Size list of the Global settings page +fn size_list<'a>(h: &'a Harness<'_, TextureCraftApp>) -> egui_kittest::Node<'a> { + h.get_all_by_role(egui::Role::ComboBox) + .find(|list| list.accesskit_node().value().as_deref() == Some("Based on each Texture Set's size")) + .expect("the Size list") +} + +#[test] +fn on_a_short_narrow_screen_the_settings_scroll_and_the_footer_stays_in_view() { + let screen = egui::vec2(800.0, 480.0); + let mut h = harness(screen); + for label in ["Cancel", "Export"] { + let rect = window_button_rect(&h, label, screen.x); + assert!(rect.max.x <= screen.x && rect.max.y <= screen.y, "{label} {rect:?}"); + } + let export = window_button_rect(&h, "Export", screen.x); + + // The last setting and the right end of the value lists scroll into the window, above the footer + h.get_by_label("Color space").scroll_to_me(); + h.run_steps(4); + let color_space = h.get_by_label("Color space").rect(); + assert!(color_space.max.y < export.min.y, "Color space {color_space:?}, footer {export:?}"); + + size_list(&h).scroll_to_me(); + h.run_steps(4); + let size = size_list(&h).rect(); + assert!(size.max.x <= export.max.x, "Size {size:?}, window right end {}", export.max.x); +}