diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 7e48fc244e..d10d320ad9 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -82,10 +82,8 @@ pub fn app_bar(app: &mut VectorcraftApp, ui: &mut Ui) { ui.add_space(2.0); // With the macOS menu bar the menus are at the top of the screen instead. let menus_end = if app.services.native_menu.is_some() { ui.cursor().min.x } else { menus::menu_bar(app, ui) }; - // The right-side group fills the space after the menus from the right; when it runs - // short, Discord goes first (it is also under Help), then Explore tutorials (also - // Window › Learn), then the search icon (the palette stays under its shortcut), then - // the workspace switcher narrows. + // The right-side group fills the space after the menus from the right, in the order + // [`fit_right_group`] gives. let full = ui.max_rect(); let right_edge = if captions_right > 0.0 { full.right() - captions_right - 10.0 } else { full.right() }; let right = egui::Rect::from_min_max(egui::pos2(menus_end + 8.0, full.top()), egui::pos2(right_edge, full.bottom())); @@ -97,21 +95,22 @@ pub fn app_bar(app: &mut VectorcraftApp, ui: &mut Ui) { let text = ui.painter().layout_no_wrap(label.text().to_string(), egui::FontId::proportional(12.0), t.warning); text.size().x + 2.0 * ui.spacing().button_padding.x + 8.0 + ui.spacing().item_spacing.x }); - let room = (right.width() - safe_w).max(0.0); - let switcher = safe.is_none() || room >= 64.0 + 8.0; // Built-in workspace names translate; the user's own stay as typed. let ws_name = if crate::workspaces::is_builtin(&app.ui.workspace) { tl!(&app.ui.workspace).to_string() } else { app.ui.workspace.clone() }; let ws = ui.painter().layout_no_wrap(ws_name, egui::FontId::proportional(12.0), t.text); - let ws_w = (ws.size().x + 36.0).clamp(112.0, 190.0); - let gap = ui.spacing().item_spacing.x; - // The search icon, as in PhotoCraft: shown while a minimal switcher fits beside it. - let icon = 28.0; - let search = switcher && room >= 64.0 + 8.0 + gap + icon; - let ws_w = ws_w.min(room - 8.0 - gap - if search { icon } else { 0.0 }).max(64.0); - // Explore tutorials, beside the search icon, opens the Learn panel. - let learn = search && room >= ws_w + 8.0 + 2.0 * (gap + icon); - let discord = learn && room >= ws_w + 8.0 + 2.0 * (gap + icon) + 10.0 + gap + crate::community::discord_width(ui, false); + let shortcut = menus::shortcut_of("help.commandPalette").map(menus::shown_shortcut); + let field = SearchField::new(ui, &t, shortcut); + let fit = fit_right_group(&RightWidths { + room: (right.width() - safe_w).max(0.0), + safe_mode: safe.is_some(), + switcher: (ws.size().x + 36.0).clamp(112.0, 190.0), + field: field.width, + icon: BAR_ICON, + gap: ui.spacing().item_spacing.x, + discord: crate::community::discord_width(ui, false), + }); + let (switcher, ws_w, learn, discord) = (fit.switcher, fit.switcher_w, fit.learn, fit.discord); let mut rui = ui.new_child(egui::UiBuilder::new().max_rect(right).layout(egui::Layout::right_to_left(egui::Align::Center))); let ui = &mut rui; // Workspace switcher: shows the current workspace, opens Window → Workspace. @@ -131,19 +130,26 @@ pub fn app_bar(app: &mut VectorcraftApp, ui: &mut Ui) { ui.add_space(8.0); } // Search → command palette (its shortcut opens it too). - if search { - let tip = match menus::shortcut_of("help.commandPalette") { - Some(sc) => format!("{} ({})", tl!("Search commands and tools"), menus::shown_shortcut(sc)), - None => tl!("Search commands and tools").to_string(), - }; - if widgets::icon_button(ui, "search", &tip, app.ui.palette_open, icon).clicked() { - app.ui.palette_open = !app.ui.palette_open; - app.ui.palette_query.clear(); - } + let with_shortcut = |text: &str| match &field.shortcut { + Some(sc) => format!("{text} ({sc})"), + None => text.to_string(), + }; + let tip = with_shortcut(tl!("Search commands and tools")); + let name = with_shortcut(tl!("Search commands")); + let clicked = match fit.search { + Search::Field => field.show(ui, &t, &name, &tip, app.ui.palette_open).clicked(), + Search::Icon => widgets::icon_button(ui, "search", &tip, app.ui.palette_open, BAR_ICON).clicked(), + Search::Hidden => false, + }; + // The field and the icon toggle the palette as its shortcut does, and like the shortcut + // they do nothing while a dialog is open. + if clicked && app.ui.dialog.is_none() { + app.ui.palette_open = !app.ui.palette_open; + app.ui.palette_query.clear(); } if learn { let shown = crate::panels::learn::visible(&app.ui); - if widgets::icon_button(ui, "graduation-cap", tl!("Explore tutorials"), shown, icon).clicked() + if widgets::icon_button(ui, "graduation-cap", tl!("Explore tutorials"), shown, BAR_ICON).clicked() && let Err(e) = app.run("window.learn", json!({})) { app.ui.status = e; @@ -168,6 +174,133 @@ pub fn app_bar(app: &mut VectorcraftApp, ui: &mut Ui) { } } +/// The side of the app bar's square icon buttons (the search icon, Explore tutorials). +const BAR_ICON: f32 = 28.0; +/// The narrowest the workspace switcher gets. +const MIN_SWITCHER: f32 = 64.0; + +/// How the app bar shows the search that opens the command palette. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Search { + /// A field with the magnifier, "Search commands" and the palette's shortcut. + Field, + /// The magnifier alone. + Icon, + /// Not in the bar; the palette stays under its shortcut and Help › Search Commands…. + Hidden, +} + +/// The widths [`fit_right_group`] fits into `room`, in points. +#[derive(Clone, Copy, Debug)] +struct RightWidths { + /// The room after the menus, less the Safe Mode label's. + room: f32, + safe_mode: bool, + /// The workspace switcher's full width. + switcher: f32, + /// The search field's width. + field: f32, + icon: f32, + gap: f32, + discord: f32, +} + +/// What the right-hand group of the app bar shows. +#[derive(Clone, Copy, Debug, PartialEq)] +struct RightGroup { + switcher: bool, + switcher_w: f32, + search: Search, + learn: bool, + discord: bool, +} + +/// The right-hand group for the room it has. As the room runs short, the community button goes first +/// (it is also under Help), then Explore tutorials (also Window › Learn), then the search field becomes the +/// search icon, then the workspace switcher narrows to [`MIN_SWITCHER`], then the icon goes. In Safe +/// Mode the label's width is taken first, and the switcher (also under Window › Workspace) goes when +/// a minimal one does not fit. +fn fit_right_group(w: &RightWidths) -> RightGroup { + let room = w.room; + let switcher = !w.safe_mode || room >= MIN_SWITCHER + 8.0; + let icon = switcher && room >= MIN_SWITCHER + 8.0 + w.gap + w.icon; + let field = icon && room >= w.switcher + 8.0 + w.gap + w.field; + let search = if field { + Search::Field + } else if icon { + Search::Icon + } else { + Search::Hidden + }; + let search_w = match search { + Search::Field => w.gap + w.field, + Search::Icon => w.gap + w.icon, + Search::Hidden => 0.0, + }; + let switcher_w = w.switcher.min(room - 8.0 - search_w).max(MIN_SWITCHER); + let learn_end = switcher_w + 8.0 + search_w + w.gap + w.icon; + let learn = field && room >= learn_end; + let discord = learn && room >= learn_end + 10.0 + w.gap + w.discord; + RightGroup { switcher, switcher_w, search, learn, discord } +} + +/// The app bar's search field: a button drawn as a field. The command palette's popup holds the +/// only text field. +struct SearchField { + hint: Arc, + /// The palette's shortcut as the menus show it; none when the user cleared it. + shortcut: Option, + key: Option>, + width: f32, +} + +impl SearchField { + /// Space from the field's left edge to the hint text (the magnifier sits in it). + const TEXT_LEFT: f32 = 26.0; + /// The widest the field gets. + const MAX_WIDTH: f32 = 220.0; + + fn new(ui: &Ui, t: &Tokens, shortcut: Option) -> SearchField { + let hint = ui.painter().layout_no_wrap(tl!("Search commands").to_string(), egui::FontId::proportional(12.0), t.text_dim); + let text_w = Self::TEXT_LEFT + hint.size().x + 8.0; + // A shortcut that leaves no room for the hint in the widest field is left to the tooltip. + let key = shortcut + .as_ref() + .map(|s| ui.painter().layout_no_wrap(s.clone(), egui::FontId::proportional(11.0), t.text_dim)) + .filter(|k| text_w + 12.0 + k.size().x <= Self::MAX_WIDTH); + let key_w = key.as_ref().map_or(0.0, |k| 12.0 + k.size().x); + let width = (text_w + key_w + 24.0).clamp(120.0, Self::MAX_WIDTH); + SearchField { hint, shortcut, key, width } + } + + /// Draws the field. A click, or Enter or Space with the keyboard on it, clicks it. Screen + /// readers get a button called `name`, and hovering it shows `tip`. + fn show(self, ui: &mut Ui, t: &Tokens, name: &str, tip: &str, open: bool) -> egui::Response { + let (r, resp) = ui.allocate_exact_size(vec2(self.width, WIDGET_H), Sense::click()); + let fill = if open { + t.tool_active + } else if resp.hovered() { + t.hover + } else { + t.input + }; + let border = if resp.has_focus() { t.accent } else { t.input_border }; + ui.painter().rect(r, CornerRadius::same(4), fill, Stroke::new(1.0, border), egui::StrokeKind::Inside); + icons::paint(ui, "search", egui::Rect::from_center_size(r.left_center() + vec2(14.0, 0.0), vec2(14.0, 14.0)), t.icon); + let mut text_right = r.right() - 8.0; + if let Some(key) = self.key { + let at = egui::pos2(text_right - key.size().x, r.center().y - key.size().y / 2.0); + text_right = at.x - 12.0; + ui.painter().with_clip_rect(r).galley(at, key, t.text_dim); + } + let clip = egui::Rect::from_min_max(r.min, egui::pos2(text_right.max(r.left()), r.bottom())); + let at = egui::pos2(r.left() + Self::TEXT_LEFT, r.center().y - self.hint.size().y / 2.0); + ui.painter().with_clip_rect(clip).galley(at, self.hint, t.text_dim); + resp.widget_info(|| widgets::icon_button_info(ui.is_enabled(), open, name)); + resp.on_hover_text(tip) + } +} + /// Whether the window shows the system's title bar instead of the app drawing its own /// ([`VectorcraftApp::desktop_frame`]): Windows with Preferences › User Interface › System Title /// Bar, and Linux whenever the desktop draws the frame, with or without the preference. The diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index f1c63eafb4..f0ac33613b 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -159,6 +159,387 @@ fn hints_name_keys_as_the_menus_do() { } } +/// The widths of the app bar's right-hand group used by the fitting tests. +fn right_widths(room: f32, safe_mode: bool) -> super::RightWidths { + super::RightWidths { room, safe_mode, switcher: 150.0, field: 170.0, icon: 28.0, gap: 8.0, discord: 80.0 } +} + +/// What the group shows, in words, with the switcher's width as full, narrower or minimal. +fn right_stage(g: &super::RightGroup) -> String { + let switcher = match g.switcher_w { + _ if !g.switcher => "no switcher", + w if w >= 150.0 => "full switcher", + w if w > super::MIN_SWITCHER => "narrower switcher", + _ => "minimal switcher", + }; + format!("discord {}, learn {}, {:?}, {switcher}", g.discord, g.learn, g.search) +} + +/// As the app bar's room runs short, Discord goes first, then Explore tutorials, then the search +/// field becomes the icon, then the workspace switcher narrows to its minimum, then the icon goes. +/// Whatever shows fits in the room, down to the minimal switcher alone. +#[test] +fn the_app_bar_gives_up_its_right_hand_controls_in_order() { + let mut stages: Vec = Vec::new(); + for room in (0..=700).rev().map(|r| r as f32) { + let w = right_widths(room, false); + let g = super::fit_right_group(&w); + let stage = right_stage(&g); + if stages.last() != Some(&stage) { + stages.push(stage); + } + let search = match g.search { + super::Search::Field => w.gap + w.field, + super::Search::Icon => w.gap + w.icon, + super::Search::Hidden => 0.0, + }; + let learn = if g.learn { w.gap + w.icon } else { 0.0 }; + let discord = if g.discord { 10.0 + w.gap + w.discord } else { 0.0 }; + let used = g.switcher_w + 8.0 + search + learn + discord; + assert!(used <= room || g.switcher_w == super::MIN_SWITCHER && g.search == super::Search::Hidden, "{room}: {g:?} needs {used}"); + } + assert_eq!( + stages, + [ + "discord true, learn true, Field, full switcher", + "discord false, learn true, Field, full switcher", + "discord false, learn false, Field, full switcher", + "discord false, learn false, Icon, full switcher", + "discord false, learn false, Icon, narrower switcher", + "discord false, learn false, Icon, minimal switcher", + // Once the icon has gone, the switcher takes the room it leaves. + "discord false, learn false, Hidden, narrower switcher", + "discord false, learn false, Hidden, minimal switcher", + ] + ); + // In Safe Mode the label's width is taken first (not counted in `room`), and the switcher goes + // when a minimal one does not fit. + let safe = |room| right_stage(&super::fit_right_group(&right_widths(room, true))); + assert_eq!(safe(700.0), "discord true, learn true, Field, full switcher"); + assert_eq!(safe(72.0), "discord false, learn false, Hidden, minimal switcher"); + assert_eq!(safe(71.0), "discord false, learn false, Hidden, no switcher"); +} + +/// What screen readers call the app bar's search field, before its shortcut, and how the collapsed +/// icon's name starts. +const SEARCH_NAME: &str = "Search commands"; + +/// A native menu bar that draws nothing. +struct NoMenus; +impl crate::native_menu::Backend for NoMenus { + fn sync(&mut self, _: &crate::native_menu::MenuBar) {} + fn drain(&mut self) -> Vec { + Vec::new() + } +} + +/// The app bar drawn alone, `width` points wide. +struct AppBar { + app: crate::VectorcraftApp, + ctx: egui::Context, + width: f32, + /// Handle the app's keys before the bar and show the command palette after it, as the app's + /// frame does. Off, Tab moves the keyboard focus through the bar's controls, as with a screen + /// reader. + keys: bool, +} + +/// The app bar's search control, as a screen reader and the painter see it. +#[derive(Debug)] +struct SearchSeen { + name: String, + rect: egui::Rect, + texts: Vec, +} + +impl AppBar { + fn new(width: f32) -> AppBar { + crate::i18n::set_current(crate::i18n::Lang::EN); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + let app = crate::VectorcraftApp::new(Session::new(), Default::default()); + crate::shortcut_editor::sync(&app.ui); + AppBar { app, ctx, width, keys: false } + } + + /// One frame; the accessibility nodes and the texts painted, with where each is. + fn frame(&mut self, events: Vec) -> (Vec, Vec<(String, egui::Rect)>) { + fn walk(s: &egui::Shape, v: &mut Vec<(String, egui::Rect)>) { + match s { + egui::Shape::Text(t) => v.push((t.galley.text().to_string(), egui::Rect::from_min_size(t.pos, t.galley.size()))), + egui::Shape::Vec(s) => s.iter().for_each(|s| walk(s, v)), + _ => {} + } + } + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(self.width, 600.0)); + let (app, keys) = (&mut self.app, self.keys); + let mut out = self.ctx.run_ui(egui::RawInput { events, screen_rect: Some(screen), ..Default::default() }, |ui| { + if keys { + crate::shortcuts::handle(app, ui.ctx()); + } + super::app_bar(app, ui); + if keys { + crate::palette::show(app, ui.ctx()); + } + }); + out.textures_delta.clear(); + let mut texts = vec![]; + out.shapes.iter().for_each(|c| walk(&c.shape, &mut texts)); + (out.platform_output.accesskit_update.map(|u| u.nodes.into_iter().map(|(_, n)| n).collect()).unwrap_or_default(), texts) + } + + /// The search control after two frames, if the bar shows it. + fn search(&mut self) -> Option { + self.frame(vec![]); + let (nodes, texts) = self.frame(vec![]); + let node = nodes.iter().find(|n| n.label().is_some_and(|l| l.starts_with(SEARCH_NAME)))?; + let b = node.bounds()?; + let rect = egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32)); + // Without the icon set loaded, a test frame draws an icon as a warning sign; leave it out. + let mut texts: Vec<(String, egui::Rect)> = + texts.into_iter().filter(|(t, r)| rect.expand(0.5).contains_rect(*r) && !t.starts_with('\u{26a0}')).collect(); + texts.sort_by(|a, b| a.1.left().total_cmp(&b.1.left())); + let texts = texts.into_iter().map(|(t, _)| t).collect(); + Some(SearchSeen { name: node.label().unwrap_or_default().to_string(), rect, texts }) + } + + /// Where the in-window menus end: the right edge of the Help menu's title, if the bar shows it. + fn menus_end(&mut self) -> Option { + self.frame(vec![]); + let nodes = self.frame(vec![]).0; + nodes.iter().filter(|n| n.label() == Some("Help")).filter_map(|n| n.bounds()).map(|b| b.x1 as f32).reduce(f32::max) + } + + fn has(&mut self, name: &str) -> bool { + self.frame(vec![]); + self.frame(vec![]).0.iter().any(|n| n.label() == Some(name)) + } + + fn click(&mut self, at: egui::Pos2) { + let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + self.frame(vec![egui::Event::PointerMoved(at), press(true)]); + self.frame(vec![press(false)]); + } + + /// Whether the widget at `rect` has the keyboard focus. + fn focused_at(&self, rect: egui::Rect) -> bool { + self.ctx.memory(|m| m.focused()).and_then(|id| self.ctx.read_response(id)).is_some_and(|r| r.rect == rect) + } + + /// A press and release of `key`; Space also types a space, as a keyboard does. + fn key(&mut self, key: egui::Key) { + let event = |pressed| egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers: Default::default() }; + let mut press = vec![event(true)]; + if key == egui::Key::Space { + press.push(egui::Event::Text(" ".into())); + } + self.frame(press); + self.frame(vec![event(false)]); + } +} + +/// A wide app bar shows a search field with the palette's shortcut in it, and screen readers get a +/// button named [`SEARCH_NAME`] with the shortcut. +#[test] +fn a_wide_app_bar_shows_a_search_field_with_the_palette_shortcut() { + let mut bar = AppBar::new(1400.0); + let shortcut = crate::menus::shown_shortcut("Cmd+Shift+/"); + let seen = bar.search().expect("the search field shows"); + assert_eq!(seen.name, format!("{SEARCH_NAME} ({shortcut})")); + assert!(seen.rect.width() >= 120.0 && seen.rect.width() <= 220.0, "a field, not the 28-point icon: {seen:?}"); + assert_eq!(seen.texts, [SEARCH_NAME.to_string(), shortcut], "{seen:?}"); + assert!(bar.has("Explore tutorials")); +} + +/// The field shows the palette's shortcut as the user set it, and no shortcut once it is cleared. +#[test] +fn the_search_field_follows_the_palettes_shortcut() { + let mut bar = AppBar::new(1400.0); + crate::keymap::set_override(&mut bar.app.ui.shortcut_overrides, "help.commandPalette", "Alt+F9"); + crate::shortcut_editor::sync(&bar.app.ui); + let rebound = crate::menus::shown_shortcut("Alt+F9"); + let seen = bar.search().expect("the search field shows"); + assert_eq!(seen.name, format!("{SEARCH_NAME} ({rebound})")); + assert_eq!(seen.texts, [SEARCH_NAME.to_string(), rebound], "{seen:?}"); + crate::keymap::set_override(&mut bar.app.ui.shortcut_overrides, "help.commandPalette", ""); + crate::shortcut_editor::sync(&bar.app.ui); + let seen = bar.search().expect("the search field shows"); + assert_eq!(seen.name, SEARCH_NAME); + assert_eq!(seen.texts, [SEARCH_NAME], "{seen:?}"); + bar.app.ui.shortcut_overrides.clear(); + crate::shortcut_editor::sync(&bar.app.ui); +} + +/// A shortcut too long to sit beside "Search commands" in the widest field is left to the tooltip +/// and the screen-reader name, and "Search commands" stays readable. +#[test] +fn a_long_shortcut_leaves_the_search_hint_readable() { + crate::i18n::set_current(crate::i18n::Lang::EN); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let long = format!("Ctrl+Alt+Shift+{}", "PageDown".repeat(4)); + let mut fields = vec![]; + for _ in 0..2 { + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { + let t = Tokens::get(ui.ctx()); + fields = [Some("Ctrl+Shift+/".to_string()), Some(long.clone()), None] + .into_iter() + .map(|s| { + let f = super::SearchField::new(ui, &t, s); + (f.width, f.hint.size().x, f.key.as_ref().map(|k| k.size().x), f.shortcut.clone()) + }) + .collect(); + }); + out.textures_delta.clear(); + } + let [(short_w, hint, short_key, _), (long_w, _, long_key, long_shortcut), (none_w, _, none_key, _)] = &fields[..] else { + panic!("three fields: {fields:?}"); + }; + let short_key = short_key.expect("a short shortcut is shown"); + assert!(*short_w <= 220.0 && 26.0 + hint + 12.0 + short_key + 8.0 <= *short_w, "the hint and the shortcut fit side by side: {fields:?}"); + assert_eq!((*long_key, long_shortcut.as_deref()), (None, Some(long.as_str())), "a long one is left to the tooltip and the name"); + assert!(*long_w <= 220.0 && 26.0 + hint + 8.0 <= *long_w, "{fields:?}"); + assert!(none_key.is_none() && *none_w >= 120.0, "{fields:?}"); +} + +/// A click on the field, or on the icon it becomes in a narrow bar, opens the command palette with an +/// empty query, and a second click closes it, as the palette's shortcut does. While a dialog is open +/// neither does anything, as the shortcut does. +#[test] +fn a_click_on_the_search_field_opens_the_palette() { + for icon in [false, true] { + let mut bar = AppBar::new(1400.0); + if icon { + let narrow = (300..1400).rev().step_by(10).find(|w| { + bar.width = *w as f32; + bar.search().is_some_and(|s| s.rect.width() == 28.0) + }); + assert!(narrow.is_some(), "a narrow bar shows the icon"); + } + let at = bar.search().expect("the search control shows").rect.center(); + bar.app.ui.palette_query = "old".into(); + bar.click(at); + assert!(bar.app.ui.palette_open, "icon: {icon}"); + assert_eq!(bar.app.ui.palette_query, "", "icon: {icon}"); + bar.app.ui.palette_query = "typed".into(); + bar.click(at); + assert!(!bar.app.ui.palette_open, "a second click closes it (icon: {icon})"); + assert_eq!(bar.app.ui.palette_query, "", "icon: {icon}"); + bar.app.ui.dialog = Some(crate::state::Dialog::new("about", json!({}))); + bar.click(at); + assert!(!bar.app.ui.palette_open, "not over a dialog (icon: {icon})"); + } +} + +/// The keyboard focus reaches the field, Enter or Space opens the palette and does nothing else, and +/// Tab then moves the focus on. This holds with the app's keys handled, the palette drawn after the +/// bar, a document open, and an object selected with the Selection tool, whose Enter otherwise +/// opens Move. In the app, Tab with no field focused shows and hides the panels instead of moving +/// the focus, so the focus reaches the bar the way a screen reader moves it. +#[test] +fn the_keyboard_opens_the_palette_from_the_search_field() { + let cases = + [(egui::Key::Enter, 0), (egui::Key::Space, 0), (egui::Key::Enter, 1), (egui::Key::Space, 1), (egui::Key::Enter, 2), (egui::Key::Space, 2)]; + for (key, setup) in cases { + let document = setup > 0; + let mut bar = AppBar::new(1400.0); + let field = bar.search().expect("the search field shows").rect; + assert!(field.width() >= 120.0, "a field, not the icon: {field:?}"); + let mut reached = false; + for _ in 0..40 { + bar.key(egui::Key::Tab); + if bar.focused_at(field) { + reached = true; + break; + } + } + assert!(reached, "Tab reaches the search field"); + bar.keys = true; + if document { + bar.app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + } + if setup == 2 { + let id = bar.app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 30})).unwrap()["id"].clone(); + bar.app.select_tool("selection"); + bar.app.session.execute("select.set", &json!({"ids": [id]})).unwrap(); + } + // The app's keys leave the focus on the field. + bar.frame(vec![]); + assert!(bar.focused_at(field), "{key:?} (setup {setup})"); + assert!(!bar.app.ui.palette_open); + let status = bar.app.ui.status.clone(); + bar.key(key); + // The key opens the palette and goes no further: it does not pick the first result, type a + // space into the palette's field or open Move. + assert!(bar.app.ui.palette_open, "{key:?} opens the palette (setup {setup})"); + assert!(bar.app.ui.dialog.is_none(), "{key:?} opened no dialog (setup {setup})"); + assert_eq!(bar.app.ui.palette_query, "", "{key:?} (setup {setup})"); + assert!(bar.app.ui.recent_commands.is_empty() && bar.app.ui.status == status, "{key:?} ran nothing (setup {setup})"); + } + // Tab moves the focus off the field with the app's keys handled. + let mut bar = AppBar::new(1400.0); + let field = bar.search().expect("the search field shows").rect; + for _ in 0..40 { + if bar.focused_at(field) { + break; + } + bar.key(egui::Key::Tab); + } + assert!(bar.focused_at(field), "Tab reaches the search field at {field:?}"); + bar.keys = true; + let panels = (bar.app.ui.dock, bar.app.ui.toolbar); + bar.key(egui::Key::Tab); + assert!(!bar.focused_at(field), "Tab leaves the field"); + assert_eq!((bar.app.ui.dock, bar.app.ui.toolbar), panels, "Tab on the field does not hide the panels"); +} + +/// As the window narrows, the search field becomes the icon after Explore tutorials has gone and +/// before the icon goes, never overlapping the menus: with a long workspace name, with the menus in +/// the system's menu bar, and with the window's own caption buttons. +#[test] +fn a_narrowing_app_bar_turns_the_search_field_into_the_icon() { + for case in ["default", "long workspace name", "native menus", "caption buttons"] { + let mut bar = AppBar::new(1400.0); + match case { + "long workspace name" => bar.app.ui.workspace = "A workspace with a very long name indeed".into(), + "native menus" => bar.app.services.native_menu = Some(crate::native_menu::NativeMenu::new(Box::new(NoMenus))), + "caption buttons" => bar.app.custom_titlebar = true, + _ => {} + } + assert_eq!(bar.menus_end().is_some(), case != "native menus", "{case}: the in-window menus show"); + // 0: gone, 1: icon, 2: field. + let mut last = 2; + let mut seen_icon = false; + for width in (300..=1400).rev().step_by(10) { + bar.width = width as f32; + let learn = bar.has("Explore tutorials"); + let search = bar.search(); + let now = match &search { + Some(s) if s.rect.width() >= 120.0 => 2, + Some(s) => { + assert_eq!(s.rect.width(), 28.0, "{case} at {width}"); + assert!(s.texts.is_empty(), "the icon has no text: {case} at {width}"); + 1 + } + None => 0, + }; + assert!(width < 1400 || now == 2, "{case}: a wide bar shows the field"); + assert!(now <= last, "{case} at {width}: the search came back as the bar narrowed"); + assert!(!learn || now == 2, "{case} at {width}: Explore tutorials outlasted the field"); + if let Some(s) = &search { + assert!(s.rect.right() <= width as f32, "{case} at {width}: {s:?}"); + if let Some(menus_end) = bar.menus_end() { + assert!(s.rect.left() >= menus_end, "{case} at {width}: the search overlaps the menus ending at {menus_end}: {s:?}"); + } + } + seen_icon |= now == 1; + last = now; + } + assert!(seen_icon, "{case}: the field becomes the icon before it goes"); + } +} + #[derive(Debug)] struct StatusText { text: String, diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 71e443a399..2ea516f550 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -3182,6 +3182,7 @@ digits Malayalam Малаялам Scripts Скриптове Search Търсене Search All Търсене във всички + Search commands Търсене на команди Search commands and tools Търсене на команди и инструменти Search commands and tools… Търсене на команди и инструменти… Recent Commands Последни команди diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 883d6dd387..620d5edd19 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -1300,6 +1300,7 @@ lighting Light Svjetlo Name* @ 66.67% (RGB/Preview) Naziv* @ 66,67% (RGB/pregled) No Document Nema dokumenta Press Pritisnite + Search commands Pretraži naredbe Search commands and tools Pretraži naredbe i alate Style: Stil: Switch workspace Promijeni radni prostor diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index a8a63cbf55..1a4208cc01 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -4110,6 +4110,7 @@ digits Malayalam Malaiàlam Scrub Numeric Fields by Dragging Canvia els camps numèrics arrossegant Search Cerca Search All Cerca a tot + Search commands Cerca ordres Search commands and tools Cerca ordres i eines Search commands and tools… Cerca ordres i eines… Recent Commands Ordres recents diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 569b1347ec..02f5b97abc 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -1324,6 +1324,7 @@ lighting Light Světlo Name* @ 66.67% (RGB/Preview) Název* @ 66,67 % (RGB/náhled) No Document Žádný dokument Press Klávesou + Search commands Hledat příkazy Search commands and tools Hledat příkazy a nástroje Style: Styl: Switch workspace Přepnout pracovní prostor diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 4578e4efc1..9733b65591 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -3901,6 +3901,7 @@ lighting Light Lys Name* @ 66.67% (RGB/Preview) Navn* @ 66.67% (RGB/forhåndsvisning) No Document Intet dokument Press Tryk på + Search commands Søg i kommandoer Search commands and tools Søg i kommandoer og værktøjer Style: Typografi: Switch workspace Skift arbejdsområde diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index c943c89dd2..8a262a0d66 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -3246,6 +3246,7 @@ digits Malayalam Malayalam Filter Layers Panel Rows Zeilen im Ebenenbedienfeld filtern @msg `Custom` stands for changed settings: save the preset under another name `Custom` steht für geänderte Einstellungen: Speichern Sie die Vorgabe unter einem anderen Namen @msg `{key}` must be an array of these names: {_1} `{key}` muss ein Array mit diesen Namen sein: {_1} + Search commands Befehle suchen Search commands and tools Befehle und Werkzeuge suchen Search commands and tools… Befehle und Werkzeuge suchen… Recent Commands Zuletzt verwendete Befehle diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 906640aa0a..0fc84a4f9a 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -3948,6 +3948,7 @@ digits Malayalam Μαλαγιάλαμ Scribble… Μουτζούρωμα… Script / Brush Σενάριο / Πινέλο Search All Αναζήτηση όλων + Search commands Αναζήτηση εντολών Search commands and tools Αναζήτηση εντολών και εργαλείων Search commands and tools… Αναζήτηση εντολών και εργαλείων… Recent Commands Πρόσφατες εντολές diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 9239c93a73..f6c7c0e152 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -3284,6 +3284,7 @@ digits Malayalam Malayálam Filter Layers Panel Rows Filtrar filas del panel Capas @msg `Custom` stands for changed settings: save the preset under another name `Custom` representa ajustes modificados: guarda el preajuste con otro nombre @msg `{key}` must be an array of these names: {_1} `{key}` debe ser una lista de estos nombres: {_1} + Search commands Buscar comandos Search commands and tools Buscar comandos y herramientas Search commands and tools… Buscar comandos y herramientas… Recent Commands Comandos recientes diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 423703e5c1..e971f1fe79 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -1302,6 +1302,7 @@ lighting Light Valo Name* @ 66.67% (RGB/Preview) Nimi* @ 66.67% (RGB/esikatselu) No Document Ei asiakirjaa Press Paina + Search commands Hae komentoja Search commands and tools Hae komentoja ja työkaluja Style: Tyyli: Switch workspace Vaihda työtilaa diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 8af602785b..4a89f385bf 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -3272,6 +3272,7 @@ digits Malayalam Malayalam Filter Layers Panel Rows Filtrer les lignes du panneau Calques @msg `Custom` stands for changed settings: save the preset under another name `Custom` désigne des réglages modifiés : enregistrez le paramètre prédéfini sous un autre nom @msg `{key}` must be an array of these names: {_1} `{key}` doit être un tableau de noms parmi {_1} + Search commands Chercher des commandes Search commands and tools Chercher commandes et outils Search commands and tools… Chercher commandes et outils… Recent Commands Commandes récentes diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 4eed343e3d..d8caa0e6b1 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -3388,6 +3388,7 @@ Search Commands… આદેશો શોધો… Search Fonts Folder ફોન્ટ ફોલ્ડર શોધો Search Preferences પસંદગીઓ શોધો + Search commands આદેશો શોધો Search commands and tools આદેશો અને ટૂલ્સ શોધો Search commands and tools… આદેશો અને ટૂલ્સ શોધો… Recent Commands તાજેતરના આદેશો diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index de33cdbd92..164537497d 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -4462,6 +4462,7 @@ antiAlias Sharp शार्प Search खोजें Search All सभी खोजें Search artboards खोज आर्टबोर्ड + Search commands आदेश खोजें Search commands and tools खोज आदेश और टूल Search commands and tools… आदेश और टूल खोजें… Recent Commands हाल के आदेश diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index f869e7d07b..9c856323ce 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -3904,6 +3904,7 @@ mark-style Japanese Japán Filter Layers Panel Rows Rétegek panel sorainak szűrése @msg `Custom` stands for changed settings: save the preset under another name a `Custom` a módosított beállításokat jelöli: mentsd az előbeállítást más néven @msg `{key}` must be an array of these names: {_1} `{key}`: ezen nevek tömbje kell: {_1} + Search commands Parancsok keresése Search commands and tools Parancsok és eszközök keresése Search commands and tools… Parancsok és eszközök keresése… Recent Commands Legutóbbi parancsok diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index c5f865e69b..0c5b65e7f0 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -1227,6 +1227,7 @@ lighting Light Cahaya Name* @ 66.67% (RGB/Preview) Nama* @ 66.67% (RGB/Pratinjau) No Document Tidak ada dokumen Press Tekan + Search commands Cari perintah Search commands and tools Cari perintah dan alat Style: Gaya: Switch workspace Ganti ruang kerja diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 08cefdbed7..c4e2f39dc4 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -3327,6 +3327,7 @@ digits Malayalam Malayalam Filter Layers Panel Rows Filtra righe del pannello Livelli @msg `Custom` stands for changed settings: save the preset under another name `Custom` indica impostazioni modificate: salva il preset con un altro nome @msg `{key}` must be an array of these names: {_1} `{key}` deve essere un array di questi nomi: {_1} + Search commands Cerca comandi Search commands and tools Cerca comandi e strumenti Search commands and tools… Cerca comandi e strumenti… Recent Commands Comandi recenti diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 59c7628f40..bd1c00f4ae 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -3204,6 +3204,7 @@ mark-style Japanese 日本式 Filter Layers Panel Rows レイヤーパネルの行をフィルター @msg `Custom` stands for changed settings: save the preset under another name `Custom` は変更した設定を表します: プリセットを別の名前で保存してください @msg `{key}` must be an array of these names: {_1} `{key}` には {_1} の中の名前の配列を指定してください + Search commands コマンドを検索 Search commands and tools コマンドとツールを検索 Search commands and tools… コマンドとツールを検索… Recent Commands 最近使ったコマンド diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 9393433cdb..6589d60e98 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -3269,6 +3269,7 @@ lighting Light სინათლე Name* @ 66.67% (RGB/Preview) სახელი* @ 66.67% (RGB/წინასწარი ნახვა) No Document დოკუმენტი არ არის Press დააჭირეთ + Search commands ბრძანებების ძიება Search commands and tools ბრძანებებისა და ხელსაწყოების ძიება Style: სტილი: Switch workspace სამუშაო სივრცის გადართვა diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 49d5e10dc1..13860e91b9 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -3193,6 +3193,7 @@ mark-style Japanese 일본식 Filter Layers Panel Rows 레이어 패널 행 필터링 @msg `Custom` stands for changed settings: save the preset under another name `Custom`은 변경된 설정을 나타냅니다. 프리셋을 다른 이름으로 저장하세요 @msg `{key}` must be an array of these names: {_1} `{key}`은(는) 다음 이름의 배열이어야 합니다: {_1} + Search commands 명령 검색 Search commands and tools 명령 및 도구 검색 Search commands and tools… 명령 및 도구 검색… Recent Commands 최근 명령 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index f071ebd0e2..9f165efd14 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -1795,6 +1795,7 @@ lighting Light Licht Name* @ 66.67% (RGB/Preview) Naam* @ 66.67% (RGB/Voorbeeld) No Document Geen document Press Druk op + Search commands Opdrachten zoeken Search commands and tools Opdrachten en gereedschappen zoeken Style: Stijl: Switch workspace Werkruimte wisselen diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 2477c73abd..20e2f86d10 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -1254,6 +1254,7 @@ lighting Light Światło Name* @ 66.67% (RGB/Preview) Nazwa* @ 66,67% (RGB/Podgląd) No Document Brak dokumentu Press Naciśnij + Search commands Szukaj poleceń Search commands and tools Szukaj poleceń i narzędzi Style: Styl: Switch workspace Przełącz obszar roboczy diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 333351b9af..0d95825dde 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -2742,6 +2742,7 @@ digits Malayalam Malaiala @msg `Custom` stands for changed settings: save the preset under another name `Custom` representa configurações alteradas: salve a predefinição com outro nome @msg `{key}` must be an array of these names: {_1} `{key}` deve ser uma matriz destes nomes: {_1} Search Commands… Pesquisar Comandos… + Search commands Pesquisar comandos Search commands and tools Pesquisar comandos e ferramentas Search commands and tools… Pesquisar comandos e ferramentas… Recent Commands Comandos recentes diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index ae33aa0d55..3dfaa07482 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -3316,6 +3316,7 @@ digits Malayalam Малаялам Filter Layers Panel Rows Фильтровать строки панели «Слои» @msg `Custom` stands for changed settings: save the preset under another name `Custom` обозначает изменённые параметры: сохраните набор под другим именем @msg `{key}` must be an array of these names: {_1} `{key}` должно быть массивом из этих имён: {_1} + Search commands Поиск команд Search commands and tools Поиск команд и инструментов Search commands and tools… Поиск команд и инструментов… Recent Commands Недавние команды diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 1bd4fd0692..248adc3ec7 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -3202,6 +3202,7 @@ digits Malayalam Malayalam Scripts Skript Search Sök Search All Sök i alla + Search commands Sök kommandon Search commands and tools Sök kommandon och verktyg Search commands and tools… Sök kommandon och verktyg… Recent Commands Senaste kommandon diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index a2a38c679a..c8ff293ebb 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -3074,6 +3074,7 @@ digits Malayalam Malayalam Redefine {name} “{name}” Stilini Yeniden Tanımla @msg `Custom` stands for changed settings: save the preset under another name `Custom` değiştirilmiş ayarları ifade eder: ön ayarı başka bir adla kaydedin @msg `{key}` must be an array of these names: {_1} `{key}` şu adlardan oluşan bir dizi olmalıdır: {_1} + Search commands Komutları arayın Search commands and tools Komutları ve araçları arayın Search commands and tools… Komutları ve araçları arayın… Recent Commands Son komutlar diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 17c673885d..c4e95fd2db 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -3319,6 +3319,7 @@ digits Malayalam Малаялам Filter Layers Panel Rows Фільтрувати рядки панелі «Шари» @msg `Custom` stands for changed settings: save the preset under another name `Custom` позначає змінені параметри: збережіть набір під іншим ім’ям @msg `{key}` must be an array of these names: {_1} `{key}` має бути масивом цих назв: {_1} + Search commands Пошук команд Search commands and tools Пошук команд та інструментів Search commands and tools… Пошук команд та інструментів… Recent Commands Нещодавні команди diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index da89525314..6c79308d93 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -3661,6 +3661,7 @@ mark-style Japanese Kiểu Nhật Filter Layers Panel Rows Lọc hàng bảng Lớp @msg `Custom` stands for changed settings: save the preset under another name `Custom` biểu thị các cài đặt đã thay đổi: hãy lưu thiết lập sẵn với tên khác @msg `{key}` must be an array of these names: {_1} `{key}` phải là một mảng gồm các tên sau: {_1} + Search commands Tìm kiếm lệnh Search commands and tools Tìm kiếm lệnh và công cụ Search commands and tools… Tìm kiếm lệnh và công cụ… Recent Commands Lệnh gần đây diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 5f612cb0d4..1e318d4001 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -3146,6 +3146,7 @@ digits Malayalam 马拉雅拉姆数字 Locked 已锁定 Hidden 已隐藏 Filter Layers Panel Rows 筛选图层面板行 + Search commands 搜索命令 Search commands and tools 搜索命令和工具 Search commands and tools… 搜索命令和工具… Recent Commands 最近使用的命令 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index e0b5a13ee2..e2f1a7950c 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -4452,6 +4452,7 @@ digits Malayalam 馬來亞拉姆數字 Locked 已鎖定 Hidden 已隱藏 Filter Layers Panel Rows 篩選圖層面板列 + Search commands 搜尋指令 Search commands and tools 搜尋指令與工具 Search commands and tools… 搜尋指令與工具… Recent Commands 最近使用的指令 diff --git a/crates/ui-egui/src/panels/learn/tests.rs b/crates/ui-egui/src/panels/learn/tests.rs index 319ca1decf..21486d4b1a 100644 --- a/crates/ui-egui/src/panels/learn/tests.rs +++ b/crates/ui-egui/src/panels/learn/tests.rs @@ -104,10 +104,10 @@ fn explore_tutorials_on_the_app_bar_shows_and_hides_the_learn_panel() { let ctx = context(); assert!(!shown(&app)); let nodes = frame(&mut app, &ctx, vec![], app_bar); - let search = center_where(&nodes, |label| label.starts_with("Search commands and tools")); + let search = center_where(&nodes, |label| label.starts_with("Search commands")); let learn = center(&nodes, "Explore tutorials"); - let (search, learn) = (search.expect("the search icon shows"), learn.expect("the app bar has Explore tutorials")); - assert!(learn.x < search.x && (learn.y - search.y).abs() < 1.0, "beside the search icon: {learn:?}, {search:?}"); + let (search, learn) = (search.expect("the search field shows"), learn.expect("the app bar has Explore tutorials")); + assert!(learn.x < search.x && (learn.y - search.y).abs() < 1.0, "beside the search field: {learn:?}, {search:?}"); click(&mut app, &ctx, "Explore tutorials", app_bar); assert!(shown(&app), "{}", app.ui.status); click(&mut app, &ctx, "Explore tutorials", app_bar); diff --git a/docs/development.md b/docs/development.md index 64b66678b5..2b1a3d7d87 100644 --- a/docs/development.md +++ b/docs/development.md @@ -111,7 +111,7 @@ When the interface thread stays in one part of a frame for 3 s (VectorCraft's ow ## macOS: the menu bar -On macOS the menus live in the system menu bar, not in the window's app bar (which keeps the brand mark, Home, the search icon and the workspace switcher next to the traffic lights, centred on the bar by `apps/vectorcraft/src/mac_window.rs`). `--in-window-menus` or `VECTORCRAFT_IN_WINDOW_MENUS=1` keeps them in the window, as on Windows, Linux and the web; so does a menu bar AppKit refuses to build (logged). `ui.inspect` says which with `nativeMenuBar`. +On macOS the menus live in the system menu bar, not in the window's app bar (which keeps the brand mark, Home, the search field and the workspace switcher next to the traffic lights, centred on the bar by `apps/vectorcraft/src/mac_window.rs`). `--in-window-menus` or `VECTORCRAFT_IN_WINDOW_MENUS=1` keeps them in the window, as on Windows, Linux and the web; so does a menu bar AppKit refuses to build (logged). `ui.inspect` says which with `nativeMenuBar`. - **One menu model.** `crates/ui-egui/src/native_menu.rs` (platform-free, tested on every platform) builds the menu bar from the in-window menus (`menus::menu_tree`, each item through `menus::entry`, which the in-window menus draw too) and lays it out the Mac way: the VectorCraft menu holds About, Settings ▸ (one item per Preferences page, General… ⌘K), Language ▸, Appearance ▸ (UI brightness), Services, Hide VectorCraft ⌃⌘H (⌘H stays View › Hide Edges), Hide Others ⌥⌘H, Show All and Quit ⌘Q (the app's own `app.quit`, so unsaved documents are asked about); those leave Edit and Help. The in-window bar itself never shows the VectorCraft menu (it starts at File, as in Illustrator, on every platform): Language and Appearance have no in-window menu and are synthesized in `mac_layout`, and Quit is File › Exit in the window, relabelled to Quit in the App menu. Window starts with Minimize ⌃⌘M and Zoom and ends with Bring All to Front, and Help is the system's Help menu (its search field). A system key a command (or a user's shortcut) already has stays the command's, and the log says so. - **The native side** is `apps/vectorcraft/src/mac_menu.rs`: muda (`=0.21.1`, default features off, macOS only, no `unsafe`) builds the `NSMenu`s. Labels, enabled and checked are updated in place when anything they show may have changed (a command ran, the document, its history or selection changed, a click or a key press); a change of structure (a recent file, the language, a shortcut) rebuilds the menus. While an interaction is open (for example a move, scale or shape drag, a dialog's preview or the font menu's preview), the app updates them for the document's changes only when the interaction begins and when it ends. diff --git a/docs/mcp.md b/docs/mcp.md index c7aa202d3f..e2de2d90df 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3212,7 +3212,7 @@ own layout rules. ## Learn panel -Window › Learn and the Explore tutorials button beside the search icon at the right end of the app bar show and hide +Window › Learn and the Explore tutorials button beside the search field at the right end of the app bar show and hide the Learn panel. Its For you tab holds a Get started section with a Quick skill guide card; choosing the card opens the Skills tab. The Skills tab lists VectorCraft's own skills, each with a progress ring and the count of its tutorials finished of all its tutorials. Choosing a skill lists its tutorials, choosing a tutorial shows its numbered steps, and diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 0782bacab9..a4585db2f7 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1017,7 +1017,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - The Free Transform widget's Constrain works in Free Distort as well as in Free Transform ([the help page](https://helpx.adobe.com/illustrator/using/tool-techniques/free-transform-tool.html)). With Constrain on, or Shift held, a corner dragged in Free Distort moves only along the line through the opposite corner, in the box's own proportions, and the other three corners stay in place; on a turned box the line runs through the box's own corners. The line is VectorCraft's own rule. Cmd/Ctrl+Alt+Shift on a corner still drags in Perspective Distort, where Constrain stays unavailable (tools `xform::free::tests::free_distort_corner_keeps_to_its_diagonal_with_shift_or_constrain`, `shift_pressed_during_a_free_distort_drag_constrains_it`, `a_turned_box_is_constrained_along_its_own_diagonal`, `along_diagonal_of_a_degenerate_box`; engine `xform::free_transform_constrained_distort_keeps_the_corner_on_its_diagonal`; ui-egui `free_transform::tests::the_widget_sets_the_mode_and_a_corner_drag_then_distorts`). - Native macOS menu bar, vector tool cursors, a command palette (Help › Search Commands…), middle-button panning with any tool. Native menus explicitly end tracking on command selection, outside window presses and Escape; menu updates wait until tracking ends, and a dismissing press never starts a canvas gesture (M14.8). - A Recent Commands button beside the Help › Search Commands field lists the last five commands and tools picked from the palette, most recent first, with a command picked again moved to the top. Choosing a row closes the palette and runs it as a pick of the same result does; with no picks yet the list shows a dimmed No recent commands row, and a command that is not available now, such as a filter of a plug-in that is not loaded, is left out until it comes back. The ids are saved with the UI state. While the list is open, Up and Down move through its rows, wrapping at the ends, and Escape closes the list before the palette. This is VectorCraft's own addition and does not raise a score (#6376; `palette` tests `recent_commands_*`, `a_recent_command_runs_what_its_pick_runs`, `the_keys_wrap_within_recent_commands`, `escape_closes_recent_commands_before_the_palette`). - - The Learn panel (Window › Learn, or Explore tutorials beside the search icon on the app bar) has a For you tab with a Get started section and a Quick skill guide card, and a Skills tab that lists VectorCraft's own skills with their progress rings and counts of tutorials finished; a skill lists its tutorials, a tutorial shows its numbered steps, and Back goes up a level; `learn.list`, `learn.tab {tab}`, `learn.skill {skill}`, `learn.show {tutorial}` and `learn.back` script it, and the tab buttons, the rows and Back run them ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html); `panels::learn::tests`). + - The app bar's search control is a field showing a magnifier, "Search commands" and the Help › Search Commands… shortcut. The field shows no shortcut when the shortcut is cleared or too long to fit beside the text; the tooltip and the screen-reader name still give it. A click on the field, or Enter or Space while it has the keyboard focus, toggles the command palette as the shortcut does, and the palette's popup holds the text field. While the field has the focus, the app's own keys stay off, so Enter does not open Move and Tab moves the focus on. While a dialog is open the field and the icon do nothing, as the shortcut does. Screen readers name the field Search commands, with the shortcut. As the bar narrows, the community button goes first, then Explore tutorials, then the field becomes the magnifier icon, then the workspace switcher narrows to 64 points, then the icon goes; Safe Mode's label keeps its room first. This is VectorCraft's own addition and does not raise a score (`chrome::tests`: `the_app_bar_gives_up_its_right_hand_controls_in_order`, `a_wide_app_bar_shows_a_search_field_with_the_palette_shortcut`, `the_search_field_follows_the_palettes_shortcut`, `a_long_shortcut_leaves_the_search_hint_readable`, `a_click_on_the_search_field_opens_the_palette`, `the_keyboard_opens_the_palette_from_the_search_field`, `a_narrowing_app_bar_turns_the_search_field_into_the_icon`). + - The Learn panel (Window › Learn, or Explore tutorials beside the search field on the app bar) has a For you tab with a Get started section and a Quick skill guide card, and a Skills tab that lists VectorCraft's own skills with their progress rings and counts of tutorials finished; a skill lists its tutorials, a tutorial shows its numbered steps, and Back goes up a level; `learn.list`, `learn.tab {tab}`, `learn.skill {skill}`, `learn.show {tutorial}` and `learn.back` script it, and the tab buttons, the rows and Back run them ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html); `panels::learn::tests`). - A tool's name in a Learn tutorial step is a blue link that shows where the tool is without choosing it (`learn.locateTool {tool}`): its toolbar button is marked, a collapsed group's flyout opens with the tool's row marked, a torn-off strip comes to the front, and a tool no shown toolbar holds is marked in the All Tools drawer. The mark, its 3 seconds and the hidden-toolbar cases are VectorCraft's own rules ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html); `panels::learn::tests`, the `a_learn_link_*` tests in `toolbar::tests`). - Under a tutorial's steps, View more opens the tutorial's own practice sample as a new untitled document, and once the tutorial is finished, Next Up moves to the next tutorial in the same skill, as the help page describes ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html)). The samples are VectorCraft's own drawings. A Finish tutorial button that shows once the sample is open, the untitled copy, Back to skills in place of Next Up after a skill's last tutorial, and Next Up showing the next tutorial without opening its sample are VectorCraft's own rules. `learn.openSample`, `learn.finish`, `learn.next` and `learn.skills` (Back to skills) script them. Not done: the help page's short video. Regression tests: `view_more_opens_the_tutorial_s_sample_as_a_new_untitled_document`, `finishing_a_tutorial_offers_next_up_in_its_skill`, `the_practice_controls_work_from_the_keyboard`, `the_last_tutorial_of_a_skill_offers_back_to_skills`, `learn_finish_and_learn_next_follow_the_practice`, `learn_skills_shows_the_list_of_skills`, `the_practice_commands_reject_a_missing_or_unknown_tutorial`, `every_tutorial_has_its_own_readable_sample` and `the_next_tutorial_is_the_next_one_in_the_same_skill` in `crates/ui-egui/src/panels/learn/tests.rs`. - A Learn tutorial's steps are marked complete as the learner works, and a skill's progress ring fills as its tutorials are finished, as the help page describes ([the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html)). Each step has a check box that marks it done once the tutorial's sample is open (`learn.markStep`); Finish tutorial marks every step done; a skill's count shows its tutorials finished of all, and a finished tutorial has a check mark in its skill's list. Marking steps by hand, the count, keeping the progress in the preferences (the web build keeps it while the page is open) and Reset progress (`learn.resetProgress`) are VectorCraft's own rules; `learn.list` reports the progress. Regression tests: `a_step_s_check_box_marks_only_that_step`, `a_step_s_check_box_works_from_the_keyboard`, `finishing_tutorials_fills_their_skill_s_ring_and_count`, `a_skill_with_no_tutorials_shows_0_of_0`, `learn_mark_step_checks_its_params`, `reset_progress_clears_only_the_progress`, `the_preferences_keep_the_progress` and `saved_progress_is_read_leniently` in `crates/ui-egui/src/panels/learn/tests.rs`.