Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into properties-bullets-options

moppeeerd5b977193776
diff --cc crates/ui-egui/src/panels/properties/tests.rs
index 000000000,095bd5690..74fd68ba7
mode 000000,100644..100644
--- a/crates/ui-egui/src/panels/properties/tests.rs
+++ b/crates/ui-egui/src/panels/properties/tests.rs
@@@ -1,0 -1,815 +1,831 @@@
+ use egui_kittest::{
+ Harness,
+ kittest::{NodeT, Queryable},
+ };
+
+ use super::*;
+
+ /// A link to a panel whose flyout is open leaves the flyout open.
+ #[test]
+ fn a_panel_link_keeps_its_open_flyout() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ show_panel(&mut app, "stroke");
+ assert_eq!(app.ui.docking_flyout.as_deref(), Some("stroke"));
+ show_panel(&mut app, "stroke");
+ assert!(crate::panel_docking::showing(&app, "stroke"));
+ }
+
+ fn language(app: &mut DesignApp) -> Value {
+ text_attrs(app).unwrap()["chars"]["language"].clone()
+ }
+
+ fn linked_graphics(paths: &[Option<&str>]) -> (DesignApp, Vec<designcraft_doc::ItemId>, Vec<designcraft_doc::AssetId>) {
+ use designcraft_doc::{Asset, AssetId, Content, Graphic, ItemId};
+ use std::sync::Arc;
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"title": "Linked graphics"})).unwrap();
+ let mut items = Vec::new();
+ let mut assets = Vec::new();
+ for (index, path) in paths.iter().enumerate() {
+ let x = 72 + index * 100;
+ let id = ItemId(app.run("frame.create", json!({"rect": [x, 72, x + 72, 144]})).unwrap()["id"].as_u64().unwrap());
+ let doc = Arc::make_mut(&mut app.session.doc_mut().unwrap().doc);
+ let aid = AssetId(doc.alloc());
+ doc.assets.insert(
+ aid,
+ Arc::new(Asset {
+ id: aid,
+ name: "photo.svg".into(),
+ mime: "image/svg+xml".into(),
+ link: path.map(str::to_owned),
+ data: Arc::new(
+ br##"<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32"><rect width="32" height="32" fill="#4488cc"/></svg>"##
+ .to_vec(),
+ ),
+ pixels: Some((32, 32)),
+ ..Default::default()
+ }),
+ );
+ doc.item_mut(id).unwrap().content = Content::Graphic(Graphic {
+ layer_options: None,
+ asset: aid,
+ size: (72.0, 72.0),
+ xf: designcraft_geom::Affine::IDENTITY,
+ clip: None,
+ auto_fit: Default::default(),
+ fit_align: 4,
+ crop: [0.0; 4],
+ wrap: Default::default(),
+ fill: Default::default(),
+ });
+ items.push(id);
+ assets.push(aid);
+ }
+ (app, items, assets)
+ }
+
+ fn links_harness(app: DesignApp, width: f32) -> Harness<'static, DesignApp> {
+ let mut ready = false;
+ let mut h = Harness::builder().with_size(vec2(width, 600.0)).build_ui_state(
+ move |ui, app: &mut DesignApp| {
+ if !ready {
+ crate::theme::install_fonts(ui.ctx(), "");
+ crate::theme::apply(ui.ctx(), &Tokens::for_brightness(Default::default()));
+ ready = true;
+ return;
+ }
+ links_panel(app, ui);
+ },
+ app,
+ );
+ h.input_mut().max_texture_side = Some(8192);
+ h.run_steps(3);
+ h
+ }
+
+ /// With the caret in text, the Stroke panel offers the text's stroke options, not an empty panel.
+ /// The first and last line indents take negative values, as InDesign's (and the Paragraph
+ /// panel's) do; the left and right indents and the spacing don't.
+ #[test]
+ fn last_line_indent_may_be_negative() {
+ for key in ["firstLineIndent", "lastLineIndent"] {
+ assert!(super::para_field_min(key) < 0.0, "{key}");
+ }
+ for key in ["leftIndent", "rightIndent", "spaceBefore", "spaceAfter"] {
+ assert_eq!(super::para_field_min(key), 0.0, "{key}");
+ }
+ }
+
+ #[test]
+ fn stroke_panel_shows_the_text_stroke_options_while_text_is_selected() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.run("frame.create", json!({"rect": [72, 72, 400, 400], "content": "text", "caret": true})).unwrap();
+ let mut ready = false;
+ let mut h = Harness::builder().with_size(vec2(320.0, 400.0)).build_ui_state(
+ move |ui, app: &mut DesignApp| {
+ if !ready {
+ crate::theme::install_fonts(ui.ctx(), "");
+ crate::theme::apply(ui.ctx(), &Tokens::for_brightness(Default::default()));
+ ready = true;
+ return;
+ }
+ stroke_panel(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ assert!(h.query_by_label("Select an object.").is_none());
+ h.get_by_label("Stroke Behind Fill");
+ }
+
+ /// As InDesign's: Edit Page takes the Page tool to the page in view, and Properties sets that
+ /// page alone; Back returns to the document.
+ #[test]
+ fn edit_page_shows_the_page_and_sets_its_size_alone() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"pages": 3, "facingPages": false})).unwrap();
+ app.ui.dock_tab = "properties".into();
+ let mut h = crate::test_window::open(app, vec2(1400.0, 900.0));
+ crate::canvas::go_to_page(&mut h.state_mut().app, 1);
+ h.run_steps(3);
+ h.get_by_label("Edit Page").click();
+ h.run_steps(3);
+ let st = h.state().app.session.active().unwrap();
+ assert_eq!((h.state().app.session.tool_id(), st.selection.page), ("page", Some(1)));
+ assert!(h.query_by_label("Document Setup").is_none(), "no dialog");
+ let _ = h.get_by_label("Page Size");
+ let _ = h.get_by_label("Margins and Columns");
+ h.get_by_label("Landscape").click();
+ h.run_steps(3);
+ let doc = &h.state().app.session.active().unwrap().doc;
+ let size = |abs: usize| doc.page(abs).map(|p| (p.width, p.height)).unwrap();
+ assert_eq!(size(1), (792.0, 612.0), "the page turns");
+ assert_eq!((size(0), size(2)), ((612.0, 792.0), (612.0, 792.0)), "the others don't");
+ h.get_by_label("Back").click();
+ h.run_steps(3);
+ let st = h.state().app.session.active().unwrap();
+ assert_eq!((h.state().app.session.tool_id(), st.selection.page), ("selection", None));
+ let _ = h.get_by_label("Edit Page");
+ }
+
+ #[test]
+ fn links_panel_distinguishes_same_named_sources_and_keeps_link_actions() {
+ let first = "/project/assets/studio-a/photo.svg";
+ let second = "/project/assets/studio-b/photo.svg";
+ let (app, items, assets) = linked_graphics(&[Some(first), Some(second), None]);
+ let mut h = links_harness(app, 320.0);
+ assert_eq!(h.get_all_by_label("photo.svg").count(), 3);
+ assert!(h.query_by_label(first).is_some(), "the first source path is visible in the row");
+ h.get_by_label(second).click();
+ h.run_steps(3);
+ h.get_by_label("Go To").click();
+ h.run_steps(3);
+ assert_eq!(h.state().session.active().unwrap().selection.items, vec![items[1]]);
+ h.get_by_label("Embed").click();
+ h.run_steps(3);
+ assert!(h.state().session.active().unwrap().doc.assets[&assets[1]].link.is_none());
+ assert_eq!(h.state().session.active().unwrap().doc.assets[&assets[0]].link.as_deref(), Some(first));
+ assert!(h.query_by_label(second).is_none(), "an embedded graphic no longer shows a source path");
+ assert_eq!(h.get_all_by_label("Embedded").count(), 2);
+ assert_eq!(h.get_all_by_label("photo.svg").count(), 3);
+ h.get_by_label(first).click();
+ h.run_steps(3);
+ h.get_by_label("Go To").click();
+ h.run_steps(3);
+ assert_eq!(h.state().session.active().unwrap().selection.items, vec![items[0]]);
+ }
+
+ #[test]
+ fn links_panel_keeps_long_source_paths_inside_a_narrow_panel() {
+ let path = "/project/assets/studio-a/very-long-folder-name/another-long-folder-name/photo.svg";
+ let (app, _, _) = linked_graphics(&[Some(path)]);
+ let mut h = links_harness(app, 240.0);
+ let source = h.get_by_label(path).rect();
+ assert!(source.width() < 150.0, "the source is truncated to its column: {source:?}");
+ assert!(source.right() <= 240.0, "the source stays inside the narrow panel: {source:?}");
+ assert!(h.get_by_label("Page · PPI").rect().right() <= 240.0);
+ h.get_by_label(path).click();
+ h.run_steps(3);
+ assert!(h.output().shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(text) if text.galley.job.text == path && !text.galley.elided && text.visual_bounding_rect().right() <= 240.0)), "the selected path is painted in full and wraps inside the panel");
+ }
+
+ #[test]
+ fn properties_character_section_sets_the_language() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "bunun", "caret": true})).unwrap();
+ app.run("edit.selectAll", json!({})).unwrap();
+ assert_ne!(language(&mut app), "French");
+ let mut h = Harness::builder().with_size(vec2(320.0, 1400.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ // The panel's fonts are installed before its first frame.
+ let id = egui::Id::unique("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ show(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ assert!(h.query_by_label("Language").is_none(), "under •••, as in InDesign");
+ h.get_all_by_label("More Options").next().unwrap().click();
+ h.run_steps(3);
+ h.get_by_label("Language").click();
+ h.run_steps(2);
+ h.get_by_label("French").click();
+ h.run_steps(2);
+ assert_eq!(language(h.state_mut()), "French");
+ }
+
+ /// Properties › Character and Paragraph •••, as in InDesign: the sections expand in place,
+ /// with the scales, baseline shift, skew, language, OpenType and the case buttons, and the
+ /// indents, spacing and drop caps.
+ /// Properties › Paragraph ••• on a First Line Only paragraph: Align to Baseline Grid shows
+ /// pressed, and a click turns alignment off instead of making it All Lines.
+ #[test]
+ fn more_options_grid_button_keeps_first_line_only() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "If fine plants", "caret": true})).unwrap();
+ app.run("edit.selectAll", json!({})).unwrap();
+ app.run("type.para", json!({"attrs": {"gridAlign": "firstLineOnly"}})).unwrap();
+ let mut h = panel_harness(app, show);
+ h.run_steps(3);
+ h.get_all_by_label("More Options").nth(1).unwrap().click();
+ h.run_steps(3);
+ assert_eq!(h.get_by_label("Align to Baseline Grid").accesskit_node().toggled(), Some(egui::accesskit::Toggled::True));
+ assert_eq!(text_attrs(h.state_mut()).unwrap()["para"]["gridAlign"], "firstLineOnly");
+ h.get_by_label("Align to Baseline Grid").click();
+ h.run_steps(3);
+ assert_eq!(text_attrs(h.state_mut()).unwrap()["para"]["gridAlign"], "none");
+ }
+
+ #[test]
+ fn more_options_expand_character_and_paragraph_in_place() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "If fine plants", "caret": true})).unwrap();
+ app.run("edit.selectAll", json!({})).unwrap();
+ let mut h = panel_harness(app, show);
+ h.run_steps(3);
+ for l in ["Vertical Scale", "Small Caps", "Drop Cap Number of Lines", "Space Before"] {
+ assert!(h.query_by_label(l).is_none(), "{l} hidden until •••");
+ }
+ h.get_all_by_label("More Options").next().unwrap().click();
+ h.run_steps(3);
+ h.get_by_label("Small Caps").click();
+ h.run_steps(3);
+ let _ = h.get_by_label("OpenType");
+ let _ = h.get_by_label("Language");
+ h.get_all_by_label("More Options").nth(1).unwrap().click();
+ h.run_steps(3);
+ let _ = h.get_by_label("Hyphenate");
+ h.get_by_label("Align to Baseline Grid").click();
+ h.run_steps(3);
+ let a = text_attrs(h.state_mut()).unwrap();
+ assert_eq!(a["chars"]["capitalization"], "smallCaps");
+ assert_eq!(a["para"]["gridAlign"], "allLines");
+ // ••• again folds the section.
+ h.get_all_by_label("More Options").next().unwrap().click();
+ h.run_steps(3);
+ assert!(h.query_by_label("Small Caps").is_none());
+ }
+
+ /// The Paragraph panel on a First Line Only paragraph: Align to Baseline Grid shows pressed
+ /// and keeps First Line Only, and the panel menu checks Only Align First Line to Grid.
+ #[test]
+ fn paragraph_panel_keeps_first_line_only() {
+ let mut app = text_app();
+ app.run("type.para", json!({"attrs": {"gridAlign": "firstLineOnly"}})).unwrap();
+ let mut h = panel_harness(app, paragraph_panel);
+ h.run_steps(3);
+ assert_eq!(h.get_by_label("Align to Baseline Grid").accesskit_node().toggled(), Some(egui::accesskit::Toggled::True));
+ h.get_by_label("Align to Baseline Grid").click();
+ h.run_steps(3);
+ assert_eq!(text_attrs(h.state_mut()).unwrap()["para"]["gridAlign"], "firstLineOnly");
+ h.get_by_label("☰").click();
+ h.run_steps(3);
+ let _ = h.get_by_label("✓ Only Align First Line to Grid");
+ }
+
+ #[test]
+ fn paragraph_panel_menu_toggles_ignore_optical_margin() {
+ let mut h = panel_harness(text_app(), paragraph_panel);
+ h.run_steps(3);
+ h.get_by_label("☰").click();
+ h.run_steps(3);
+ h.get_by_label(" Ignore Optical Margin").click();
+ h.run_steps(3);
+ assert_eq!(text_attrs(h.state_mut()).unwrap()["para"]["ignoreOpticalMargin"], true);
+ h.get_by_label("☰").click();
+ h.run_steps(3);
+ h.get_by_label("✓ Ignore Optical Margin").click();
+ h.run_steps(3);
+ assert_eq!(text_attrs(h.state_mut()).unwrap()["para"]["ignoreOpticalMargin"], false);
+ }
+
+ #[test]
+ fn paragraph_panel_menu_define_lists_opens_its_dialog() {
+ let mut h = panel_harness(text_app(), paragraph_panel);
+ h.run_steps(3);
+ h.get_by_label("☰").click();
+ h.run_steps(3);
+ h.get_by_label("Define Lists…").click();
+ h.run_steps(3);
+ assert!(h.state_mut().ui.dialog.is_some(), "Define Lists");
+ }
+
+ #[test]
+ fn paragraph_panel_is_laid_out_as_indesigns_with_its_panel_menu() {
+ let mut h = panel_harness(text_app(), paragraph_panel);
+ h.run_steps(3);
+ for l in [
+ "Left Indent",
+ "Right Indent",
+ "First Line Left Indent",
+ "Last Line Right Indent",
+ "Space Before",
+ "Space After",
+ "Space Between Paragraphs Using Same Style",
+ "Drop Cap Number of Lines",
+ "Drop Cap One or More Characters",
+ "Paragraph Shading",
+ "Paragraph Border",
+ "Hyphenate",
+ "Do Not Align to Baseline Grid",
+ ] {
+ let _ = h.get_by_label(l);
+ }
+ let para = |h: &mut Harness<'static, DesignApp>| text_attrs(h.state_mut()).unwrap()["para"].clone();
+ // Space Between Paragraphs Using Same Style starts at Ignore; a value is set, and emptying
+ // the field ignores it again.
+ assert!(para(&mut h)["sameParaStyleSpacing"].is_null());
+ let field = h.get_all_by_role(egui::accesskit::Role::TextInput).nth(6).unwrap();
+ field.focus();
+ field.type_text("6 pt");
+ h.run_steps(1);
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ assert_eq!(para(&mut h)["sameParaStyleSpacing"], 6.0);
+ h.get_all_by_role(egui::accesskit::Role::TextInput).nth(6).unwrap().focus();
+ h.run_steps(1);
+ for _ in 0..8 {
+ h.key_press(egui::Key::Backspace);
+ }
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ assert!(para(&mut h)["sameParaStyleSpacing"].is_null(), "Ignore");
+ // Shading on, then the grid buttons and Only Align First Line to Grid from the menu.
+ h.get_by_label("Shading").click();
+ h.run_steps(3);
+ assert_eq!(para(&mut h)["shadingOn"], true);
+ h.get_by_label("Align to Baseline Grid").click();
+ h.run_steps(3);
+ assert_eq!(para(&mut h)["gridAlign"], "allLines");
+ h.get_by_label("☰").click();
+ h.run_steps(3);
+ for l in
+ [" Balance Ragged Lines", "Keep Options…", "Drop Caps and Nested Styles…", "GREP Styles…", "Define Lists…", "Restart/Continue Numbering"]
+ {
+ let _ = h.get_by_label(l);
+ }
+ h.get_by_label(" Only Align First Line to Grid").click();
+ h.run_steps(3);
+ assert_eq!(para(&mut h)["gridAlign"], "firstLineOnly");
+ h.get_by_label("Do Not Align to Baseline Grid").click();
+ h.run_steps(3);
+ assert_eq!(para(&mut h)["gridAlign"], "none");
+ // Keep Options… opens the selected paragraphs' Keep Options, and OK applies them.
+ h.get_by_label("☰").click();
+ h.run_steps(3);
+ h.get_by_label("Keep Options…").click();
+ h.run_steps(3);
+ let app = h.state_mut();
+ let d = app.ui.dialog.as_mut().expect("Keep Options");
+ assert_eq!((d.id.as_str(), d.s("section").as_str()), ("paragraphLocal", "keep"));
+ d.fields.insert("p.keepWithNext".into(), json!(2));
+ crate::dialogs::confirm(app).unwrap();
+ assert_eq!(para(&mut h)["keepWithNext"], 2);
+ }
+
+ fn kerning(app: &mut DesignApp) -> Value {
+ text_attrs(app).unwrap()["chars"]["kerning"].clone()
+ }
+
+ /// A harness drawing `panel` for `app` (fonts installed before the first frame).
+ fn panel_harness(app: DesignApp, panel: fn(&mut DesignApp, &mut egui::Ui)) -> Harness<'static, DesignApp> {
+ Harness::builder().with_size(vec2(320.0, 1400.0)).build_ui_state(
+ move |ui, app: &mut DesignApp| {
+ let id = egui::Id::unique("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ panel(app, ui);
+ },
+ app,
+ )
+ }
+
+ fn text_app() -> DesignApp {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "AVATAR", "caret": true})).unwrap();
+ app.run("edit.selectAll", json!({})).unwrap();
+ app
+ }
+
+ #[test]
+ fn properties_kerning_menu_sets_zero_kerning() {
+ let mut h = panel_harness(text_app(), show);
+ h.run_steps(3);
+ assert_eq!(kerning(h.state_mut())["kind"], "metrics");
+ h.get_by_label("Kerning").click();
+ h.run_steps(2);
+ h.get_by_label("0").click();
+ h.run_steps(2);
+ assert_eq!(kerning(h.state_mut())["kind"], "none");
+ }
+
+ fn undo_steps(app: &DesignApp) -> usize {
+ app.session.active().unwrap().history.undo.len()
+ }
+
+ fn font_style(app: &mut DesignApp) -> String {
+ text_attrs(app).unwrap()["chars"]["fontStyle"].as_str().unwrap().to_string()
+ }
+
+ /// The Digits menu uses the reference names (documented as Arabic, Hindi and Farsi), which
+ /// are translated, with a sample of each script's figures.
+ #[test]
+ fn digits_choices_use_the_reference_names() {
+ assert_eq!(DIGIT_OPTIONS.map(|o| o.1), ["Default", "Arabic", "Hindi", "Farsi", "Native"]);
+ for (lang, _) in crate::i18n::LANGUAGES {
+ let tr = |s| crate::i18n::tr(lang, s);
+ let shown: Vec<String> = DIGIT_OPTIONS.iter().map(|o| digit_label(lang, *o)).collect();
+ let expected = [
+ tr("Default").to_string(),
+ format!("{} 0123", tr("Arabic")),
+ format!("{} ٠١٢٣", tr("Hindi")),
+ format!("{} ۰۱۲۳", tr("Farsi")),
+ tr("Native").to_string(),
+ ];
+ assert_eq!(shown, expected, "{lang}");
+ }
+ }
+
+ #[test]
+ fn axes_with_an_inverted_or_missing_range_get_no_slider() {
+ let axis = |tag: &str, min: f32, max: f32| (tag.to_string(), tag.to_string(), min, min, max);
+ let kept = usable_axes(vec![axis("wght", 100.0, 900.0), axis("wdth", 125.0, 75.0), axis("opsz", f32::NAN, 72.0), axis("slnt", 0.0, 0.0)]);
+ let tags: Vec<&str> = kept.iter().map(|a| a.0.as_str()).collect();
+ assert_eq!(tags, ["wght", "slnt"]);
+ }
+
+ #[test]
+ fn variable_font_style_keeps_two_decimals_at_most() {
+ let values = [("wght".to_string(), 512.0_f32), ("wdth".to_string(), 1.25), ("opsz".to_string(), 0.4801)];
+ assert_eq!(variable_font_style("Regular", &values), "Regular {wght:512,wdth:1.25,opsz:0.48}");
+ assert_eq!(axis_step(100.0, 900.0), (1.0, 0));
+ assert_eq!(axis_step(0.48, 3.2), (0.01, 2));
+ }
+
+ #[test]
+ fn a_live_preview_held_over_many_frames_is_one_undo_step_once_let_go() {
+ let mut app = text_app();
+ let steps = undo_steps(&app);
+ let size = |app: &mut DesignApp| text_attrs(app).unwrap()["chars"]["size"].as_f64().unwrap();
+ // A drag: a preview on most frames, held without moving on others.
+ for v in [20.0, 24.0, 30.0] {
+ app.settle_live_preview();
+ app.live_preview("Size", "type.char", json!({"attrs": {"size": v}}));
+ app.settle_live_preview();
+ app.hold_live_preview();
+ }
+ assert_eq!(size(&mut app), 30.0, "the page shows the last preview");
+ assert_eq!(undo_steps(&app), steps, "nothing is undoable while held");
+ // Let go: a frame without a hold, then the frame after it commits the preview.
+ app.settle_live_preview();
+ assert_eq!(undo_steps(&app), steps, "the last held frame keeps it open");
+ app.settle_live_preview();
+ assert_eq!(undo_steps(&app), steps + 1);
+ assert!(app.session.active().unwrap().interaction.is_none());
+ app.settle_live_preview();
+ assert_eq!(undo_steps(&app), steps + 1, "committed once");
+ // Later edits get their own undo steps.
+ app.run("type.char", json!({"attrs": {"tracking": 50}})).unwrap();
+ assert_eq!(undo_steps(&app), steps + 2);
+ }
+
+ /// A system variable font with two or more axes (macOS ships some), loaded into the shared fonts.
+ fn system_variable_font() -> Option<&'static str> {
+ let candidates = [("/System/Library/Fonts/Supplemental/Skia.ttf", "Skia"), ("/System/Library/Fonts/NewYork.ttf", "New York")];
+ candidates.into_iter().find_map(|(path, family)| {
+ let bytes = std::fs::read(path).ok()?;
+ let db = designcraft_fonts::FontDb::global();
+ db.add_font(bytes);
+ let style = db.styles(family).first().cloned()?;
+ (db.axes(family, &style).len() >= 2).then_some(family)
+ })
+ }
+
+ #[test]
+ fn dragging_one_of_several_axis_sliders_is_one_undo_step() {
+ let Some(family) = system_variable_font() else {
+ eprintln!("skipped: no variable font with two axes on this system");
+ return;
+ };
+ let mut app = text_app();
+ super::super::apply_font(&mut app, &super::super::FontPick { family: family.into(), style: None });
+ let before = font_style(&mut app);
+ let steps = undo_steps(&app);
+ // The app commits a preview no panel held at the start of each frame (DesignApp::ui).
+ let mut h = Harness::builder().with_size(vec2(320.0, 1400.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ let id = egui::Id::unique("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ app.settle_live_preview();
+ character_panel(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ let sliders = h.get_all_by_role(egui::accesskit::Role::Slider).map(|n| n.rect()).collect::<Vec<_>>();
+ assert!(sliders.len() >= 2, "one slider per axis: {sliders:?}");
+ let track = sliders[0];
+ let y = track.center().y;
+ h.hover_at(egui::pos2(track.left() + 2.0, y));
+ h.run_steps(1);
+ h.drag_at(egui::pos2(track.left() + 2.0, y));
+ h.run_steps(1);
+ for k in 1..=10 {
+ h.hover_at(egui::pos2(track.left() + track.width() * k as f32 / 10.0, y));
+ h.run_steps(1);
+ assert_eq!(undo_steps(h.state()), steps, "no undo step while dragging (frame {k})");
+ }
+ let previewed = font_style(h.state_mut());
+ assert_ne!(previewed, before, "the drag previews on the page");
+ h.drop_at(egui::pos2(track.right(), y));
+ h.run_steps(3);
+ assert_eq!(undo_steps(h.state()), steps + 1, "the whole drag is one undo step");
+ assert_eq!(font_style(h.state_mut()), previewed);
+ h.state_mut().run("edit.undo", json!({})).unwrap();
+ assert_eq!(font_style(h.state_mut()), before);
+ }
+
+ #[test]
+ fn character_panel_has_kerning_and_takes_a_typed_manual_value() {
+ let mut h = panel_harness(text_app(), character_panel);
+ h.run_steps(3);
+ // The caption and the control share the name: click the control.
+ h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Kerning").click();
+ h.run_steps(2);
+ // Address the manual-value editor by semantics, not tree traversal order.
+ let field = h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Manual Kerning");
+ field.focus();
+ field.type_text("-40");
+ h.run_steps(1);
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ assert_eq!(kerning(h.state_mut()), json!({"kind": "manual", "value": -40.0}));
+ }
+
+ #[test]
+ fn a_manual_kerning_value_at_a_caret_kerns_the_pair() {
+ let mut app = text_app();
+ let story = app.session.active().unwrap().selection.text.unwrap().story;
+ app.run("text.select", json!({"story": story.0, "anchor": 1, "focus": 1})).unwrap();
+ let mut h = panel_harness(app, character_panel);
+ h.run_steps(3);
+ h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Kerning").click();
+ h.run_steps(2);
+ let field = h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Manual Kerning");
+ field.focus();
+ field.type_text("-80");
+ h.run_steps(1);
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ let st = h.state_mut().session.active().unwrap().doc.story(story).unwrap().format_after(0).over.kerning;
+ assert_eq!(st, Some(designcraft_doc::Kerning::Manual(-80.0)), "A of the A|V pair");
+ assert_eq!(kerning(h.state_mut()), json!({"kind": "manual", "value": -80.0}));
+ }
+
+ #[test]
+ fn clicking_a_swatch_chip_in_the_appearance_fill_menu_applies_it() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ // A graphic frame: the Appearance section shows a single Fill chip.
+ let id = app.run("frame.create", json!({"rect": [72, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();
+ app.run("selection.set", json!({"ids": [id]})).unwrap();
+ let before = app.session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.swatch.clone();
+ assert_ne!(before, "[Paper]");
+ let mut h = Harness::builder().with_size(vec2(320.0, 1400.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ let id = egui::Id::unique("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ show(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ // Open the Fill menu from the Appearance chip.
+ h.get_by_label("Fill swatch").click();
+ h.run_steps(3);
+ // Click the *chip* (the row's left edge), not the name.
+ let name = "[Paper]".to_string();
+ let row = h.get_by_label(&name).rect();
+ // The row spans the menu (chip + name), not just the name text.
+ assert!(row.width() > 150.0, "the row is the full menu width, chip included: {row:?}");
+ let p = row.min + vec2(8.0, row.height() / 2.0);
+ h.hover_at(p);
+ h.drag_at(p);
+ h.drop_at(p);
+ h.run_steps(4);
+ let after = h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.swatch.clone();
+ assert_eq!(after, name, "clicking the swatch chip applies it");
+ }
+
+ fn panel(app: DesignApp) -> Harness<'static, DesignApp> {
+ let mut h = Harness::builder().with_size(vec2(320.0, 1400.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ let id = egui::Id::unique("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ show(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ h
+ }
+
++ /// The course's chapter 21: Properties › Bullets and Numbering › Options opens the Bullets
++ /// and Numbering dialog, as InDesign's, not the Paragraph panel.
++ #[test]
++ fn bullets_options_open_the_bullets_and_numbering_dialog() {
++ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
++ app.run("file.new", json!({})).unwrap();
++ let f = app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "4 eggs"})).unwrap();
++ app.run("text.select", json!({"story": f["story"], "anchor": 0, "focus": 6})).unwrap();
++ let mut h = panel(app);
++ h.get_by_label("Options").click();
++ h.run_steps(3);
++ let d = h.state().ui.dialog.clone().expect("a dialog");
++ assert_eq!((d.id.as_str(), d.s("section").as_str()), ("paragraphLocal", "bullets"));
++ assert_ne!(h.state().ui.open_panel.as_deref(), Some("paragraph"));
++ }
++
+ /// The course's chapter 21: Properties' Bulleted List button gives the selected paragraphs
+ /// bullets with InDesign's hanging indent; pressed again, both go.
+ #[test]
+ fn the_bulleted_list_button_applies_a_hanging_indent() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let f = app
+ .run(
+ "frame.create",
+ json!({"rect": [72, 72, 300, 200], "content": "text", "text": "4 eggs
+ 1 cup milk"}),
+ )
+ .unwrap();
+ app.run("text.select", json!({"story": f["story"], "anchor": 0, "focus": 15})).unwrap();
+ let mut h = panel(app);
+ h.get_by_label("Bulleted List").click();
+ h.run_steps(3);
+ let a = h.state_mut().run("type.selectionAttrs", json!({})).unwrap();
+ assert_eq!(
+ (a["para"]["listType"].as_str(), a["para"]["leftIndent"].as_f64(), a["para"]["firstLineIndent"].as_f64()),
+ (Some("bullets"), Some(18.0), Some(-18.0))
+ );
+ assert_eq!(crate::menus::checked(h.state(), "list.bullets", &json!({})), Some(true), "Type › Apply Bullets shows it");
+ h.get_by_label("Bulleted List").click();
+ h.run_steps(3);
+ let a = h.state_mut().run("type.selectionAttrs", json!({})).unwrap();
+ assert_eq!((a["para"]["listType"].as_str(), a["para"]["leftIndent"].as_f64()), (Some("none"), Some(0.0)));
+ }
+
+ #[test]
+ fn several_shapes_show_pathfinder_and_intersect_combines_them() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let a = app.run("frame.create", json!({"rect": [100, 100, 300, 300], "shape": "ellipse"})).unwrap()["id"].clone();
+ let b = app.run("frame.create", json!({"rect": [200, 100, 300, 200]})).unwrap()["id"].clone();
+ // One shape: no Pathfinder section.
+ app.run("selection.set", json!({"ids": [a]})).unwrap();
+ let mut h = panel(app);
+ assert!(h.query_by_label("Pathfinder").is_none());
+ // Two: the section and its five buttons; Intersect leaves one shape, the ellipse's quarter.
+ h.state_mut().run("selection.set", json!({"ids": [a, b]})).unwrap();
+ h.run_steps(3);
+ assert!(h.query_by_label("Pathfinder").is_some());
+ for op in ["Add", "Subtract", "Intersect", "Exclude Overlap", "Minus Back"] {
+ assert!(h.query_by_label(op).is_some(), "{op}");
+ }
+ h.get_by_label("Intersect").click();
+ h.run_steps(3);
+ let doc = &h.state().session.active().unwrap().doc;
+ let items = &doc.spreads[0].items;
+ assert_eq!(items.len(), 1, "one shape left");
+ let r = items[0].bounds();
+ assert!((r.x0 - 200.0).abs() < 0.5 && (r.y1 - 200.0).abs() < 0.5 && (r.x1 - 300.0).abs() < 0.5, "{r:?}");
+ }
+
+ const CYAN: &str = "C=100 M=0 Y=0 K=0";
+
+ #[test]
+ fn the_fill_menu_sets_a_tint() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let id = app.run("frame.create", json!({"rect": [72, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();
+ app.run("object.fill", json!({"swatch": CYAN, "ids": [id]})).unwrap();
+ app.run("selection.set", json!({"ids": [id]})).unwrap();
+ let mut h = panel(app);
+ h.get_by_label("Fill swatch").click();
+ h.run_steps(3);
+ // A frame that isn't a text frame: no Apply To.
+ assert!(h.query_by_label("Apply To:").is_none());
+ // The field on the Tint row (Opacity also reads 100%).
+ let row = h.get_by_label("Tint:").rect();
+ h.query_all_by(|n| n.role() == egui::accesskit::Role::TextInput && n.value().as_deref() == Some("100%"))
+ .find(|n| (n.rect().center().y - row.center().y).abs() < 8.0)
+ .expect("the Tint field")
+ .click();
+ h.run_steps(2);
+ h.event(egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND });
+ h.event(egui::Event::Text("25".into()));
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ let fill = h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.clone();
+ assert_eq!((fill.swatch.as_str(), fill.tint), (CYAN, 0.25), "the tint, on the same swatch");
+ }
+
+ #[test]
+ fn a_tint_on_several_objects_keeps_each_ones_swatch() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let a = app.run("frame.create", json!({"rect": [72, 72, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ let b = app.run("frame.create", json!({"rect": [220, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();
+ app.run("object.fill", json!({"swatch": CYAN, "ids": [a]})).unwrap();
+ app.run("object.fill", json!({"swatch": "[Black]", "ids": [b]})).unwrap();
+ app.run("selection.set", json!({"ids": [a, b]})).unwrap();
+ let mut h = panel(app);
+ h.get_by_label("Fill swatch").click();
+ h.run_steps(3);
+ let row = h.get_by_label("Tint:").rect();
+ h.query_all_by(|n| n.role() == egui::accesskit::Role::TextInput && n.value().as_deref() == Some("100%"))
+ .find(|n| (n.rect().center().y - row.center().y).abs() < 8.0)
+ .expect("the Tint field")
+ .click();
+ h.run_steps(2);
+ h.event(egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND });
+ h.event(egui::Event::Text("25".into()));
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ let doc = &h.state().session.active().unwrap().doc;
+ let fill = |id: u64| doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.clone();
+ assert_eq!((fill(a).swatch.as_str(), fill(a).tint), (CYAN, 0.25));
+ assert_eq!((fill(b).swatch.as_str(), fill(b).tint), ("[Black]", 0.25), "the second keeps its own swatch");
+ }
+
+ #[test]
+ fn apply_to_text_colours_a_text_frames_text_not_the_frame() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let r = app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "Heading"})).unwrap();
+ let (id, story) = (r["id"].as_u64().unwrap(), designcraft_doc::StoryId(r["story"].as_u64().unwrap()));
+ app.run("selection.set", json!({"ids": [id]})).unwrap();
+ let mut h = panel(app);
+ h.get_by_label("Fill swatch").click();
+ h.run_steps(3);
+ h.get_by_label("Text").click();
+ h.run_steps(3);
+ h.get_by_label(CYAN).click();
+ h.run_steps(3);
+ let doc = &h.state().session.active().unwrap().doc;
+ assert_eq!(doc.story(story).unwrap().char_format_at(0).over.fill.as_deref(), Some(CYAN), "the text is cyan");
+ assert_eq!(doc.item(designcraft_doc::ids::ItemId(id)).unwrap().fill.swatch, "[None]", "the frame isn't");
+ }
+
+ #[test]
+ fn transform_flips_and_rotates_from_properties() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let id = app.run("frame.create", json!({"rect": [72, 72, 300, 200]})).unwrap()["id"].as_u64().unwrap();
+ app.run("selection.set", json!({"ids": [id]})).unwrap();
+ let mut h = panel(app);
+ let xf = |h: &Harness<'_, DesignApp>| h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().xf;
+ // Flip Horizontal mirrors the frame (a negative determinant); Flip Vertical as well brings it
+ // back to a half turn, as in the tutorial's petal.
+ h.get_by_label("Flip Horizontal").click();
+ h.run_steps(3);
+ assert!(xf(&h).determinant() < 0.0, "{:?}", xf(&h));
+ h.get_by_label("Flip Vertical").click();
+ h.run_steps(3);
+ let c = xf(&h).as_coeffs();
+ assert!((c[0] + 1.0).abs() < 1e-9 && (c[3] + 1.0).abs() < 1e-9, "a half turn: {c:?}");
+ let info = h.state_mut().session.execute("transform.info", &json!({})).unwrap();
+ assert!((info["rotation"].as_f64().unwrap().abs() - 180.0).abs() < 1e-6, "{info}");
+ // A quarter turn clockwise from there.
+ h.get_by_label("Rotate 90° Clockwise").click();
+ h.run_steps(3);
+ let info = h.state_mut().session.execute("transform.info", &json!({})).unwrap();
+ assert!((info["rotation"].as_f64().unwrap() - 90.0).abs() < 1e-6, "{info}");
+ // The angle and scale fields are there.
+ assert!(h.query_by(|n| n.role() == egui::accesskit::Role::TextInput && n.value().as_deref() == Some("90°")).is_some());
+ }
diff --cc crates/ui-egui/src/panels/properties/text.rs
index 000000000,342ad8dda..e0de1ce7c
mode 000000,100644..100644
--- a/crates/ui-egui/src/panels/properties/text.rs
+++ b/crates/ui-egui/src/panels/properties/text.rs
@@@ -1,0 -1,623 +1,624 @@@
+ use super::object::swatch_menu;
+ use super::typography::{para_field_min, show_typography_panel};
+ use super::{
+ Align, DesignApp, FIELD_H, NumField, Rect, Sense, Stroke, StrokeKind, Tokens, Ui, Value, block, full_width, icon_toggle, icons, json, link_label,
+ more_options, outline_button, place, pos2, section, set_temp_bool, show_panel, sub, temp_bool, text_attrs, units, vec2, widgets,
+ };
+
+ // ---------------------------------------------------------------- Text
+
+ pub(super) fn text_style_section(app: &mut DesignApp, ui: &mut Ui) {
+ let t = Tokens::get(ui.ctx());
+ section(ui, crate::i18n::tr(&app.ui.language, "Text Style"), true);
+ let Some(a) = text_attrs(app) else { return };
+ let tab = app.ui.text_style_tab;
+ let fw = full_width(ui);
+ if let Some(k) = widgets::segmented(
+ ui,
+ &[crate::i18n::tr(&app.ui.language, "Paragraph Styles"), crate::i18n::tr(&app.ui.language, "Character Styles")],
+ tab as usize,
+ fw,
+ ) {
+ app.ui.text_style_tab = k as u8;
+ }
+ ui.add_space(5.0);
+ let (names, cur): (Vec<String>, String) = {
+ let Some(st) = app.session.active() else { return };
+ if tab == 0 {
+ (
+ st.doc.styles.paragraph.iter().map(|p| p.name.clone()).filter(|n| n != designcraft_doc::NO_PARA_STYLE).collect(),
+ a["paragraphStyle"].as_str().unwrap_or("").to_string(),
+ )
+ } else {
+ (st.doc.styles.character.iter().map(|p| p.name.clone()).collect(), a["characterStyle"].as_str().unwrap_or("[None]").to_string())
+ }
+ };
+ let ov = if tab == 0 { a["paraOverrides"].as_u64().unwrap_or(0) + a["charOverrides"].as_u64().unwrap_or(0) } else { 0 };
+ let shown = crate::i18n::style_name(&app.ui.language, &cur);
+ let label = if ov > 0 { format!("{shown}+") } else { shown.to_string() };
+ let resp = widgets::dropdown_h(ui, "", fw, 34.0);
+ // The row paints its own swatch and name, so the dropdown itself has no text to name it.
+ let style_kind = crate::i18n::tr(&app.ui.language, if tab == 0 { "Paragraph Style" } else { "Character Style" }).to_owned();
+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, &style_kind));
+ // "Ag" swatch + style name.
+ let ag = Rect::from_min_size(resp.rect.min + vec2(6.0, 6.0), vec2(22.0, 22.0));
+ ui.painter().rect_filled(ag, 1.0, egui::Color32::WHITE);
+ ui.painter().text(ag.center(), egui::Align2::CENTER_CENTER, "Ag", egui::FontId::new(13.0, egui::FontFamily::Proportional), egui::Color32::BLACK);
+ crate::rtl::paint(
+ &ui.painter().with_clip_rect(resp.rect.shrink2(vec2(20.0, 0.0))),
+ pos2(ag.max.x + 8.0, resp.rect.center().y),
+ egui::Align2::LEFT_CENTER,
+ &label,
+ egui::FontId::proportional(11.5),
+ t.text,
+ );
+ let mut pick = None;
+ egui::Popup::menu(&resp).show(|ui| {
+ ui.set_min_width(fw);
+ egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| {
+ for n in &names {
+ if ui.selectable_label(*n == cur, crate::rtl::widget(ui, crate::i18n::style_name(&app.ui.language, n))).clicked() {
+ pick = Some(n.clone());
+ ui.close();
+ }
+ }
+ });
+ });
+ if let Some(n) = pick {
+ if tab == 0 {
+ let _ = app.run("style.paragraph.apply", json!({"name": n, "clearOverrides": false}));
+ } else {
+ let _ = app.run("style.character.apply", json!({"name": n}));
+ }
+ }
+ ui.add_space(4.0);
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 8.0;
+ if icon_toggle(
+ ui,
+ "pilcrow-menu",
+ false,
+ crate::i18n::tr(&app.ui.language, if tab == 0 { "Paragraph Styles panel" } else { "Character Styles panel" }),
+ )
+ .clicked()
+ {
+ show_panel(app, if tab == 0 { "paragraphStyles" } else { "characterStyles" });
+ }
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ ui.spacing_mut().item_spacing.x = 12.0;
+ ui.add_space(4.0);
+ if icon_toggle(ui, "style-new", false, crate::i18n::tr(&app.ui.language, crate::i18n::tr(&app.ui.language, "Create new style"))).clicked()
+ {
+ let cmd = if tab == 0 { "style.paragraph.create" } else { "style.character.create" };
+ let _ = app.run(cmd, json!({}));
+ }
+ if icon_toggle(ui, "style-clear", false, crate::i18n::tr(&app.ui.language, crate::i18n::tr(&app.ui.language, "Clear overrides")))
+ .clicked()
+ && tab == 0
+ && !cur.is_empty()
+ {
+ let _ = app.run("style.paragraph.apply", json!({"name": cur, "clearOverrides": true}));
+ }
+ if icon_toggle(ui, "style-load", false, crate::i18n::tr(&app.ui.language, "Styles panel")).clicked() {
+ show_panel(app, if tab == 0 { "paragraphStyles" } else { "characterStyles" });
+ }
+ });
+ });
+ }
+
+ pub(super) fn text_appearance_section(app: &mut DesignApp, ui: &mut Ui) {
+ let t = Tokens::get(ui.ctx());
+ let Some(a) = text_attrs(app) else { return };
+ let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return };
+ let c = &a["chars"];
+ for (k, (key, label)) in [("fill", "Fill"), ("stroke", "Stroke")].into_iter().enumerate() {
+ let sw = c[key].as_str().unwrap_or(designcraft_color::swatch::NONE).to_string();
+ let b = block(ui, FIELD_H);
+ let (col, g) = widgets::swatch_colors(&doc, &sw, 1.0);
+ let chip = sub(b, 4.0, 2.0, 17.0, 17.0);
+ if k == 0 {
+ widgets::paint_chip(ui.painter(), chip, col, g);
+ } else {
+ widgets::paint_stroke_chip(ui.painter(), chip, col, egui::Color32::from_gray(20));
+ }
+ ui.painter().rect_stroke(chip, 0.0, Stroke::new(1.0, t.field_border), StrokeKind::Inside);
+ // The "T" marks text formatting.
+ let tc = if col.is_some_and(|c| c.r() as u32 + c.g() as u32 + c.b() as u32 > 380) { egui::Color32::BLACK } else { egui::Color32::WHITE };
+ if k == 0 {
+ ui.painter().text(chip.center(), egui::Align2::CENTER_CENTER, "T", crate::theme::semibold(12.0), tc);
+ }
+ let resp = ui.interact(chip, ui.scope_id().with(("tchip", k)), Sense::click()).on_hover_text(format!("{label}: {sw}"));
+ swatch_menu(app, &resp, &doc, &sw, k != 0, false, true);
+ if k == 0 {
+ crate::rtl::paint(
+ ui.painter(),
+ b.min + vec2(34.0, FIELD_H / 2.0),
+ egui::Align2::LEFT_CENTER,
+ crate::i18n::tr(&app.ui.language, label),
+ egui::FontId::proportional(11.5),
+ t.text,
+ );
+ } else {
+ if place(ui, sub(b, 34.0, 0.0, 56.0, FIELD_H), |ui| link_label(ui, crate::i18n::tr(&app.ui.language, label), 56.0)).clicked() {
+ show_panel(app, "stroke");
+ }
+ const WEIGHTS: &[f64] = &[0.0, 0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0];
+ if let Some(v) = place(ui, sub(b, 96.0, 0.0, 69.0, FIELD_H), |ui| {
+ NumField::number("tsw", c["strokeWeight"].as_f64(), " pt", 3).width(69.0).spinner().presets(WEIGHTS).range(0.0, 100.0).show(ui)
+ }) {
+ let _ = app.run("type.char", json!({"attrs": {"strokeWeight": v}}));
+ }
+ }
+ ui.add_space(4.0);
+ }
+ let mut behind = c["strokeBehindFill"].as_bool().unwrap_or(false);
+ if ui.checkbox(&mut behind, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Stroke Behind Fill"))).changed() {
+ let _ = app.run("type.char", json!({"attrs": {"strokeBehindFill": behind}}));
+ }
+ }
+
+ /// Character section: font family (with search), style, size/leading, kerning/tracking, •••.
+ pub(super) fn character_section(app: &mut DesignApp, ui: &mut Ui) {
+ let t = Tokens::get(ui.ctx());
+ let Some(a) = text_attrs(app) else { return };
+ let c = a["chars"].clone();
+ let fam = c["fontFamily"].as_str().unwrap_or("").to_string();
+ let sty = c["fontStyle"].as_str().unwrap_or("").to_string();
+ let fw = full_width(ui);
+ // Family dropdown with a search segment on the left.
+ let fonts = crate::panels::fonts(app);
+ let menu = crate::panels::font_menu(app);
+ let resp = widgets::dropdown(ui, "", fw);
+ // A painted search icon and family name, as in the font menus: name the field itself.
+ let family_label = crate::i18n::tr(&app.ui.language, "Font Family:").to_owned();
+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, &family_label));
+ let r = resp.rect;
+ icons::paint(ui.painter(), Rect::from_min_size(r.min + vec2(3.0, 3.0), vec2(14.0, 14.0)), "search", t.icon);
+ widgets::chevron_down(ui.painter(), r.min + vec2(22.0, 10.5), t.icon);
+ ui.painter().text(
+ r.min + vec2(30.0, 10.5),
+ egui::Align2::LEFT_CENTER,
+ if fam.is_empty() { "—".to_string() } else { crate::panels::font_label(app, &menu, &fam) },
+ egui::FontId::proportional(11.5),
+ t.text,
+ );
+ if let Some(f) = crate::panels::font_popup(app, ui, &resp, &menu, &fam) {
+ crate::panels::apply_font(app, &f);
+ }
+ ui.add_space(1.0);
+ let styles = fonts.styles(&fam);
+ let cur = styles.iter().position(|s| *s == sty);
+ if let Some(k) = widgets::dropdown_list(ui, if sty.is_empty() { "—" } else { &sty }, fw, &styles, cur) {
+ let _ = app.run("type.char", json!({"attrs": {"fontStyle": styles[k]}}));
+ }
+ ui.add_space(1.0);
+ const SIZES: &[f64] = &[6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 14.0, 18.0, 21.0, 24.0, 30.0, 36.0, 48.0, 60.0, 72.0];
+ let half = (fw - 10.0) / 2.0;
+ let b = block(ui, 2.0 * FIELD_H + 5.0);
+ let size = c["size"].as_f64();
+ let auto = c["leading"]["kind"].as_str() != Some("points");
+ let lv = if auto { size.map(|s| s * a["para"]["autoLeading"].as_f64().unwrap_or(1.2)) } else { c["leading"]["value"].as_f64() };
+ icons::paint(ui.painter(), sub(b, 0.0, 1.0, 19.0, 19.0), "font-size", t.icon);
+ if let Some(v) = place(ui, sub(b, 24.0, 0.0, half - 24.0, FIELD_H), |ui| {
+ NumField::number("csize", size, " pt", 2).width(half - 24.0).spinner().presets(SIZES).range(0.1, 1296.0).show(ui)
+ }) {
+ let _ = app.run("type.char", json!({"attrs": {"size": v}}));
+ }
+ icons::paint(ui.painter(), sub(b, half + 10.0, 1.0, 19.0, 19.0), "leading", t.icon);
+ let lw = half - 24.0;
+ let lshow = lv.map(|v| (v * 100.0).round() / 100.0);
+ if let Some(v) = place(ui, sub(b, half + 34.0, 0.0, lw, FIELD_H), |ui| {
+ let key = if auto { "cleadauto" } else { "clead" };
+ // Auto leading is shown in parentheses, like "(14.4 pt)".
+ NumField::number(key, lshow, " pt", 2).width(lw).spinner().presets(SIZES).range(0.0, 5000.0).parens(auto).show(ui)
+ }) {
+ let _ = app.run("type.char", json!({"attrs": {"leading": {"kind": "points", "value": v}}}));
+ }
+ // Kerning / tracking.
+ icons::paint(ui.painter(), sub(b, 0.0, 27.0, 19.0, 19.0), "kerning", t.icon);
+ place(ui, sub(b, 24.0, 26.0, half - 24.0, FIELD_H), |ui| kerning_control(app, ui, "ckern", &c["kerning"], half - 24.0));
+ icons::paint(ui.painter(), sub(b, half + 10.0, 27.0, 19.0, 19.0), "tracking", t.icon);
+ const TRACK: &[f64] = &[-100.0, -75.0, -50.0, -25.0, -10.0, -5.0, 0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 200.0];
+ if let Some(v) = place(ui, sub(b, half + 34.0, 26.0, lw, FIELD_H), |ui| {
+ NumField::number("ctrack", c["tracking"].as_f64(), "", 0).width(lw).spinner().presets(TRACK).step(5.0).range(-1000.0, 10000.0).show(ui)
+ }) {
+ let _ = app.run("type.char", json!({"attrs": {"tracking": v}}));
+ }
+ // ••• shows the rest in place, as InDesign's Properties panel does.
+ let more = temp_bool(ui, "props_char_more", false);
+ if more {
+ character_more(app, ui, &c, fw);
+ }
+ if more_options(ui, &app.ui.language).clicked() {
+ set_temp_bool(ui, "props_char_more", !more);
+ }
+ }
+
+ /// A percentage or other number field in one half of a two-field row, with its icon.
+ #[allow(clippy::too_many_arguments)]
+ pub(super) fn half_field(ui: &mut Ui, b: Rect, right: bool, y: f32, half: f32, icon: &str, tip: &str, field: NumField) -> Option<f64> {
+ half_field_or_clear(ui, b, right, y, half, icon, tip, field).flatten()
+ }
+
+ /// [`half_field`] for a value that may be unset: emptying the field commits `Some(None)`.
+ #[allow(clippy::too_many_arguments)]
+ pub(super) fn half_field_or_clear(
+ ui: &mut Ui,
+ b: Rect,
+ right: bool,
+ y: f32,
+ half: f32,
+ icon: &str,
+ tip: &str,
+ field: NumField,
+ ) -> Option<Option<f64>> {
+ let t = Tokens::get(ui.ctx());
+ let x = if right { half + 10.0 } else { 0.0 };
+ let ir = sub(b, x, y + 1.0, 19.0, 19.0);
+ icons::paint(ui.painter(), ir, icon, t.icon);
+ let resp = ui.interact(ir, ui.scope_id().with(("half_icon", icon)), Sense::hover());
+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, tip));
+ let label = resp.id;
+ resp.on_hover_text(tip);
+ place(ui, sub(b, x + 24.0, y, half - 24.0, FIELD_H), |ui| field.width(half - 24.0).labelled_by(label).show_or_clear(ui))
+ }
+
+ /// Properties › Character after •••: vertical and horizontal scale, baseline shift and skew,
+ /// language and OpenType, then All Caps, Small Caps, Superscript, Subscript, Underline and
+ /// Strikethrough, as InDesign lays them out.
+ fn character_more(app: &mut DesignApp, ui: &mut Ui, c: &Value, fw: f32) {
+ let lang_ui = app.ui.language.clone();
+ let tr = |s: &str| crate::i18n::tr(&lang_ui, s).to_string();
+ let half = (fw - 10.0) / 2.0;
+ let b = block(ui, 2.0 * FIELD_H + 5.0);
+ const SCALES: &[f64] = &[25.0, 50.0, 75.0, 80.0, 90.0, 100.0, 110.0, 120.0, 125.0, 150.0, 200.0];
+ let pct = |v: &Value| v.as_f64().map(|s| (s * 1000.0).round() / 10.0);
+ let field = |id, v, suffix, decimals| NumField::number(id, v, suffix, decimals).spinner();
+ if let Some(v) = half_field(
+ ui,
+ b,
+ false,
+ 0.0,
+ half,
+ "vscale",
+ &tr("Vertical Scale"),
+ field("cvscale", pct(&c["vScale"]), "%", 1).presets(SCALES).range(1.0, 1000.0),
+ ) {
+ let _ = app.run("type.char", json!({"attrs": {"vScale": v / 100.0}}));
+ }
+ if let Some(v) = half_field(
+ ui,
+ b,
+ true,
+ 0.0,
+ half,
+ "hscale",
+ &tr("Horizontal Scale"),
+ field("chscale", pct(&c["hScale"]), "%", 1).presets(SCALES).range(1.0, 1000.0),
+ ) {
+ let _ = app.run("type.char", json!({"attrs": {"hScale": v / 100.0}}));
+ }
+ if let Some(v) = half_field(
+ ui,
+ b,
+ false,
+ 26.0,
+ half,
+ "baseline-shift",
+ &tr("Baseline Shift"),
+ field("cbshift", c["baselineShift"].as_f64(), " pt", 2).range(-5000.0, 5000.0),
+ ) {
+ let _ = app.run("type.char", json!({"attrs": {"baselineShift": v}}));
+ }
+ if let Some(v) =
+ half_field(ui, b, true, 26.0, half, "skew", &tr("Skew (False Italic)"), field("cskew", c["skew"].as_f64(), "°", 1).range(-85.0, 85.0))
+ {
+ let _ = app.run("type.char", json!({"attrs": {"skew": v}}));
+ }
+ // Language (hyphenation, spelling and typographer's quotes follow it) and OpenType.
+ ui.add_space(4.0);
+ let lang = c["language"].as_str().unwrap_or("English: USA").to_string();
+ let label = tr("Language");
+ let row = block(ui, FIELD_H);
+ let resp = place(ui, sub(row, 0.0, 0.0, half, FIELD_H), |ui| widgets::dropdown(ui, crate::i18n::tr(&lang_ui, &lang), half)).on_hover_ui(|ui| {
+ crate::rtl::label(ui, label.clone());
+ });
+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, &label));
+ egui::Popup::menu(&resp).show(|ui| {
+ ui.set_min_width(half);
+ egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| language_menu(app, ui, &lang));
+ });
+ if place(ui, sub(row, half + 10.0, 0.0, half, FIELD_H), |ui| widgets::outline_button(ui, &tr("OpenType"), half)).clicked() {
+ show_typography_panel(app);
+ }
+ // The case and position buttons.
+ ui.add_space(8.0);
+ let caps = c["capitalization"].as_str().unwrap_or("normal").to_string();
+ let pos = c["position"].as_str().unwrap_or("normal").to_string();
+ let (ul, st) = (c["underline"].as_bool().unwrap_or(false), c["strikethrough"].as_bool().unwrap_or(false));
+ let buttons: [(&str, &str, bool, Value); 6] = [
+ ("TT", "All Caps", caps == "allCaps", json!({"capitalization": if caps == "allCaps" { "normal" } else { "allCaps" }})),
+ ("small-caps", "Small Caps", caps == "smallCaps", json!({"capitalization": if caps == "smallCaps" { "normal" } else { "smallCaps" }})),
+ ("T¹", "Superscript", pos == "superscript", json!({"position": if pos == "superscript" { "normal" } else { "superscript" }})),
+ ("T₁", "Subscript", pos == "subscript", json!({"position": if pos == "subscript" { "normal" } else { "subscript" }})),
+ ("T̲", "Underline", ul, json!({"underline": !ul})),
+ ("T", "Strikethrough", st, json!({"strikethrough": !st})),
+ ];
+ let pitch = fw / 6.0;
+ let row = block(ui, 22.0);
+ for (i, (text, tip, on, attrs)) in buttons.into_iter().enumerate() {
+ let r = Rect::from_center_size(row.min + vec2(pitch * (i as f32 + 0.5), 11.0), vec2(26.0, 22.0));
+ let resp = ui.interact(r, ui.scope_id().with(("case", i)), Sense::click());
+ let t = Tokens::get(ui.ctx());
+ if on {
+ ui.painter().rect_filled(r, 2.0, t.tool_active);
+ } else if resp.hovered() {
+ ui.painter().rect_filled(r, 2.0, t.hover);
+ }
+ let col = if on { t.text_strong } else { t.icon };
+ if text == "small-caps" {
+ crate::icons::paint(ui.painter(), r, "small-caps", col);
+ } else {
+ ui.painter().text(r.center(), egui::Align2::CENTER_CENTER, text, egui::FontId::proportional(13.0), col);
+ }
+ // Strikethrough: the T struck through (a combining stroke doesn't draw in every font).
+ if i == 5 {
+ ui.painter().line_segment([r.center() + vec2(-6.0, 0.5), r.center() + vec2(6.0, 0.5)], Stroke::new(1.2, col));
+ }
+ let tip = tr(tip);
+ resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, on, &tip));
+ if resp.on_hover_text(&tip).clicked() {
+ let _ = app.run("type.char", json!({"attrs": attrs}));
+ }
+ }
+ ui.add_space(4.0);
+ }
+
+ /// Paragraph section: the 9 alignment buttons and •••.
+ pub(super) fn paragraph_section(app: &mut DesignApp, ui: &mut Ui) {
+ let Some(a) = text_attrs(app) else { return };
+ let cur: Align = serde_json::from_value(a["para"]["align"].clone()).unwrap_or_default();
+ let fw = full_width(ui);
+ let pitch = fw / 9.0;
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 0.0;
+ for (al, icon) in [
+ (Align::Left, "palign-left"),
+ (Align::Center, "palign-center"),
+ (Align::Right, "palign-right"),
+ (Align::LeftJustified, "palign-justify-left"),
+ (Align::CenterJustified, "palign-justify-center"),
+ (Align::RightJustified, "palign-justify-right"),
+ (Align::FullyJustified, "palign-justify-all"),
+ (Align::TowardsSpine, "palign-spine-towards"),
+ (Align::AwayFromSpine, "palign-spine-away"),
+ ] {
+ if widgets::icon_toggle_sized(ui, icon, cur == al, al.label(), vec2(pitch.min(23.0), 21.0)).clicked() {
+ let _ = app.run("type.para", json!({"attrs": {"align": al}}));
+ }
+ if pitch > 23.0 {
+ ui.add_space(pitch - 23.0);
+ }
+ }
+ });
+ let more = temp_bool(ui, "props_para_more", false);
+ if more {
+ paragraph_more(app, ui, &a["para"], fw);
+ }
+ if more_options(ui, &app.ui.language).clicked() {
+ set_temp_bool(ui, "props_para_more", !more);
+ }
+ }
+
+ /// Properties › Paragraph after •••: left and right indent, first line and last line indent,
+ /// space before and after, drop cap lines and characters, then Hyphenate and Align to Baseline
+ /// Grid, as InDesign lays them out.
+ fn paragraph_more(app: &mut DesignApp, ui: &mut Ui, p: &Value, fw: f32) {
+ let lang_ui = app.ui.language.clone();
+ let tr = |s: &str| crate::i18n::tr(&lang_ui, s).to_string();
+ let u = units(app);
+ let half = (fw - 10.0) / 2.0;
+ ui.add_space(4.0);
+ let b = block(ui, 4.0 * FIELD_H + 15.0);
+ let rows = [
+ (("indent-left", "Left Indent", "leftIndent"), ("indent-right", "Right Indent", "rightIndent")),
+ (("indent-first", "First Line Left Indent", "firstLineIndent"), ("indent-last", "Last Line Right Indent", "lastLineIndent")),
+ (("space-before", "Space Before", "spaceBefore"), ("space-after", "Space After", "spaceAfter")),
+ ];
+ for (i, (l, r)) in rows.into_iter().enumerate() {
+ let y = i as f32 * (FIELD_H + 5.0);
+ for (right, (icon, tip, key)) in [(false, l), (true, r)] {
+ let min = para_field_min(key);
+ let field = NumField::measure(key, p[key].as_f64(), u).spinner().range(min, 10_000.0);
+ if let Some(v) = half_field(ui, b, right, y, half, icon, &tr(tip), field) {
+ let _ = app.run("type.para", json!({"attrs": {key: v}}));
+ }
+ }
+ }
+ let y = 3.0 * (FIELD_H + 5.0);
+ for (right, icon, tip, key, max) in [
+ (false, "drop-lines", "Drop Cap Number of Lines", "dropCapLines", designcraft_compose::MAX_DROP_CAP_LINES),
+ (true, "drop-chars", "Drop Cap One or More Characters", "dropCapChars", designcraft_compose::MAX_DROP_CAP_CHARS),
+ ] {
+ let field = NumField::number(key, p[key].as_f64(), "", 0).spinner().range(0.0, max as f64);
+ if let Some(v) = half_field(ui, b, right, y, half, icon, &tr(tip), field) {
+ let _ = app.run("type.para", json!({"attrs": {key: (v.max(0.0) as u64).min(max as u64)}}));
+ }
+ }
+ ui.add_space(4.0);
+ ui.horizontal(|ui| {
+ // First Line Only is aligned too: the button shows it pressed, and a click turns alignment off.
+ let grid = matches!(p["gridAlign"].as_str(), Some("allLines" | "firstLineOnly"));
+ if widgets::icon_toggle(ui, "grid-baseline", grid, &tr("Align to Baseline Grid")).clicked() {
+ let _ = app.run("type.para", json!({"attrs": {"gridAlign": if grid { "none" } else { "allLines" }}}));
+ }
+ ui.add_space(12.0);
+ let mut h = p["hyphenate"].as_bool().unwrap_or(true);
+ if widgets::checkbox(ui, &mut h, &tr("Hyphenate")).changed() {
+ let _ = app.run("type.para", json!({"attrs": {"hyphenate": h}}));
+ }
+ });
+ ui.add_space(4.0);
+ }
+
+ pub(super) fn bullets_section(app: &mut DesignApp, ui: &mut Ui) {
+ if text_attrs(app).is_none() {
+ return;
+ }
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 10.0;
+ // As InDesign's: a list with the default hanging indent, or (pressed: every selected
+ // paragraph has it, as Type › Apply Bullets shows) no list.
+ use designcraft_doc::ListType;
+ for (icon, kind, cmd, tip) in
+ [("bullets", ListType::Bullets, "list.bullets", "Bulleted List"), ("numbering", ListType::Numbers, "list.numbers", "Numbered List")]
+ {
+ let on = app.session.selection_has_list(kind);
+ if icon_toggle(ui, icon, on, crate::i18n::tr(&app.ui.language, tip)).clicked() {
+ let _ = app.run(cmd, json!({"on": !on}));
+ }
+ }
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ ui.add_space(8.0);
++ // As InDesign's: the Bullets and Numbering dialog for the selected paragraphs.
+ if outline_button(ui, crate::i18n::tr(&app.ui.language, "Options"), 66.0).clicked() {
- show_panel(app, "paragraph");
++ let _ = app.run("app.bulletsNumberingDialog", json!({}));
+ }
+ });
+ });
+ }
+
+ pub(super) fn quick_actions_text(app: &mut DesignApp, ui: &mut Ui) {
+ let fw = full_width(ui);
+ let hw = (fw - 10.0) / 2.0;
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 10.0;
+ let r = outline_button(ui, crate::i18n::tr(&app.ui.language, "Change Case"), hw);
+ egui::Popup::menu(&r).show(|ui| {
+ for (label, v) in [("UPPERCASE", "allCaps"), ("Small Caps", "smallCaps"), ("Normal", "normal")] {
+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, label))).clicked() {
+ let _ = app.run("type.char", json!({"attrs": {"capitalization": v}}));
+ ui.close();
+ }
+ }
+ });
+ if outline_button(ui, crate::i18n::tr(&app.ui.language, "Story Editor"), hw).clicked() {
+ let _ = app.run("app.storyEditor", json!({}));
+ }
+ });
+ ui.add_space(4.0);
+ if outline_button(ui, crate::i18n::tr(&app.ui.language, "Fill with Placeholder Text"), fw).clicked() {
+ let _ = app.run("type.fillWithPlaceholder", json!({}));
+ }
+ }
+
+ /// Text Frame section: columns, gutter, [Options].
+ pub(super) fn text_frame_section(app: &mut DesignApp, ui: &mut Ui) {
+ let t = Tokens::get(ui.ctx());
+ let u = units(app);
+ let Some(st) = app.session.active() else { return };
+ let fid = st.selection.items.first().copied().or_else(|| st.selection.text.and_then(|t| t.frame));
+ let Some(opts) = fid.and_then(|f| st.doc.item(f)).and_then(|i| i.text_frame()).map(|t| t.options.clone()) else { return };
+ let b = block(ui, FIELD_H);
+ icons::paint(ui.painter(), sub(b, 0.0, 1.0, 19.0, 19.0), "text-columns", t.icon);
+ if let Some(v) = place(ui, sub(b, 22.0, 0.0, 54.0, FIELD_H), |ui| {
+ NumField::number("tfcols", Some(opts.columns as f64), "", 0).width(54.0).spinner().range(1.0, 40.0).show(ui)
+ }) {
+ let _ = app.run("object.textFrameOptions", json!({"columns": v.max(1.0) as u64}));
+ }
+ icons::paint(ui.painter(), sub(b, 83.0, 1.0, 19.0, 19.0), "text-gutter", t.icon);
+ if let Some(v) = place(ui, sub(b, 105.0, 0.0, 54.0, FIELD_H), |ui| {
+ NumField::measure("tfgut", Some(opts.gutter), u).width(54.0).spinner().range(0.0, 1440.0).show(ui)
+ }) {
+ let _ = app.run("object.textFrameOptions", json!({"gutter": v}));
+ }
+ let ow = (b.max.x - 8.0) - (b.min.x + 164.0);
+ if place(ui, sub(b, 164.0, 0.5, ow, 20.0), |ui| outline_button(ui, crate::i18n::tr(&app.ui.language, "Options"), ow)).clicked() {
+ app.ui.dialog = Some(crate::dialogs::Dialog::new("textFrameOptions", json!({})));
+ }
+ }
+
+ /// Languages offered for text (InDesign-style names).
+ pub(crate) const LANGUAGES: &[&str] = &[
+ "[No Language]",
+ "English: USA",
+ "English: UK",
+ "English: Canadian",
+ "German: 2006 Reform",
+ "German: Swiss 2006 Reform",
+ "French",
+ "French: Canadian",
+ "Spanish",
+ "Italian",
+ "Portuguese",
+ "Portuguese: Brazilian",
+ "Dutch: 2005 Reform",
+ "Danish",
+ "Swedish",
+ "Norwegian: Bokmål",
+ "Finnish",
+ "Polish",
+ "Czech",
+ "Hungarian",
+ "Greek",
+ "Russian",
+ "Ukrainian",
+ "Georgian",
+ "Turkish",
+ "Japanese",
+ "Chinese",
+ "Chinese: Simplified",
+ "Chinese: Traditional",
+ "Korean",
+ "Arabic",
+ "Hebrew",
+ ];
+
+ /// The Language list (Character panel, Properties ▸ Character): picking one sets the language of
+ /// the selected text.
+ pub(crate) fn language_menu(app: &mut DesignApp, ui: &mut Ui, cur: &str) {
+ for l in LANGUAGES {
+ if ui.selectable_label(*l == cur, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, l))).clicked() {
+ let _ = app.run("type.char", json!({"attrs": {"language": l}}));
+ ui.close();
+ }
+ }
+ }
+
+ /// Kerning for the text selection, or at a caret for the pair at the caret: the label shows
+ /// Metrics, Optical, 0 or the manual value; its menu sets one of the first three or a manual value
+ /// in 1/1000 em (typed or stepped).
+ pub(crate) fn kerning_control(app: &mut DesignApp, ui: &mut egui::Ui, id: &str, k: &Value, width: f32) {
+ let kind = k["kind"].as_str().unwrap_or("metrics");
+ let manual = k["value"].as_f64().filter(|v| kind == "manual" && v.is_finite());
+ let label = match (kind, manual) {
+ ("optical", _) => "Optical".to_string(),
+ ("none", _) => "0".to_string(),
+ ("manual", Some(v)) => format!("{v}"),
+ _ => "Metrics".to_string(),
+ };
+ let resp = widgets::dropdown(ui, crate::i18n::tr(&app.ui.language, &label), width);
+ let name = crate::i18n::tr(&app.ui.language, "Kerning");
+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, name));
+ egui::Popup::menu(&resp).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| {
+ for (text, v) in [("Metrics", json!({"kind": "metrics"})), ("Optical", json!({"kind": "optical"})), ("0", json!({"kind": "none"}))] {
+ if ui.selectable_label(label == text, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, text))).clicked() {
+ let _ = app.run("type.kernPair", json!({"kerning": v}));
+ ui.close();
+ }
+ }
+ ui.separator();
+ // A manual value in 1/1000 em: after each selected character, or between the two at a caret.
+ let field = format!("{id}_manual");
+ if let Some(v) = NumField::number(&field, Some(manual.unwrap_or(0.0)), "", 0)
+ .name("Manual Kerning")
+ .width(90.0)
+ .spinner()
+ .step(5.0)
+ .range(-1000.0, 10000.0)
+ .show(ui)
+ {
+ let _ = app.run("type.kernPair", json!({"kerning": {"kind": "manual", "value": v}}));
+ }
+ });
+ }