From 4fbca02f5bb2101e55c7598124a7d79a9f05ad08 Mon Sep 17 00:00:00 2001 From: BFlat Date: Tue, 24 Nov 2026 17:36:14 +0700 Subject: [PATCH] Look like production: title bar, command search, switcher, status bar, rail card, option links (#9220) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More of the window's chrome looks like production's VectorCraft, through craft-libs options already on the app's pin. - **Title bar:** drawn on the background surface, as production's app bar was. Its trailing items leave by rank as the window narrows (Discord, then Learn, then Arrange, then the search) before the menus fold, as production's did. - **Search:** the command search is a field (`CommandSearch`). - **Workspace switcher:** quiet, and as wide as the workspace it shows. - **Menus:** menu titles sit closer together (`MenuTitlePad::Control`). - **Document tab:** the unsaved mark follows the document's name: "Untitled-1* @ 92 % (RGB/Preview)". - **Status bar:** the position and timings sit at the bar's end and leave first when it narrows. - **Tools rail:** shown as a card on the dock's background (`rail_cards`). Window › Toolbars › Compact packs it densely. - **Option links** ("Opacity:", "Style:", "Character:" and the Appearance list's links) are drawn in the normal ink with an underline, as production drew them. Links that leave the panel's subject keep the accent. The Stroke field's label link still takes the accent; it needs a framework option and follows separately. Tests: the app-bar fit test now expects the search field to keep its width until it drops; production narrowed it to its icon first. A framework option for a ranked unit with a short form is an open follow-up. Checks: `vectorcraft-ui-egui` lib tests 3780 passed, 0 failed. Clippy (`vectorcraft-ui-egui`, `vectorcraft`, all targets, `-D warnings`) and `cargo fmt --check` are clean. --- crates/ui-egui/src/app.rs | 3 + crates/ui-egui/src/chrome.rs | 75 +++++++++--------------- crates/ui-egui/src/chrome/control_bar.rs | 6 +- crates/ui-egui/src/chrome/status_bar.rs | 41 +++++++------ crates/ui-egui/src/chrome/tabs.rs | 3 +- crates/ui-egui/src/chrome/tests.rs | 7 +-- crates/ui-egui/src/panel_docking.rs | 2 +- crates/ui-egui/src/panels.rs | 8 ++- crates/ui-egui/src/panels/appearance.rs | 10 ++-- crates/ui-egui/src/panels/character.rs | 3 +- crates/ui-egui/src/panels/paragraph.rs | 4 +- crates/ui-egui/src/panels/transform.rs | 4 +- crates/ui-egui/src/toolbar.rs | 16 ++++- crates/ui-egui/src/workspaces.rs | 3 +- 14 files changed, 94 insertions(+), 91 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index d04cdf9b92..225be05ca7 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -5,6 +5,7 @@ use craft::platform::clock::monotonic_ms; use craft::theme::variant::Tone; use craft::ui::buttons::{ActiveLook, PushButtonLook}; use craft::ui::contract::{Bind, GlyphColon}; +use craft::ui::menu::MenuTitlePad; use craft::ui::runtime::env::{RootEnv, Scale, ScrubDrags, WindowKey}; use craft::ui::runtime::frame::{FrameInput, FrameOutput}; use craft::ui::runtime::toast::{self, Toast}; @@ -676,6 +677,8 @@ pub(crate) fn root_env(prefs: &vectorcraft_engine::Prefs, native_ppp: f32) -> Ro // A glyph that stands for a word caption ("X", "W") takes a form's colon as production drew it ("X:"); "#" and // the colour channel letters stay bare. root.values.set(GlyphColon::Form); + // The menu bar's titles stand as close as production's, which share the line with the bar's other controls. + root.values.set(MenuTitlePad::Control); // A bare Tab on the canvas, or with nothing focused, toggles the panels (`window.dock`) instead of moving focus. root.tab_toggles_chrome = true; // Escape in a text field gives up its focus, reverting any typing, so the next keys are the window's. diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index e77335fcc1..3516edf65f 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -4,17 +4,16 @@ use std::borrow::Cow; use std::cell::RefCell; use craft::behavior::IconId; -use craft::behavior::fit::{FitItem, FitKeep, fit_items}; use craft::menu::MenuBarUi; -use craft::ui::buttons::{Button, ButtonChord, IconButton, PopupMark, ToggleButton}; +use craft::ui::buttons::{Button, CommandSearch, IconButton, PopupMark, ToggleButton}; use craft::ui::contract::{Bind, BodyCx, Props, Show, ShowContainer, Trigger}; use craft::ui::display::{Divider, Picture}; -use craft::ui::layout::measure_slot; +use craft::ui::layout_components::Row; use craft::ui::menu::{Menu, MenuItem}; -use craft::ui::primitives::{HAlign, IconSpec}; +use craft::ui::primitives::IconSpec; use craft::ui::runtime::windows::WindowHost; use craft::ui::shell::{Frame, Title, TitleBar}; -use craft::ui::style::Variant; +use craft::ui::style::{SurfaceKind, Variant}; use egui::Ui; use serde_json::json; @@ -69,18 +68,21 @@ enum Trailing { impl Trailing { /// The controls in the order they are drawn. const SHOWN: [Trailing; 6] = [Trailing::Discord, Trailing::Learn, Trailing::Search, Trailing::Arrange, Trailing::Safe, Trailing::Switcher]; - /// The controls in the order the fit gives them up, last first: each is also in a menu, so a hidden one goes nowhere. - const DROPPED_LAST_FIRST: [Trailing; 6] = - [Trailing::Safe, Trailing::Switcher, Trailing::Search, Trailing::Arrange, Trailing::Learn, Trailing::Discord]; - /// Whether the fit may drop it. - fn keep(self) -> FitKeep { - if matches!(self, Trailing::Safe | Trailing::Switcher) { FitKeep::Pinned } else { FitKeep::Free } + /// The rank the bar gives it up in, lowest first: Discord, tutorials, Arrange Documents, then the search. Each is + /// also in a menu, so a hidden one goes nowhere. Safe Mode and the switcher always show. + fn rank(self) -> Option { + match self { + Trailing::Discord => Some(1), + Trailing::Learn => Some(2), + Trailing::Arrange => Some(3), + Trailing::Search => Some(4), + Trailing::Safe | Trailing::Switcher => None, + } } - /// Shows the control, in its shorter form when `short` (the search as its icon); the fit measures it through the - /// same call. - fn show(self, app: &mut VectorcraftApp, ui: &mut Ui, short: bool) { + /// Shows the control. + fn show(self, app: &mut VectorcraftApp, ui: &mut Ui) { match self { Trailing::Safe => { let shown = Button::new(tl!("Safe Mode")).variant(Variant::GHOST).tooltip(tl!("Safe Mode…")).show(ui); @@ -97,19 +99,9 @@ impl Trailing { .show(ui); } Trailing::Arrange => arrange_documents(app, ui), - Trailing::Search if short => { - IconButton::command(IconId::new("search"), PALETTE).label(tl!("Search commands")).show(ui); - } + // Named as production's field, not after the command's menu row. Trailing::Search => { - // PLAN: assumed `Button::command` is bound by a `&str` command id; the command opens the palette. - // Named as production's field, not after the command's menu row. - Button::command(PALETTE) - .label(tl!("Search commands")) - .icon(IconSpec::svg(IconId::new("search"))) - .variant(Variant::SECONDARY) - .align(HAlign::Start) - .chord(ButtonChord::Trailing) - .show(ui); + CommandSearch::new(PALETTE, tl!("Search commands")).show(ui); } // PLAN: assumed `crate::workspaces::switcher(app: &mut VectorcraftApp, ui: &mut Ui)` (chrome-w14's `WorkspaceSwitcher`). Trailing::Switcher => crate::workspaces::switcher(app, ui), @@ -171,29 +163,18 @@ fn leading(ui: &mut Ui, app: &mut VectorcraftApp) { } } -/// The end of the bar: the controls that fit in the room, the first-listed going last. +/// The end of the bar: each ranked control in a row of its own, which the fitted title bar gives up whole, lowest rank +/// first, before the menus narrow. fn trailing(ui: &mut Ui, app: &mut VectorcraftApp) { let safe = vectorcraft_plugins::safe_mode::active(); - let order: Vec = Trailing::DROPPED_LAST_FIRST.into_iter().filter(|t| safe || *t != Trailing::Safe).collect(); - let gap = ui.spacing().item_spacing.x; - let room = ui.available_width(); - let mut measure = |t: Trailing, short: bool| measure_slot(ui, room, |ui| t.show(app, ui, short)).x; - let items: Vec = order - .iter() - .map(|&t| { - let item = FitItem::new(measure(t, false), 0, t.keep()); - // The search narrows to its icon before it goes. - if t == Trailing::Search { item.short(measure(t, true)) } else { item } - }) - .collect(); - let fit = fit_items(&items, room, gap, gap, 0.0); - ui.horizontal_centered(|ui| { - for t in Trailing::SHOWN { - if let Some(at) = order.iter().position(|o| *o == t).filter(|at| fit.shown.contains(at)) { - t.show(app, ui, fit.short.contains(&at)); + for t in Trailing::SHOWN.into_iter().filter(|t| safe || *t != Trailing::Safe) { + match t.rank() { + Some(rank) => { + Row::new().fit_rank(rank).show(ui, |ui, _| t.show(app, ui)); } + None => t.show(app, ui), } - }); + } } /// The application bar, the body of the shell's title bar: brand mark, Home and menus, then Discord, @@ -207,9 +188,9 @@ pub fn app_bar(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut VectorcraftApp) { let start = |ui: &mut Ui, _: &mut BodyCx<'_>| leading(ui, &mut app.borrow_mut()); let end = |ui: &mut Ui, _: &mut BodyCx<'_>| trailing(ui, &mut app.borrow_mut()); let _ = if titled { - TitleBar::new().show_titled(ui, Title::new(tl!("VectorCraft")), start, end) + TitleBar::new().surface(SurfaceKind::Background).show_titled(ui, Title::new(tl!("VectorCraft")), start, end) } else { - TitleBar::new().trailing(end).show(ui, start).output + TitleBar::new().surface(SurfaceKind::Background).show_fitted(ui, start, end) }; } diff --git a/crates/ui-egui/src/chrome/control_bar.rs b/crates/ui-egui/src/chrome/control_bar.rs index f2eec9c4de..2088bfa1b4 100644 --- a/crates/ui-egui/src/chrome/control_bar.rs +++ b/crates/ui-egui/src/chrome/control_bar.rs @@ -1,6 +1,6 @@ use craft::behavior::IconId; use craft::ui::bars::{Bar, BarKind}; -use craft::ui::buttons::{Button, IconButton, Link}; +use craft::ui::buttons::{Button, IconButton}; use craft::ui::contract::{Bind, PopupKind, Props as _, Show as _, ShowContainer as _, SideLabel, Trigger}; use craft::ui::display::{Divider, Elide, Shade, Text}; use craft::ui::form::Field; @@ -323,7 +323,7 @@ fn opacity_field(app: &mut VectorcraftApp, ui: &mut Ui, opacity: f32, selected: fn style_group(app: &mut VectorcraftApp, ui: &mut Ui) { let mut open = false; ranked(ui, rank::GROUP, |ui| { - open |= Link::new(tl!("Style:")).show(ui).clicked(); + open |= crate::panels::option_link(tl!("Style:")).show(ui).clicked(); crate::panels::graphic_styles::style_picker(app, ui); }); if open { @@ -533,7 +533,7 @@ fn object_name(app: &VectorcraftApp, anchors: AnchorControls) -> Option<(&'stati fn object_label(app: &mut VectorcraftApp, ui: &mut Ui, label: &'static str, image: bool) { if !image { Text::new(label).elide(Elide::End).show(ui); - } else if Link::new(label).show(ui).clicked() { + } else if crate::panels::option_link(label).show(ui).clicked() { crate::panels::links::show_selected_image(app, ui.ctx()); } } diff --git a/crates/ui-egui/src/chrome/status_bar.rs b/crates/ui-egui/src/chrome/status_bar.rs index 60cbc2d068..c3fb782f18 100644 --- a/crates/ui-egui/src/chrome/status_bar.rs +++ b/crates/ui-egui/src/chrome/status_bar.rs @@ -3,7 +3,7 @@ use craft::behavior::IconId; use craft::behavior::kurbo::Size; use craft::ui::bars::{Bar, BarKind, StatusMessage, StatusProgress}; use craft::ui::buttons::{Button, IconButton}; -use craft::ui::contract::{Bind, Entry, Gap, LabelKind, Outcome as _, Props as _, Show as _, ShowContainer as _, SideLabel, Trigger}; +use craft::ui::contract::{Bind, BodyCx, Entry, Gap, LabelKind, Outcome as _, Props as _, Show as _, ShowContainer as _, SideLabel, Trigger}; use craft::ui::display::{Divider, Elide, Shade, Text}; use craft::ui::form::Field; use craft::ui::layout_components::Row; @@ -42,8 +42,28 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { let busy = busy_labels(app); let (mut zoom_to, mut rotate_to, mut go, mut show_pick, mut stop) = (None, None, None, None, false); + // The readouts end the bar, the pointer's position and then the timings; a narrow bar leaves out the timings + // first, then the position, before the message. + let readouts = |ui: &mut Ui, _: &mut BodyCx<'_>| { + // With no hover point the axes stay empty and keep their width. + let origin = app.ruler_origin(); + Row::new().gap(Gap::Item).fit_rank(2).show(ui, |ui, _| { + for (axis, value) in [("X", app.hover_doc.map(|p| p.x - origin.x)), ("Y", app.hover_doc.map(|p| p.y - origin.y))] { + let text = value.map(|v| format!("{axis}: {}", unit.readout(v))).unwrap_or_default(); + Text::new(text).role(TypeRole::Mono).shade(Shade::Muted).sample(format!("{axis}: -8888.88 {}", unit.suffix())).show(ui); + } + }); + let readout = |text: String, sample: String| Text::new(text).shade(Shade::Faint).sample(sample); + Row::new().gap(Gap::Item).fit_rank(1).show(ui, |ui, _| { + readout(format!("{render} {:.1} ms", app.perf.render_ms), format!("{render} 8888.8 ms")).show(ui); + readout(format!("{ui_name} {:.1} ms", app.perf.frame_ms), format!("{ui_name} 8888.8 ms")).show(ui); + // No rate until the window has drawn continuously for a moment (`frame_rate`). + let fps = if app.perf.fps > 0.0 { format!("{:.0} fps", app.perf.fps) } else { "\u{2013} fps".into() }; + readout(fps, "8888 fps".into()).show(ui); + }); + }; // PLAN: assumed VectorcraftApp::canvas_view() -> Option (cv.S4) and the label msgid "Status Bar". - Bar::new(tl!("Status Bar"), BarKind::Status).show(ui, |ui, _| { + Bar::new(tl!("Status Bar"), BarKind::Status).trailing(readouts).show(ui, |ui, _| { let zoom = Field::new(tl!("Zoom")) .side(SideLabel::new().kind(LabelKind::Hidden)) .show(ui, |ui, _| ZoomField::new(tl!("Zoom"), app.canvas_view(), document).scrub(true).show(ui)); @@ -81,23 +101,6 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { Text::new(shown.to_owned()).shade(Shade::Muted).elide(Elide::End).show(ui); let more = IconButton::new(IconId::new("chevron_down")).label(tl!("Show")).show(ui); show_pick = Menu::new(tl!("Show")).values().opened_by(more.response(), Trigger::Press).pick(ui, &shows).picked; - // A narrow bar leaves out the timings first, then the pointer's position, before the message. - let readout = |text: String, sample: String| Text::new(text).shade(Shade::Faint).sample(sample); - Row::new().gap(Gap::Item).fit_rank(1).show(ui, |ui, _| { - readout(format!("{render} {:.1} ms", app.perf.render_ms), format!("{render} 8888.8 ms")).show(ui); - readout(format!("{ui_name} {:.1} ms", app.perf.frame_ms), format!("{ui_name} 8888.8 ms")).show(ui); - // No rate until the window has drawn continuously for a moment (`frame_rate`). - let fps = if app.perf.fps > 0.0 { format!("{:.0} fps", app.perf.fps) } else { "\u{2013} fps".into() }; - readout(fps, "8888 fps".into()).show(ui); - }); - // With no hover point the axes stay empty and keep their width. - let origin = app.ruler_origin(); - Row::new().gap(Gap::Item).fit_rank(2).show(ui, |ui, _| { - for (axis, value) in [("X", app.hover_doc.map(|p| p.x - origin.x)), ("Y", app.hover_doc.map(|p| p.y - origin.y))] { - let text = value.map(|v| format!("{axis}: {}", unit.readout(v))).unwrap_or_default(); - Text::new(text).role(TypeRole::Mono).shade(Shade::Muted).sample(format!("{axis}: -8888.88 {}", unit.suffix())).show(ui); - } - }); if app.session.script_running() { stop = Button::new(tl!("Stop")).show(ui).response().clicked(); } diff --git a/crates/ui-egui/src/chrome/tabs.rs b/crates/ui-egui/src/chrome/tabs.rs index 70c56955a6..59f0dda7ce 100644 --- a/crates/ui-egui/src/chrome/tabs.rs +++ b/crates/ui-egui/src/chrome/tabs.rs @@ -83,7 +83,8 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { // The tab's modified mark shows unsaved changes, so its text has no `*`. let whole = window_tab_title(app, w, d, false); let tab = if Some(w) == shown { - DocumentTab::new(w, whole) + // The modified mark follows the document's name, before the view's zoom and mode. + DocumentTab::new(w, whole).name_len(view_tab_name(d, doc_windows::label(app, w), false).len()) } else { DocumentTab::new(w, view_tab_name(d, doc_windows::label(app, w), false)).tooltip(whole) }; diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 217900f513..47d586032c 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -261,8 +261,8 @@ fn hints_name_keys_as_the_menus_do() { } /// As the window narrows, the app bar gives up its right-hand controls one at a time, each before the one after it: -/// Discord, Explore tutorials, Arrange Documents, the search and last the workspace switcher; the search narrows to its -/// icon before it goes. Whatever shows lies inside the window. Safe Mode's rows are in `tests/safe_mode.rs`, whose +/// Discord, Explore tutorials, Arrange Documents, the search and last the workspace switcher; each keeps its whole width +/// until it goes. Whatever shows lies inside the window. Safe Mode's rows are in `tests/safe_mode.rs`, whose /// process owns the Safe Mode switch. #[test] fn the_app_bar_gives_up_its_right_hand_controls_in_order() { @@ -291,13 +291,12 @@ fn the_app_bar_gives_up_its_right_hand_controls_in_order() { assert!(on.iter().zip(before).all(|(now, was)| !now || *was), "{width}: a control came back as the window narrowed: {on:?}"); } if let Some(search) = shown[3] { - assert!(search_widths.last().is_none_or(|w: &f32| search.rect.width() <= *w + 0.5), "{width}: the search widened as the window narrowed"); search_widths.push(search.rect.width()); } before = Some(on); } let (widest, narrowest) = (search_widths.first().copied(), search_widths.last().copied()); - assert!(widest.zip(narrowest).is_some_and(|(w, n)| n < w), "the search field becomes its icon before it goes: {search_widths:?}"); + assert!(widest.zip(narrowest).is_some_and(|(w, n)| n >= w - 0.5), "the search field keeps its width until it goes: {search_widths:?}"); } /// A text the status bar painted, with where it lies. diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index e02a0c1ea1..d06f38c22b 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -1316,7 +1316,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, keeps_tools: boo Bind::bound(&mut workspace), &specs, &mut panels, - DockConfig::default().panel_menu_always(true).panel_menu_icon(IconId::new("menu")), + DockConfig::default().panel_menu_always(true).panel_menu_icon(IconId::new("menu")).rail_cards(true), ) .hide(hide) .flyout(Bind::bound(&mut flyout)); diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 6d4c587285..489eee6f61 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -62,7 +62,7 @@ use craft::color_ui::ui::{PaintChip, PairWell, SwatchPair, SwatchPairOutput, Swa use craft::keymap::CommandRef; use craft::theme::Srgba; use craft::theme::variant::Tone; -use craft::ui::buttons::{IconButton, PopupMark}; +use craft::ui::buttons::{IconButton, Link, PopupMark}; use craft::ui::choice::SwatchSpacing; use craft::ui::contract::{Bind, CommandSet as _, Entry, ListDrag, PopupKind, Props as _, Show as _, ShowContainer as _, Sizing, Trigger}; use craft::ui::display::{Divider, Shade, Text}; @@ -907,6 +907,12 @@ pub(crate) fn subheading<'a>(title: impl Into