Merge pull request #8085 from dotCooCoo/feat/app-bar-search-field

App bar: a search field in place of the search icon
This commit is contained in:
BFlat authored and GitHub committed 2026-11-17 11:45:15 +07:00
commit 42193ed3ca
38 files changed
+635 -39

No files matched your search

+174 -25
View File
@@ -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,
community: crate::community::discord_width(ui, false),
});
let (switcher, ws_w, learn, discord) = (fit.switcher, fit.switcher_w, fit.learn, fit.community);
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,33 @@ 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, tools, panels and effects"), menus::shown_shortcut(sc)),
None => tl!("Search commands, tools, panels and effects").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, tools, panels and effects"));
let name = with_shortcut(tl!("Search commands"));
// The field and the icon toggle the palette as its shortcut does, and like the shortcut
// they do nothing while a dialog is open, so they are drawn disabled then.
let enabled = app.ui.dialog.is_none();
let open = app.ui.palette_open;
let clicked = ui
.add_enabled_ui(enabled, |ui| match fit.search {
Search::Field => field.show(ui, &t, &name, &tip, open).clicked(),
Search::Icon => {
let (_, resp) = ui.allocate_exact_size(vec2(BAR_ICON, BAR_ICON), Sense::click());
widgets::paint_icon_button_named(ui, resp, "search", &name, &tip, open).clicked()
}
Search::Hidden => false,
})
.inner;
if clicked && enabled {
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 +181,142 @@ 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,
/// Whether the bar shows the Safe Mode label.
safe_mode: bool,
/// The workspace switcher's full width.
switcher: f32,
/// The search field's width.
field: f32,
/// The side of a square icon button.
icon: f32,
/// The space between two controls.
gap: f32,
/// The community button's width.
community: f32,
}
/// What the right-hand group of the app bar shows.
#[derive(Clone, Copy, Debug, PartialEq)]
struct RightGroup {
/// Whether the workspace switcher shows.
switcher: bool,
/// The workspace switcher's width.
switcher_w: f32,
/// How the search shows.
search: Search,
/// Whether Explore tutorials shows.
learn: bool,
/// Whether the community button shows.
community: 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 community = learn && room >= learn_end + 10.0 + w.gap + w.community;
RightGroup { switcher, switcher_w, search, learn, community }
}
/// 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<egui::Galley>,
/// The palette's shortcut as the menus show it; none when the user cleared it.
shortcut: Option<String>,
key: Option<Arc<egui::Galley>>,
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<String>) -> 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
+406
View File
@@ -159,6 +159,412 @@ 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, community: 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!("community {}, learn {}, {:?}, {switcher}", g.community, g.learn, g.search)
}
/// As the app bar's room runs short, the community button 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<String> = 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 community = if g.community { 10.0 + w.gap + w.community } else { 0.0 };
let used = g.switcher_w + 8.0 + search + learn + community;
assert!(used <= room || g.switcher_w == super::MIN_SWITCHER && g.search == super::Search::Hidden, "{room}: {g:?} needs {used}");
}
assert_eq!(
stages,
[
"community true, learn true, Field, full switcher",
"community false, learn true, Field, full switcher",
"community false, learn false, Field, full switcher",
"community false, learn false, Icon, full switcher",
"community false, learn false, Icon, narrower switcher",
"community false, learn false, Icon, minimal switcher",
// Once the icon has gone, the switcher takes the room it leaves.
"community false, learn false, Hidden, narrower switcher",
"community 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), "community true, learn true, Field, full switcher");
assert_eq!(safe(72.0), "community false, learn false, Hidden, minimal switcher");
assert_eq!(safe(71.0), "community false, learn false, Hidden, no switcher");
}
/// What screen readers call the app bar's search field, and the icon it becomes, before the shortcut.
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<crate::native_menu::Event> {
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<String>,
}
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<egui::Event>) -> (Vec<egui::accesskit::Node>, 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<SearchSeen> {
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<f32> {
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 icon a narrow bar shows has the field's screen-reader name, and while a dialog is open screen
/// readers find the field and the icon disabled.
#[test]
fn the_search_icon_has_the_fields_name_and_both_are_disabled_under_a_dialog() {
let shortcut = crate::menus::shown_shortcut("Cmd+Shift+/");
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 disabled = |bar: &mut AppBar| {
bar.frame(vec![]);
let nodes = bar.frame(vec![]).0;
let node = nodes.iter().find(|n| n.label().is_some_and(|l| l.starts_with(SEARCH_NAME))).expect("the search control shows");
(node.label().unwrap_or_default().to_string(), node.is_disabled())
};
assert_eq!(disabled(&mut bar), (format!("{SEARCH_NAME} ({shortcut})"), false), "icon: {icon}");
bar.app.ui.dialog = Some(crate::state::Dialog::new("about", json!({})));
assert_eq!(disabled(&mut bar), (format!("{SEARCH_NAME} ({shortcut})"), true), "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,
+1
View File
@@ -3201,6 +3201,7 @@ digits Malayalam Малаялам
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} от {n} резултат. Продължете да пишете, за да ги стесните.|{shown} от {n} резултата. Продължете да пишете, за да ги стесните.
Recent Commands Последни команди
No recent commands Няма последни команди
Search commands Търсене на команди
Search Commands… Търсене на команди…
Secondary Вторичен
Section Symbol Символ за раздел
Can't render this file because it is too large.
+1
View File
@@ -1304,6 +1304,7 @@ lighting Light Svjetlo
Search commands, tools, panels and effects Pretraži naredbe, alate, panele i efekte
Style: Stil:
Switch workspace Promijeni radni prostor
Search commands Pretraži naredbe
Show all open documents Prikaži sve otvorene dokumente
Use Koristite
the object to select | objekat za odabir |
Can't render this file because it contains an unexpected character in line 2 and column 73.
+1
View File
@@ -4130,6 +4130,7 @@ digits Malayalam Malaiàlam
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} de {n} resultat. Continueu escrivint per reduir-los.|{shown} de {n} resultats. Continueu escrivint per reduir-los.
Recent Commands Ordres recents
No recent commands No hi ha ordres recents
Search commands Cerca ordres
Search Commands… Cerca ordres…
Search Fonts Folder Cerca a la carpeta de tipus de lletra
Searching… Cercant…
Can't render this file because it contains an unexpected character in line 2 and column 73.
+1
View File
@@ -1328,6 +1328,7 @@ lighting Light Světlo
Search commands, tools, panels and effects Hledat příkazy, nástroje, panely a efekty
Style: Styl:
Switch workspace Přepnout pracovní prostor
Search commands Hledat příkazy
Show all open documents Zobrazit všechny otevřené dokumenty
Use Příkazem
the object to select | na objekt jej vybere |
Can't render this file because it is too large.
+1
View File
@@ -3925,6 +3925,7 @@ lighting Light Lys
Search commands, tools, panels and effects Søg i kommandoer, værktøjer, paneler og effekter
Style: Typografi:
Switch workspace Skift arbejdsområde
Search commands Søg i kommandoer
Show all open documents Vis alle åbne dokumenter
Use Brug
the object to select | på objektet for at markere det |
Can't render this file because it is too large.
+1
View File
@@ -3265,6 +3265,7 @@ digits Malayalam Malayalam
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} von {n} Ergebnis. Tippen Sie weiter, um sie einzugrenzen.|{shown} von {n} Ergebnissen. Tippen Sie weiter, um sie einzugrenzen.
Recent Commands Zuletzt verwendete Befehle
No recent commands Keine zuletzt verwendeten Befehle
Search commands Befehle suchen
Search Commands… Befehle suchen…
Secondary Sekundär
Section Symbol Paragrafenzeichen
Can't render this file because it is too large.
+1
View File
@@ -3967,6 +3967,7 @@ digits Malayalam Μαλαγιάλαμ
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} από {n} αποτέλεσμα. Συνεχίστε να πληκτρολογείτε για να τα περιορίσετε.|{shown} από {n} αποτελέσματα. Συνεχίστε να πληκτρολογείτε για να τα περιορίσετε.
Recent Commands Πρόσφατες εντολές
No recent commands Δεν υπάρχουν πρόσφατες εντολές
Search commands Αναζήτηση εντολών
Search Commands… Αναζήτηση εντολών…
Secondary Δευτερεύον
Section Symbol Σύμβολο ενότητας
Can't render this file because it is too large.
+1
View File
@@ -3303,6 +3303,7 @@ digits Malayalam Malayálam
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} de {n} resultado. Sigue escribiendo para acotarlos.|{shown} de {n} resultados. Sigue escribiendo para acotarlos.
Recent Commands Comandos recientes
No recent commands No hay comandos recientes
Search commands Buscar comandos
Search Commands… Buscar comandos…
Secondary Secundario
Section Symbol Símbolo de sección
Can't render this file because it contains an unexpected character in line 2 and column 73.
+1
View File
@@ -1306,6 +1306,7 @@ lighting Light Valo
Search commands, tools, panels and effects Hae komentoja, työkaluja, paneeleita ja tehosteita
Style: Tyyli:
Switch workspace Vaihda työtilaa
Search commands Hae komentoja
Show all open documents Näytä kaikki avoimet asiakirjat
Use Käytä
the object to select | objektia valitaksesi sen |
Can't render this file because it contains an unexpected character in line 2 and column 73.
+1
View File
@@ -3291,6 +3291,7 @@ digits Malayalam Malayalam
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} sur {n} résultat. Continuez à taper pour les affiner.|{shown} sur {n} résultats. Continuez à taper pour les affiner.
Recent Commands Commandes récentes
No recent commands Aucune commande récente
Search commands Chercher des commandes
Search Commands… Rechercher des commandes…
Secondary Secondaire
Section Symbol Symbole de section
Can't render this file because it is too large.
+1
View File
@@ -3407,6 +3407,7 @@
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {n} માંથી {shown} પરિણામ. તેમને સંકુચિત કરવા લખતા રહો.|{n} માંથી {shown} પરિણામો. તેમને સંકુચિત કરવા લખતા રહો.
Recent Commands તાજેતરના આદેશો
No recent commands કોઈ તાજેતરના આદેશો નથી
Search commands આદેશો શોધો
Search images છબીઓ શોધો
Searching… શોધી રહ્યા છીએ…
Secondary ગૌણ
Can't render this file because it contains an unexpected character in line 72 and column 5.
+1
View File
@@ -4480,6 +4480,7 @@ antiAlias Sharp शार्प
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {n} में से {shown} परिणाम। इन्हें सीमित करने के लिए लिखते रहें।|{n} में से {shown} परिणाम। इन्हें सीमित करने के लिए लिखते रहें।
Recent Commands हाल के आदेश
No recent commands कोई हाल का आदेश नहीं
Search commands आदेश खोजें
Search Commands… कमांड खोजें…
Search Fonts Folder खोज फ़ॉन्ट फ़ोल्डर
Search images इमेज खोजना
Can't render this file because it is too large.
+1
View File
@@ -3924,6 +3924,7 @@ mark-style Japanese Japán
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {n} találatból {shown} látható. Gépeljen tovább a szűkítéshez.
Recent Commands Legutóbbi parancsok
No recent commands Nincsenek legutóbbi parancsok
Search commands Parancsok keresése
Search Commands… Parancsok keresése…
Search Fonts Folder Keresés betűtípusmappában
Searching… Keresés…
Can't render this file because it is too large.
+1
View File
@@ -1231,6 +1231,7 @@ lighting Light Cahaya
Search commands, tools, panels and effects Cari perintah, alat, panel, dan efek
Style: Gaya:
Switch workspace Ganti ruang kerja
Search commands Cari perintah
Show all open documents Tampilkan semua dokumen terbuka
Use Gunakan
the object to select | objek untuk memilihnya |
1 # Indonesian (id) catalog. Same format as zh-hant.tsv: context <TAB> source <TAB> translation
1231
1232
1233
1234
1235
1236
1237
+1
View File
@@ -3346,6 +3346,7 @@ digits Malayalam Malayalam
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} di {n} risultato. Continua a digitare per restringerli.|{shown} di {n} risultati. Continua a digitare per restringerli.
Recent Commands Comandi recenti
No recent commands Nessun comando recente
Search commands Cerca comandi
Search Commands… Cerca comandi…
Secondary Secondario
Section Symbol Simbolo di sezione
Can't render this file because it is too large.
+1
View File
@@ -3224,6 +3224,7 @@ mark-style Japanese 日本式
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {n} 件中 {shown} 件。続けて入力すると絞り込めます。
Recent Commands 最近使ったコマンド
No recent commands 最近使ったコマンドはありません
Search commands コマンドを検索
Secondary セカンダリ
Select All Art on Layer レイヤー上のすべてのアートを選択
Select All Assets すべてのアセットを選択
Can't render this file because it is too large.
+1
View File
@@ -3389,6 +3389,7 @@ lighting Light სინათლე
Search commands, tools, panels and effects ბრძანებების, ხელსაწყოების, პანელებისა და ეფექტების ძიება
Style: სტილი:
Switch workspace სამუშაო სივრცის გადართვა
Search commands ბრძანებების ძიება
Show all open documents ყველა ღია დოკუმენტის ჩვენება
Use გამოიყენეთ
the object to select | ობიექტზე — მოსანიშნად |
Can't render this file because it is too large.
+1
View File
@@ -3213,6 +3213,7 @@ mark-style Japanese 일본식
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. 결과 {n}개 중 {shown}개. 계속 입력하여 범위를 좁히세요.
Recent Commands 최근 명령
No recent commands 최근 명령 없음
Search commands 명령 검색
Secondary 보조
Select All Art on Layer 레이어의 모든 아트웍 선택
Select All Assets 모든 에셋 선택
Can't render this file because it is too large.
+1
View File
@@ -1799,6 +1799,7 @@ lighting Light Licht
Search commands, tools, panels and effects Opdrachten, gereedschappen, panelen en effecten zoeken
Style: Stijl:
Switch workspace Werkruimte wisselen
Search commands Opdrachten zoeken
Show all open documents Alle geopende documenten tonen
Use Gebruik
the object to select | op het object om te selecteren |
Can't render this file because it is too large.
+1
View File
@@ -1258,6 +1258,7 @@ lighting Light Światło
Search commands, tools, panels and effects Szukaj poleceń, narzędzi, paneli i efektów
Style: Styl:
Switch workspace Przełącz obszar roboczy
Search commands Szukaj poleceń
Show all open documents Pokaż wszystkie otwarte dokumenty
Use Użyj
the object to select | obiekt, aby go zaznaczyć |
Can't render this file because it is too large.
+1
View File
@@ -2762,6 +2762,7 @@ digits Malayalam Malaiala
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} de {n} resultado. Continue digitando para filtrá-los.|{shown} de {n} resultados. Continue digitando para filtrá-los.
Recent Commands Comandos recentes
No recent commands Nenhum comando recente
Search commands Pesquisar comandos
Secondary Secundária
Section Symbol Símbolo de Seção
Select Selecionar
Can't render this file because it is too large.
+1
View File
@@ -3335,6 +3335,7 @@ digits Malayalam Малаялам
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} из {n} результата. Продолжайте вводить, чтобы сузить их.|{shown} из {n} результатов. Продолжайте вводить, чтобы сузить их.|{shown} из {n} результатов. Продолжайте вводить, чтобы сузить их.
Recent Commands Недавние команды
No recent commands Нет недавних команд
Search commands Поиск команд
Search Commands… Поиск команд…
Secondary Вторичный
Section Symbol Символ параграфа
Can't render this file because it is too large.
+1
View File
@@ -3221,6 +3221,7 @@ digits Malayalam Malayalam
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} av {n} resultat. Fortsätt skriva för att begränsa dem.|{shown} av {n} resultat. Fortsätt skriva för att begränsa dem.
Recent Commands Senaste kommandon
No recent commands Inga senaste kommandon
Search commands Sök kommandon
Search Commands… Sök kommandon…
Secondary Sekundär
Section Symbol Paragraftecken
Can't render this file because it is too large.
+1
View File
@@ -3093,6 +3093,7 @@ digits Malayalam Malayalam
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {n} sonuçtan {shown} tanesi. Daraltmak için yazmaya devam edin.
Recent Commands Son komutlar
No recent commands Son komut yok
Search commands Komutları arayın
Search Commands… Arama Komutları…
Secondary İkincil
Section Symbol Bölüm Sembolü
Can't render this file because it is too large.
+1
View File
@@ -3338,6 +3338,7 @@ digits Malayalam Малаялам
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} з {n} результату. Продовжуйте вводити, щоб звузити їх.|{shown} з {n} результатів. Продовжуйте вводити, щоб звузити їх.|{shown} з {n} результатів. Продовжуйте вводити, щоб звузити їх.
Recent Commands Нещодавні команди
No recent commands Немає нещодавніх команд
Search commands Пошук команд
Search Commands… Пошук команд…
Secondary Вторинний
Section Symbol Символ параграфа
Can't render this file because it is too large.
+1
View File
@@ -3681,6 +3681,7 @@ mark-style Japanese Kiểu Nhật
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. {shown} trên {n} kết quả. Tiếp tục gõ để thu hẹp.
Recent Commands Lệnh gần đây
No recent commands Không có lệnh gần đây
Search commands Tìm kiếm lệnh
Search Commands… Tìm kiếm lệnh…
Search Fonts Folder Tìm kiếm thư mục phông chữ
Searching… Đang tìm kiếm…
Can't render this file because it contains an unexpected character in line 205 and column 5.
+1
View File
@@ -3165,6 +3165,7 @@ digits Malayalam 马拉雅拉姆数字
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. 共 {n} 个结果,显示 {shown} 个。继续输入以缩小范围。
Recent Commands 最近使用的命令
No recent commands 没有最近使用的命令
Search commands 搜索命令
Search Commands… 搜索命令…
Secondary 次要
Section Symbol 章节符号
Can't render this file because it is too large.
+1
View File
@@ -4474,6 +4474,7 @@ digits Malayalam 馬來亞拉姆數字
@plural {shown} of {n} result. Keep typing to narrow them.|{shown} of {n} results. Keep typing to narrow them. 共 {n} 個結果,顯示 {shown} 個。繼續輸入以縮小範圍。
Recent Commands 最近使用的指令
No recent commands 沒有最近使用的指令
Search commands 搜尋指令
Search Commands… 搜尋指令…
Secondary 次要
Section Symbol 章節符號
Can't render this file because it is too large.
+3 -3
View File
@@ -2543,13 +2543,13 @@ mod tests {
}
}
/// The click on the app bar's search button that opens the palette leaves it open; the next
/// click on the button closes it.
/// The click on the app bar's search field that opens the palette leaves it open; the next
/// click on the field closes it.
#[test]
fn the_click_that_opens_the_palette_does_not_close_it() {
let mut window = Window::new();
let nodes = window.frame(vec![]);
let at = button_at(&nodes, "Search commands, tools, panels and effects");
let at = button_at(&nodes, "Search commands");
window.click(at);
assert!(window.app.ui.palette_open, "the click opens the palette");
window.frame(vec![]);
+3 -3
View File
@@ -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, tools, panels and effects"));
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);
+6 -2
View File
@@ -322,11 +322,15 @@ mod tests {
assert!(!a.shrink(0.5).intersects(b.shrink(0.5)), "{a:?} overlaps {b:?} at {width}");
}
}
// Wide windows show the whole group; narrow ones drop Discord, then the search icon.
// Wide windows show the whole group, the search field included; narrow ones drop the
// community button first, and the search field goes before the search icon.
let texts: Vec<String> = texts(&out).into_iter().map(|(t, _)| t).collect();
let has = |s: &str| texts.iter().any(|t| t == s);
assert_eq!(has("Discord"), width > 1000.0, "{width}: {texts:?}");
// Search is an icon only (as in PhotoCraft): its label lives in the tooltip.
if width > 1000.0 {
assert!(has("Search commands"), "the search field shows at {width}: {texts:?}");
}
// The search's tooltip text is not painted in the bar.
assert!(!has("Search commands, tools, panels and effects"), "{width}: {texts:?}");
}
}
+3 -1
View File
@@ -30,7 +30,9 @@ pub use buttons::{
SPLIT_ARROW, flat_button, flat_button_fit, icon_button, icon_button_enabled, menu_item, menu_item_name, paint_icon_button, primary_button,
primary_button_enabled, secondary_button, split_button, split_button_named, toggle_icon,
};
pub(crate) use buttons::{button_width, flat_button_fit_width, icon_button_info, primary_button_width, secondary_button_width};
pub(crate) use buttons::{
button_width, flat_button_fit_width, icon_button_info, paint_icon_button_named, primary_button_width, secondary_button_width,
};
#[cfg(test)]
use chips::gradient_chip_colors;
pub use chips::{ProxyClicks, chip_button, chip_button_named, fill_stroke_proxy, gradient_chip, paint_chip, proxy_chip, swatch_tile};
+8 -2
View File
@@ -8,6 +8,12 @@ pub fn icon_button(ui: &mut Ui, icon: &str, tip: &str, selected: bool, size: f32
/// [`icon_button`] drawn for a response the caller made (its own id or sense).
pub fn paint_icon_button(ui: &mut Ui, resp: Response, icon: &str, tip: &str, selected: bool) -> Response {
paint_icon_button_named(ui, resp, icon, tl!(tip), tl!(tip), selected)
}
/// [`paint_icon_button`] that screen readers call `name` and that shows the tool tip `tip` (none
/// when empty), both as given.
pub(crate) fn paint_icon_button_named(ui: &mut Ui, resp: Response, icon: &str, name: &str, tip: &str, selected: bool) -> Response {
let t = Tokens::get(ui.ctx());
let rect = resp.rect;
let size = rect.width();
@@ -21,8 +27,8 @@ pub fn paint_icon_button(ui: &mut Ui, resp: Response, icon: &str, tip: &str, sel
ui.painter().rect_filled(rect, CornerRadius::same(5), bg);
let pad = (size * 0.2).round();
icons::paint(ui, icon, rect.shrink(pad), if selected { t.text_strong } else { t.icon });
resp.widget_info(|| icon_button_info(ui.is_enabled(), selected, tl!(tip)));
if !tip.is_empty() { resp.on_hover_text(tl!(tip)) } else { resp }
resp.widget_info(|| icon_button_info(ui.is_enabled(), selected, name));
if !tip.is_empty() { resp.on_hover_text(tip) } else { resp }
}
/// Small flat text button (Quick Actions style).
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -3252,7 +3252,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
+2 -1
View File
@@ -1041,7 +1041,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- 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).
- Help › Search Commands… is the first item of the Help menu in the window, with its shortcut and a separator after it; in the native macOS menu bar it is the first item below the system's search field. This is VectorCraft's own order and does not raise a score (`menus::tests::help_starts_with_search_commands`, `tests::nativemenu::the_mac_help_menu_starts_with_search_commands`).
- A Recent Commands button beside the Help › Search Commands field lists the last five commands, tools, panels and effects 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 existing rule for a focused control keeps the app's own keys off, so Enter does not open Move and Tab moves the focus on. While a dialog is open the field and the icon are drawn disabled and do nothing, as the shortcut does. Screen readers name the field and the icon 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. The field is wider than the icon, so the community button and Explore tutorials go at wider bars than they did beside the icon. 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_search_icon_has_the_fields_name_and_both_are_disabled_under_a_dialog`, `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`.