diff --git a/crates/ui-egui/src/chrome/control_bar.rs b/crates/ui-egui/src/chrome/control_bar.rs index 2088bfa1b4..7cecd2414d 100644 --- a/crates/ui-egui/src/chrome/control_bar.rs +++ b/crates/ui-egui/src/chrome/control_bar.rs @@ -23,14 +23,18 @@ pub(crate) mod rank { pub const SELECT_SIMILAR: u8 = 1; /// The inline X/Y/W/H fields and the Snapping menu. pub const FIELDS: u8 = 2; + /// The type groups (Character, Paragraph and area type's vertical alignment) and the Align buttons after them: + /// they leave before the members ahead of them, so Opacity, the Style picker and Recolor Artwork show while type + /// is selected. + pub const TYPE: u8 = 3; /// The parts of a group that its other members work without: the width profile, Recolor Artwork, Global Edit /// Options, Document Setup, an image's Edit Original. - pub const DETAIL: u8 = 3; + pub const DETAIL: u8 = 4; /// The Opacity link and field: they leave before the groups, so the narrower Style link and picker after them /// can show without them. - pub const OPACITY: u8 = 4; + pub const OPACITY: u8 = 5; /// Every other member of the bar. - pub const GROUP: u8 = 5; + pub const GROUP: u8 = 6; } /// An anchor button: icon, tooltip, command and the convert command's `to`. @@ -597,14 +601,21 @@ fn members(app: &mut VectorcraftApp, ui: &mut Ui) { if group_on(app, "graphicStyle") && count > 0 { style_group(app, ui); } - if group_on(app, "character") { - crate::panels::character::control_bar(app, ui); + let (character, paragraph) = (group_on(app, "character"), group_on(app, "paragraph")); + let typed = (character || paragraph) && crate::panels::character::text_style(app).is_some(); + if typed && character { + ranked(ui, rank::TYPE, |ui| { + crate::panels::character::control_bar(app, ui); + }); } - if group_on(app, "paragraph") { - crate::panels::paragraph::control_bar(app, ui); + if typed && paragraph { + ranked(ui, rank::TYPE, |ui| { + crate::panels::paragraph::control_bar(app, ui); + }); } - if group_on(app, "verticalAlignment") && crate::panels::properties::vertical_align::shown(app).is_some() { - group(ui, rank::GROUP, |ui| { + let vertical = group_on(app, "verticalAlignment") && crate::panels::properties::vertical_align::shown(app).is_some(); + if vertical { + group(ui, rank::TYPE, |ui| { crate::panels::properties::vertical_align::buttons(app, ui); }); } @@ -615,7 +626,9 @@ fn members(app: &mut VectorcraftApp, ui: &mut Ui) { return; } if group_on(app, "alignDistribute") { - group(ui, rank::GROUP, |ui| crate::panels::align::control_bar_strip(app, ui)); + // After the type groups, the Align buttons take their rank and, coming last, leave first. + let rank = if typed || vertical { rank::TYPE } else { rank::GROUP }; + group(ui, rank, |ui| crate::panels::align::control_bar_strip(app, ui)); } if transform { // The Transform link opens the whole Transform panel in a popover; X/Y/W/H follow inline while the diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index acc0ecf522..75dbc0754d 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -2431,6 +2431,29 @@ fn the_control_bar_leaves_members_out_in_its_priority_order() { assert!(seen.iter().any(|s| s[0] && !s[1]), "some width shows the Align buttons without the fields"); } +/// With type selected, the Character and Paragraph groups leave the Control bar before the members ahead of them: at +/// every width that shows the Character group, Opacity, Recolor Artwork and the Style picker show too, the Paragraph +/// group leaves before the Character group, the Align buttons leave before the Paragraph group, and some width shows +/// Opacity without them. +#[test] +fn the_type_groups_leave_the_control_bar_before_opacity_and_style() { + crate::i18n::set_current(crate::i18n::Lang::EN); + let mut app = crate::VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + let text = app.run("text.create", json!({"x": 10, "y": 100, "text": "Hi"})).unwrap()["id"].clone(); + app.run("select.set", json!({ "ids": [text] })).unwrap(); + let mut bar = control_shown(app); + let names = ["Character:", "Paragraph:", "Opacity:", "Recolor Artwork", "Style:", "Horizontal Align Left"]; + let seen = control_bar_widths(&mut bar, &names); + assert!(seen.iter().any(|s| s.iter().all(|shown| *shown)), "a wide bar shows {names:?}"); + for s in &seen { + assert!(!s[0] || s[2..5].iter().all(|shown| *shown), "the Character group shows only with {:?}: {s:?}", &names[2..5]); + assert!(!s[1] || s[0], "the Paragraph group shows only with the Character group: {s:?}"); + assert!(!s[5] || s[1], "the Align buttons show only with the Paragraph group: {s:?}"); + } + assert!(seen.iter().any(|s| s[2] && !s[0]), "some width shows Opacity without the Character group"); +} + /// The names of the bar's X, Y, W and H fields, in their order. const BAR_FIELDS: [&str; 4] = ["X position", "Y position", "Width", "Height"];