From c531302e21c39abcca7e925ea8eb10c72b839d82 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 18:39:27 +0000 Subject: [PATCH 1/3] Start page, clear units, version in the title, diameter sign in TrueType text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DraftCraft starts on the Start page, as AutoCAD does: New drawing in Metric (millimeters) or Imperial (inches), remembered in MEASUREINIT; Open; Open sample drawing; a Workspace picker. - The status bar's units control names the unit with the format (mm · Decimal) and switches the common units directly. - The window title shows the version with the drawing: DraftCraft 2.2.0 Plan.dwg. - ⌀ (%%c) in a TrueType font without U+2300 draws the font's own Ø (or ∅) instead of the missing-glyph box; regression test diameter_sign.rs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F67RssNr67uM2HRS3vdet4 --- CHANGELOG.md | 8 ++ apps/draftcraft/src/main.rs | 6 +- crates/fonts/src/ttf.rs | 16 +++- crates/fonts/tests/diameter_sign.rs | 39 +++++++++ crates/ui-egui/src/chrome.rs | 118 +++++++++++++++++++++++----- crates/ui-egui/src/chrome/units.rs | 97 ++++++++++++++++++++--- crates/ui-egui/src/dialogs.rs | 2 +- crates/ui-egui/src/i18n/it.tsv | 12 +++ crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/ribbon.rs | 5 +- crates/ui-egui/src/window_frame.rs | 37 ++++++++- 11 files changed, 304 insertions(+), 37 deletions(-) create mode 100644 crates/fonts/tests/diameter_sign.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa27120..01bcbbd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,16 @@ How to write it (see AGENTS.md): ## Unreleased +### New +- DraftCraft starts on the Start page, as AutoCAD does: begin a new drawing in Metric (millimeters) or Imperial (inches), open a drawing or the sample, and choose your workspace. Your choice of units is remembered for the next New. + ### Improved - The About window says DraftCraft and its logo are trademarks of DraftCraft Engineering Ventures, the organization that makes DraftCraft. +- The status bar shows the drawing's unit as well as its format (for example "mm · Decimal" or "in · Architectural"), and its menu switches between millimeters, centimeters, meters, inches, feet and unitless. +- The window title shows the DraftCraft version with the drawing's name, for example "DraftCraft 2.2.0 Plan.dwg". + +### Fixed +- The diameter sign (%%c) no longer shows as a box in text that uses a TrueType font such as Arial: it draws as the font's own Ø. ## 2.2.0 diff --git a/apps/draftcraft/src/main.rs b/apps/draftcraft/src/main.rs index b811ffd1..5f0610c9 100644 --- a/apps/draftcraft/src/main.rs +++ b/apps/draftcraft/src/main.rs @@ -471,9 +471,9 @@ fn main() -> eframe::Result { app.open_path(f); } if app.session.docs.is_empty() { - // In the units the profile asks for (MEASUREINIT, restored above). - let metric = app.session.settings.measureinit; - app.session.new_drawing(metric); + // Nothing to open: start on the Start page, as AutoCAD does, where a new drawing + // is begun in metric or imperial units and the workspace is chosen. + app.ui.start_tab = true; } let ctx = cc.egui_ctx.clone(); let desktop_theme = desktop_theme::DesktopTheme::start(move || ctx.request_repaint()); diff --git a/crates/fonts/src/ttf.rs b/crates/fonts/src/ttf.rs index 9856e1d7..1386fcc4 100644 --- a/crates/fonts/src/ttf.rs +++ b/crates/fonts/src/ttf.rs @@ -1125,12 +1125,26 @@ pub(crate) fn fallback_glyph(c: char) -> Option> { Some(glyph(&f, c)).filter(|g| g.mapped) } -/// The glyph of `c` in `face`, or from a fallback font when `face` lacks it. +/// Characters that draw the same sign as `c` in fonts that lack `c`, best first. The diameter +/// sign (⌀, U+2300, what `%%c` decodes to) is in almost no TrueType font, while nearly all have +/// Ø (U+00D8), which drafting uses for it; ∅ (U+2205) is the next best. +fn look_alikes(c: char) -> &'static [char] { + match c { + '\u{2300}' => &['\u{00D8}', '\u{2205}'], + _ => &[], + } +} + +/// The glyph of `c` in `face`; when `face` lacks it, a look-alike in the same face (so the sign +/// matches the text around it), then `c` from a fallback font. Only then the missing-glyph box. fn glyph_or_fallback(face: &Face, c: char) -> Arc { let g = glyph(face, c); if g.mapped || c.is_whitespace() { return g; } + if let Some(alike) = look_alikes(c).iter().map(|&a| glyph(face, a)).find(|a| a.mapped) { + return alike; + } fallback_glyph(c).unwrap_or(g) } diff --git a/crates/fonts/tests/diameter_sign.rs b/crates/fonts/tests/diameter_sign.rs new file mode 100644 index 00000000..45d02beb --- /dev/null +++ b/crates/fonts/tests/diameter_sign.rs @@ -0,0 +1,39 @@ +//! `%%c` (⌀, U+2300) in a TrueType text style: almost no TrueType font has U+2300, so it used to +//! come out as the font's missing-character box. It must draw the font's own Ø instead. + +use std::sync::Arc; + +use draftcraft_fonts::ttf; + +/// A system font that has Ø but not ⌀ (most of them), or `None` where there is none. +fn a_face_without_the_diameter_sign() -> Option { + let dirs = ["/usr/share/fonts", "/System/Library/Fonts", "/Library/Fonts", "C:\\Windows\\Fonts"]; + let mut stack: Vec = dirs.iter().map(Into::into).collect(); + while let Some(p) = stack.pop() { + let Ok(rd) = std::fs::read_dir(&p) else { continue }; + for e in rd.flatten() { + let p = e.path(); + if p.is_dir() { + stack.push(p); + } else if p.extension().is_some_and(|x| x.eq_ignore_ascii_case("ttf")) + && let Ok(bytes) = std::fs::read(&p) + && let Some(face) = ttf::Face::new(Arc::new(bytes), 0) + && face.has_glyph('Ø') + && !face.has_glyph('\u{2300}') + { + return Some(face); + } + } + } + None +} + +#[test] +fn the_diameter_sign_draws_as_the_fonts_own_o_slash_not_a_box() { + let Some(face) = a_face_without_the_diameter_sign() else { return }; + let (Some(dia), Some(slash)) = (ttf::shape(&face, "%%c25", 2.5, 1.0, 0.0), ttf::shape(&face, "Ø25", 2.5, 1.0, 0.0)) else { + panic!("the font shapes text"); + }; + assert_eq!(dia.glyphs, slash.glyphs, "⌀ must draw exactly like the font's Ø, not the missing-glyph box"); + assert!((dia.width - slash.width).abs() < 1e-9); +} diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 9bc44f3e..0b63799b 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -382,33 +382,95 @@ pub fn start_page(app: &mut CadApp, ui: &mut egui::Ui) { let left = Rect::from_min_size(r.min, vec2(300.0, r.height())); p.rect_filled(left, 0.0, t.chrome_dark); p.rect_filled(Rect::from_min_max(pos2(left.right(), r.top()), r.max), 0.0, t.chrome); - // The DraftCraft logo beside the name and version. - crate::brand::paint(&p, Rect::from_min_size(pos2(left.left() + 30.0, left.top() + 56.0), vec2(56.0, 56.0))); + // The DraftCraft logo beside the name, and the version under it where it is easy to read. + crate::brand::paint(&p, Rect::from_min_size(pos2(left.left() + 30.0, left.top() + 44.0), vec2(56.0, 56.0))); p.text( - pos2(left.left() + 98.0, left.top() + 70.0), + pos2(left.left() + 98.0, left.top() + 60.0), egui::Align2::LEFT_CENTER, crate::tl!("DraftCraft"), egui::FontId::proportional(28.0), t.text, ); p.text( - pos2(left.left() + 98.0, left.top() + 98.0), + pos2(left.left() + 99.0, left.top() + 88.0), egui::Align2::LEFT_CENTER, crate::tf!("Version {version}", version = env!("CARGO_PKG_VERSION")), - crate::theme::small(), - t.text_faint, + crate::theme::body(), + t.text_dim, ); - let mut y = left.top() + 140.0; let mut action = None; - for (label, cmd) in [("Open...", "open"), ("New", "new"), ("New (metric)", "new.metric"), ("Open sample drawing", "sample")] { - let br = Rect::from_min_size(pos2(left.left() + 34.0, y), vec2(220.0, 34.0)); + let x = left.left() + 34.0; + let heading = |y: f32, text: &str| { + p.text(pos2(x, y), egui::Align2::LEFT_TOP, text, crate::theme::small(), t.text_faint); + }; + // New drawing: metric or imperial, as AutoCAD's two starting templates (acadiso, acad). The + // one picked is remembered (MEASUREINIT) for a plain New, and is outlined here. + let mut y = left.top() + 128.0; + heading(y, crate::tl!("NEW DRAWING")); + y += 20.0; + let metric_default = app.session.settings.measureinit; + for (metric, title, sub, cmd) in [(true, "Metric", "Millimeters", "new.metric"), (false, "Imperial", "Inches", "new.imperial")] { + let br = Rect::from_min_size(pos2(x, y), vec2(232.0, 48.0)); let resp = ui.interact(br, ui.scope_id().with(("start", cmd)), Sense::click()); - p.rect_stroke(br, 2.0, Stroke::new(1.0, if resp.hovered() { t.text } else { t.text_dim }), egui::StrokeKind::Inside); + let current = metric == metric_default; + if resp.hovered() { + p.rect_filled(br, 4.0, t.control_hover.gamma_multiply(0.5)); + } + let edge = if current { + t.accent + } else if resp.hovered() { + t.text + } else { + t.text_dim + }; + p.rect_stroke(br, 4.0, Stroke::new(if current { 1.5 } else { 1.0 }, edge), egui::StrokeKind::Inside); + p.text(pos2(br.left() + 16.0, br.top() + 16.0), egui::Align2::LEFT_CENTER, crate::i18n::t(title), crate::theme::body(), t.text); + p.text(pos2(br.left() + 16.0, br.top() + 34.0), egui::Align2::LEFT_CENTER, crate::i18n::t(sub), crate::theme::small(), t.text_dim); + let tip = if metric { crate::tl!("A new drawing in millimeters") } else { crate::tl!("A new drawing in inches") }; + if resp.on_hover_text(tip).clicked() { + action = Some(cmd); + } + y += 56.0; + } + y += 12.0; + heading(y, crate::tl!("OPEN")); + y += 20.0; + for (label, cmd) in [("Open...", "open"), ("Open sample drawing", "sample")] { + let br = Rect::from_min_size(pos2(x, y), vec2(232.0, 34.0)); + let resp = ui.interact(br, ui.scope_id().with(("start", cmd)), Sense::click()); + if resp.hovered() { + p.rect_filled(br, 4.0, t.control_hover.gamma_multiply(0.5)); + } + p.rect_stroke(br, 4.0, Stroke::new(1.0, if resp.hovered() { t.text } else { t.text_dim }), egui::StrokeKind::Inside); p.text(pos2(br.left() + 16.0, br.center().y), egui::Align2::LEFT_CENTER, crate::i18n::t(label), crate::theme::body(), t.text); if resp.clicked() { action = Some(cmd); } - y += 44.0; + y += 42.0; + } + // The workspace: the interface layout the drawing opens in, as AutoCAD's workspace switch. + y += 12.0; + heading(y, crate::tl!("WORKSPACE")); + y += 20.0; + let names = crate::workspaces::names(app); + let current = crate::workspaces::current(app); + let mut chosen = None; + let wr = Rect::from_min_size(pos2(x, y), vec2(232.0, 28.0)); + ui.scope_builder(egui::UiBuilder::new().max_rect(wr), |ui| { + let combo = craft_ui::ComboBox::from_id_salt("start_workspace").width(232.0).selected_text(current.clone()).show_ui(ui, |ui| { + for n in &names { + if ui.selectable_label(*n == current, n).clicked() { + chosen = Some(n.clone()); + } + } + }); + let name = crate::i18n::t("Workspace").to_string(); + combo.response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::ComboBox, true, &name)); + }); + if let Some(name) = chosen + && let Err(e) = crate::workspaces::set_current(app, &name) + { + app.status = Some((e, crate::now_ms())); } let main = Rect::from_min_max(pos2(left.right() + 36.0, r.top() + 40.0), r.max); p.text(main.min, egui::Align2::LEFT_TOP, crate::tl!("Recent"), egui::FontId::proportional(22.0), t.text); @@ -449,13 +511,10 @@ pub fn start_page(app: &mut CadApp, ui: &mut egui::Ui) { } match action { Some("open") => app.start("ui.open"), - Some("new") => { - app.start("new"); - app.ui.start_tab = false; - } - Some("new.metric") => { - let _ = app.run("new", json!({ "metric": true })); - app.ui.start_tab = false; + Some(cmd @ ("new.metric" | "new.imperial")) => { + if let Err(e) = start_new(app, cmd == "new.metric") { + app.status = Some((e, crate::now_ms())); + } } Some("sample") => { app.start("ui.sample"); @@ -464,10 +523,33 @@ pub fn start_page(app: &mut CadApp, ui: &mut egui::Ui) { } } +/// The Start page's New: remember metric or imperial for later plain News (MEASUREINIT, as +/// AutoCAD keeps the last template), then open a new drawing in it. +pub(crate) fn start_new(app: &mut CadApp, metric: bool) -> Result<(), String> { + // New first: SETVAR needs a drawing open, and the Start page may have none. + app.run("new", json!({ "metric": metric }))?; + app.run("setvar", json!({ "name": "MEASUREINIT", "value": i32::from(metric) }))?; + app.ui.start_tab = false; + Ok(()) +} + #[cfg(test)] mod tests { use super::*; + #[test] + fn the_start_page_new_drawing_is_in_the_chosen_units_and_remembers_them() { + // As the desktop app starts: on the Start page, with no drawing open. + let mut app = CadApp::new(draftcraft_engine::Session::empty(), crate::Services::default()); + app.ui.start_tab = true; + start_new(&mut app, false).unwrap(); + assert_eq!(app.session.doc().unwrap().header.i64("INSUNITS", -1), 1, "imperial is inches"); + assert!(!app.session.settings.measureinit); + start_new(&mut app, true).unwrap(); + assert_eq!(app.session.doc().unwrap().header.i64("INSUNITS", -1), 4, "metric is millimeters"); + assert!(app.session.settings.measureinit, "a later plain New stays metric"); + } + #[test] fn layout_tabs_that_do_not_fit_keep_the_current_one() { let w = [50.0; 6]; diff --git a/crates/ui-egui/src/chrome/units.rs b/crates/ui-egui/src/chrome/units.rs index d3bf9317..48bc3dd6 100644 --- a/crates/ui-egui/src/chrome/units.rs +++ b/crates/ui-egui/src/chrome/units.rs @@ -1,6 +1,7 @@ -//! The status bar's drawing units: it shows the length format (LUNITS) and switches it through -//! UNITS; its last entry opens the Drawing Units dialog. The same as AutoCAD's Units status -//! control, so the units can be seen and changed without typing UNITS. +//! The status bar's drawing units: it shows the drawing's unit (INSUNITS, as "mm" or "in") and +//! its length format (LUNITS), and switches either through UNITS; its last entry opens the +//! Drawing Units dialog. Like AutoCAD's Units status control, but naming the unit too, so a +//! metric drawing and an imperial one can be told apart at a glance. use egui::{Rect, Sense, pos2, vec2}; use serde_json::json; @@ -11,6 +12,52 @@ use crate::theme::Tokens; /// LUNITS values and their names, in the order the menu lists them. pub const LENGTH_FORMATS: [(i64, &str); 5] = [(4, "Architectural"), (2, "Decimal"), (3, "Engineering"), (5, "Fractional"), (1, "Scientific")]; +/// The units the menu offers directly (INSUNITS values), metric first; the rest are in the dialog. +pub const COMMON_UNITS: [i64; 6] = [4, 5, 6, 1, 2, 0]; + +/// The short name of an INSUNITS value, as the status bar shows it ("mm", "in"). Out-of-range +/// values read as unitless, as AutoCAD reads them. +pub fn unit_abbrev(insunits: i64) -> &'static str { + match insunits { + 1 => "in", + 2 => "ft", + 3 => "mi", + 4 => "mm", + 5 => "cm", + 6 => "m", + 7 => "km", + 8 => "µin", + 9 => "mil", + 10 => "yd", + 11 => "Å", + 12 => "nm", + 13 => "µm", + 14 => "dm", + 15 => "dam", + 16 => "hm", + 17 => "Gm", + 18 => "AU", + 19 => "ly", + 20 => "pc", + 21 => "US ft", + 22 => "US in", + 23 => "US yd", + 24 => "US mi", + _ => "Unitless", + } +} + +/// The full name of an INSUNITS value ("Millimeters"); out of range reads as unitless. +pub fn unit_name(insunits: i64) -> &'static str { + usize::try_from(insunits).ok().and_then(|i| crate::dialogs::INSERTION_UNITS.get(i)).copied().unwrap_or("Unitless") +} + +/// The status bar's label: the unit and the format, "mm · Decimal". +pub fn status_label(insunits: i64, lunits: i64) -> String { + let unit = if insunits == 0 { crate::i18n::t("Unitless").to_string() } else { unit_abbrev(insunits).to_string() }; + format!("{unit} · {}", crate::i18n::t(format_name(lunits))) +} + /// The name of a LUNITS value ("Decimal" for one out of range, as AutoCAD reads it). pub fn format_name(lunits: i64) -> &'static str { LENGTH_FORMATS.iter().find(|(v, _)| *v == lunits).map_or("Decimal", |(_, n)| n) @@ -21,11 +68,12 @@ pub fn format_name(lunits: i64) -> &'static str { pub fn status(app: &mut CadApp, ui: &mut egui::Ui, right: f32, cy: f32) -> f32 { let Ok(d) = app.session.doc() else { return right }; let lunits = d.header.i64("LUNITS", 2); - let current = crate::i18n::t(format_name(lunits)).to_string(); + let insunits = d.header.i64("INSUNITS", 0); + let current = status_label(insunits, lunits); let t = Tokens::get(); let p = ui.painter().clone(); let g = p.layout_no_wrap(current, crate::theme::small(), t.text); - let w = g.size().x.min(140.0) + 22.0; + let w = g.size().x.min(180.0) + 22.0; let r = Rect::from_min_size(pos2(right - w, cy - 9.0), vec2(w, 18.0)); let resp = ui.interact(r, ui.scope_id().with("drawing_units"), Sense::click()); p.rect_filled(r, 3.0, if resp.hovered() { t.control_hover } else { t.control.gamma_multiply(0.5) }); @@ -34,10 +82,21 @@ pub fn status(app: &mut CadApp, ui: &mut egui::Ui, right: f32, cy: f32) -> f32 { p.line_segment([pos2(ax - 3.0, ay - 1.5), pos2(ax, ay + 1.5)], egui::Stroke::new(1.2, t.text_dim)); p.line_segment([pos2(ax, ay + 1.5), pos2(ax + 3.0, ay - 1.5)], egui::Stroke::new(1.2, t.text_dim)); crate::icons::describe_control(ui, &resp, "Drawing units", None, false); - let resp = resp.on_hover_text(crate::tl!("Drawing units")); + let tip = crate::tf!("Drawing units: {unit}, {format}", unit = crate::i18n::t(unit_name(insunits)), format = crate::i18n::t(format_name(lunits))); + let resp = resp.on_hover_text(tip); let mut pick: Option = None; + let mut pick_unit: Option = None; let mut dialog = false; - egui::Popup::from_toggle_button_response(&resp).width(170.0).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { + egui::Popup::from_toggle_button_response(&resp).width(190.0).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { + ui.label(egui::RichText::new(crate::tl!("Unit")).small().weak()); + for v in COMMON_UNITS { + if ui.selectable_label(v == insunits, crate::i18n::t(unit_name(v))).clicked() { + pick_unit = Some(v); + ui.close(); + } + } + ui.separator(); + ui.label(egui::RichText::new(crate::tl!("Format")).small().weak()); for (v, name) in LENGTH_FORMATS { if ui.selectable_label(v == lunits, crate::i18n::t(name)).clicked() { pick = Some(v); @@ -50,8 +109,13 @@ pub fn status(app: &mut CadApp, ui: &mut egui::Ui, right: f32, cy: f32) -> f32 { ui.close(); } }); - if let Some(v) = pick { - let res = app.run("units", json!({ "lunits": v })); + let change = match (pick, pick_unit) { + (Some(v), _) => Some(json!({ "lunits": v })), + (None, Some(v)) => Some(json!({ "insunits": v })), + (None, None) => None, + }; + if let Some(params) = change { + let res = app.run("units", params); app.canvas.list = None; if let Err(e) = res { app.status = Some((e, crate::now_ms())); @@ -68,6 +132,21 @@ mod tests { use super::*; /// Every format has a name, and the menu's pick reaches the drawing. + /// The status bar names the unit, so a metric drawing and an imperial one look different. + #[test] + fn the_units_label_names_the_unit_and_the_format() { + assert_eq!(status_label(4, 2), "mm · Decimal"); + assert_eq!(status_label(1, 4), "in · Architectural"); + assert_eq!(unit_name(4), "Millimeters"); + assert_eq!(unit_name(-3), "Unitless"); + assert_eq!(unit_abbrev(999), "Unitless"); + let mut app = CadApp::new(draftcraft_engine::Session::new(), crate::Services::default()); + for v in COMMON_UNITS { + app.run("units", json!({ "insunits": v })).unwrap(); + assert_eq!(app.session.doc().unwrap().header.i64("INSUNITS", -1), v); + } + } + #[test] fn the_units_control_names_and_sets_the_format() { assert_eq!(format_name(4), "Architectural"); diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 9a85b876..e0b42ec2 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -202,7 +202,7 @@ const LENGTH_TYPES: [(i64, &str); 5] = crate::chrome::units::LENGTH_FORMATS; /// AUNITS values. const ANGLE_TYPES: [(i64, &str); 5] = [(0, "Decimal Degrees"), (1, "Deg/Min/Sec"), (2, "Grads"), (3, "Radians"), (4, "Surveyor's Units")]; /// INSUNITS names, indexed by value (DXF Reference, header group code 70). -const INSERTION_UNITS: [&str; 25] = [ +pub(crate) const INSERTION_UNITS: [&str; 25] = [ "Unitless", "Inches", "Feet", diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index a4461c35..6e6bcfb9 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -1672,3 +1672,15 @@ menu Workspaces Aree di lavoro Total Area Area totale Specify point to place the totals as text Specificare il punto in cui inserire i totali come testo Rho Rho + Unit Unità + Drawing units: {unit}, {format} Unità del disegno: {unit}, {format} + NEW DRAWING NUOVO DISEGNO + OPEN APRI + WORKSPACE AREA DI LAVORO + Metric Metrico + Imperial Imperiale + Millimeters Millimetri + Inches Pollici + A new drawing in millimeters Un nuovo disegno in millimetri + A new drawing in inches Un nuovo disegno in pollici + Unitless Senza unità diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 1418b2ab..76488d58 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -759,6 +759,7 @@ impl CadApp { if ctx.current_pass_index() != 0 { return; } + window_frame::sync_os_title(self, ctx); if self.restore_modifiers.is_some() { ctx.request_repaint(); } diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 255745e2..1632bcbf 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -1251,10 +1251,7 @@ fn app_bar(app: &mut CadApp, ui: &mut egui::Ui, bar: Rect, out: &mut Out) { ui.data_mut(|d| d.insert_temp(id, scratch)); } // Window title, centred, between the toolbar and the search box. - let title = match app.session.state() { - Ok(st) if !app.ui.start_tab => format!("DraftCraft {}{}", st.title, if st.title.contains('.') { "" } else { ".dwg" }), - _ => format!("DraftCraft {}", crate::tl!("Start")), - }; + let title = crate::window_frame::window_title(app); let galley = p.layout_no_wrap(title, FontId::proportional(13.0), t.text); let right_limit = if sr.left() > qat_end + 120.0 { sr.left() - 10.0 } else { bar.right() - 8.0 }; let tx = (bar.center().x - galley.size().x / 2.0).max(qat_end); diff --git a/crates/ui-egui/src/window_frame.rs b/crates/ui-egui/src/window_frame.rs index f69eb1a3..3a82b5c2 100644 --- a/crates/ui-egui/src/window_frame.rs +++ b/crates/ui-egui/src/window_frame.rs @@ -40,6 +40,28 @@ pub fn draws_own_frame_here() -> bool { draws_own_frame(std::env::var("DRAFTCRAFT_TITLEBAR").ok().as_deref()) } +/// The window's title, as AutoCAD's names its version and the drawing: "DraftCraft 2.2.0 Start" +/// on the Start page, "DraftCraft 2.2.0 Plan.dwg" with a drawing open (".dwg" added to an +/// unsaved drawing's name). The ribbon's title row and the desktop's title bar both show it. +pub fn window_title(app: &CadApp) -> String { + let product = format!("DraftCraft {}", env!("CARGO_PKG_VERSION")); + match app.session.state() { + Ok(st) if !app.ui.start_tab => format!("{product} {}{}", st.title, if st.title.contains('.') { "" } else { ".dwg" }), + _ => format!("{product} {}", crate::tl!("Start")), + } +} + +/// Keep the desktop's window title (macOS, Linux, a system frame) the same as [`window_title`]. +/// Sent only when it changes. +pub fn sync_os_title(app: &CadApp, ctx: &egui::Context) { + let title = window_title(app); + let id = egui::Id::unique("draftcraft_os_window_title"); + if ctx.data(|d| d.get_temp::(id)).as_deref() != Some(title.as_str()) { + ctx.send_viewport_cmd(ViewportCommand::Title(title.clone())); + ctx.data_mut(|d| d.insert_temp(id, title)); + } +} + /// The window buttons, left to right. #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Caption { @@ -57,7 +79,8 @@ pub fn title_bar(app: &mut CadApp, ui: &mut egui::Ui) { let buttons = Rect::from_min_max(pos2(r.right() - BUTTON_W * 3.0, r.top()), r.max); let free = Rect::from_min_max(r.min, pos2(buttons.left(), r.bottom())); // First, so the controls drawn over it keep their own clicks. - craft_window::title_bar::empty_area(ui, free).on_hover_text("DraftCraft"); + let title = window_title(app); + craft_window::title_bar::empty_area(ui, free).on_hover_text(title.clone()); let p = ui.painter().clone(); let logo_left = r.left() + 8.0; let logo_w = crate::brand::paint_full(&p, logo_left, r.center().y, LOGO_H, t.chrome_dark); @@ -201,6 +224,18 @@ pub fn edges(ctx: &egui::Context) { mod tests { use super::*; + #[test] + fn the_window_title_names_the_version_and_the_drawing() { + let v = env!("CARGO_PKG_VERSION"); + let mut app = CadApp::new(draftcraft_engine::Session::new(), crate::Services::default()); + app.ui.start_tab = true; + assert_eq!(window_title(&app), format!("DraftCraft {v} Start")); + app.ui.start_tab = false; + let name = app.session.state().map(|s| s.title.clone()).unwrap_or_default(); + assert!(!name.is_empty()); + assert_eq!(window_title(&app), format!("DraftCraft {v} {name}.dwg")); + } + #[test] fn the_frame_is_drawn_on_windows_unless_asked_otherwise() { assert!(draws_own_frame(Some("app")) && draws_own_frame(Some(" APP "))); From 42c033058de2b4ded7016a038143ce0a01e1ced0 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 18:42:58 +0000 Subject: [PATCH 2/3] Version 2.2.1 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F67RssNr67uM2HRS3vdet4 --- CHANGELOG.md | 4 +++- Cargo.lock | 34 +++++++++++++++++----------------- Cargo.toml | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01bcbbd0..828cdf42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,15 @@ How to write it (see AGENTS.md): ## Unreleased +## 2.2.1 + ### New - DraftCraft starts on the Start page, as AutoCAD does: begin a new drawing in Metric (millimeters) or Imperial (inches), open a drawing or the sample, and choose your workspace. Your choice of units is remembered for the next New. ### Improved - The About window says DraftCraft and its logo are trademarks of DraftCraft Engineering Ventures, the organization that makes DraftCraft. - The status bar shows the drawing's unit as well as its format (for example "mm · Decimal" or "in · Architectural"), and its menu switches between millimeters, centimeters, meters, inches, feet and unitless. -- The window title shows the DraftCraft version with the drawing's name, for example "DraftCraft 2.2.0 Plan.dwg". +- The window title shows the DraftCraft version with the drawing's name, for example "DraftCraft 2.2.1 Plan.dwg". ### Fixed - The diameter sign (%%c) no longer shows as a box in text that uses a TrueType font such as Arial: it draws as the font's own Ø. diff --git a/Cargo.lock b/Cargo.lock index 8a1e0c1d..50c72123 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1196,7 +1196,7 @@ checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" [[package]] name = "draftcraft" -version = "2.2.0" +version = "2.2.1" dependencies = [ "chrono", "clap", @@ -1226,7 +1226,7 @@ dependencies = [ [[package]] name = "draftcraft-cli" -version = "2.2.0" +version = "2.2.1" dependencies = [ "clap", "clap_complete", @@ -1242,14 +1242,14 @@ dependencies = [ [[package]] name = "draftcraft-color" -version = "2.2.0" +version = "2.2.1" dependencies = [ "serde", ] [[package]] name = "draftcraft-constraints" -version = "2.2.0" +version = "2.2.1" dependencies = [ "draftcraft-doc", "draftcraft-geom", @@ -1259,7 +1259,7 @@ dependencies = [ [[package]] name = "draftcraft-doc" -version = "2.2.0" +version = "2.2.1" dependencies = [ "draftcraft-color", "draftcraft-geom", @@ -1270,14 +1270,14 @@ dependencies = [ [[package]] name = "draftcraft-dwg" -version = "2.2.0" +version = "2.2.1" dependencies = [ "chrono", ] [[package]] name = "draftcraft-dxf" -version = "2.2.0" +version = "2.2.1" dependencies = [ "encoding_rs", "log", @@ -1286,7 +1286,7 @@ dependencies = [ [[package]] name = "draftcraft-engine" -version = "2.2.0" +version = "2.2.1" dependencies = [ "craft-docpath", "draftcraft-color", @@ -1310,7 +1310,7 @@ dependencies = [ [[package]] name = "draftcraft-fonts" -version = "2.2.0" +version = "2.2.1" dependencies = [ "draftcraft-geom", "encoding_rs", @@ -1322,14 +1322,14 @@ dependencies = [ [[package]] name = "draftcraft-geom" -version = "2.2.0" +version = "2.2.1" dependencies = [ "serde", ] [[package]] name = "draftcraft-io" -version = "2.2.0" +version = "2.2.1" dependencies = [ "chrono", "craft-pdf", @@ -1352,7 +1352,7 @@ dependencies = [ [[package]] name = "draftcraft-mcp" -version = "2.2.0" +version = "2.2.1" dependencies = [ "clap", "draftcraft-engine", @@ -1366,7 +1366,7 @@ dependencies = [ [[package]] name = "draftcraft-render" -version = "2.2.0" +version = "2.2.1" dependencies = [ "draftcraft-color", "draftcraft-doc", @@ -1380,7 +1380,7 @@ dependencies = [ [[package]] name = "draftcraft-setup" -version = "2.2.0" +version = "2.2.1" dependencies = [ "rfd", "winresource", @@ -1388,7 +1388,7 @@ dependencies = [ [[package]] name = "draftcraft-ui-egui" -version = "2.2.0" +version = "2.2.1" dependencies = [ "chrono", "craft-ui", @@ -1416,7 +1416,7 @@ dependencies = [ [[package]] name = "draftcraft-web" -version = "2.2.0" +version = "2.2.1" dependencies = [ "craft-web-host", "draftcraft-engine", @@ -6151,7 +6151,7 @@ checksum = "9440ea3e5aeabb0ac63af70daf835274065238cdd0cec83418f417eae38bacee" [[package]] name = "xtask" -version = "2.2.0" +version = "2.2.1" dependencies = [ "chrono", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 8a6706a9..3ac73684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["crates/*", "apps/*", "xtask"] # default-members [workspace.package] -version = "2.2.0" +version = "2.2.1" edition = "2024" license = "MIT OR Apache-2.0" rust-version = "1.95" From 7556d7263de21570fdd6f854df2bc7ba2b38ea23 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 19:00:11 +0000 Subject: [PATCH 3/3] Window title text in shared code, so the web build compiles window_frame is desktop-only; the title text the ribbon shows moves to chrome, and only the desktop sets the OS window title. cargo xtask ci passes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F67RssNr67uM2HRS3vdet4 --- crates/ui-egui/src/chrome.rs | 23 +++++++++++++++++++++++ crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/ribbon.rs | 2 +- crates/ui-egui/src/window_frame.rs | 29 +++-------------------------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 0b63799b..855772ca 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -374,6 +374,17 @@ pub fn status_bar(app: &mut CadApp, ui: &mut egui::Ui) { }); } +/// The window's title, as AutoCAD's names its version and the drawing: "DraftCraft 2.2.0 Start" +/// on the Start page, "DraftCraft 2.2.0 Plan.dwg" with a drawing open (".dwg" added to an +/// unsaved drawing's name). The ribbon's title row and the desktop's title bar both show it. +pub fn window_title(app: &CadApp) -> String { + let product = format!("DraftCraft {}", env!("CARGO_PKG_VERSION")); + match app.session.state() { + Ok(st) if !app.ui.start_tab => format!("{product} {}{}", st.title, if st.title.contains('.') { "" } else { ".dwg" }), + _ => format!("{product} {}", crate::tl!("Start")), + } +} + /// The Start page (no drawing open, or the Start tab). pub fn start_page(app: &mut CadApp, ui: &mut egui::Ui) { let t = Tokens::get(); @@ -537,6 +548,18 @@ pub(crate) fn start_new(app: &mut CadApp, metric: bool) -> Result<(), String> { mod tests { use super::*; + #[test] + fn the_window_title_names_the_version_and_the_drawing() { + let v = env!("CARGO_PKG_VERSION"); + let mut app = CadApp::new(draftcraft_engine::Session::new(), crate::Services::default()); + app.ui.start_tab = true; + assert_eq!(window_title(&app), format!("DraftCraft {v} Start")); + app.ui.start_tab = false; + let name = app.session.state().map(|s| s.title.clone()).unwrap_or_default(); + assert!(!name.is_empty()); + assert_eq!(window_title(&app), format!("DraftCraft {v} {name}.dwg")); + } + #[test] fn the_start_page_new_drawing_is_in_the_chosen_units_and_remembers_them() { // As the desktop app starts: on the Start page, with no drawing open. diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 76488d58..e4931306 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -759,6 +759,7 @@ impl CadApp { if ctx.current_pass_index() != 0 { return; } + #[cfg(not(target_arch = "wasm32"))] window_frame::sync_os_title(self, ctx); if self.restore_modifiers.is_some() { ctx.request_repaint(); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 1632bcbf..9cee5b50 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -1251,7 +1251,7 @@ fn app_bar(app: &mut CadApp, ui: &mut egui::Ui, bar: Rect, out: &mut Out) { ui.data_mut(|d| d.insert_temp(id, scratch)); } // Window title, centred, between the toolbar and the search box. - let title = crate::window_frame::window_title(app); + let title = crate::chrome::window_title(app); let galley = p.layout_no_wrap(title, FontId::proportional(13.0), t.text); let right_limit = if sr.left() > qat_end + 120.0 { sr.left() - 10.0 } else { bar.right() - 8.0 }; let tx = (bar.center().x - galley.size().x / 2.0).max(qat_end); diff --git a/crates/ui-egui/src/window_frame.rs b/crates/ui-egui/src/window_frame.rs index 3a82b5c2..0e562fdf 100644 --- a/crates/ui-egui/src/window_frame.rs +++ b/crates/ui-egui/src/window_frame.rs @@ -40,21 +40,10 @@ pub fn draws_own_frame_here() -> bool { draws_own_frame(std::env::var("DRAFTCRAFT_TITLEBAR").ok().as_deref()) } -/// The window's title, as AutoCAD's names its version and the drawing: "DraftCraft 2.2.0 Start" -/// on the Start page, "DraftCraft 2.2.0 Plan.dwg" with a drawing open (".dwg" added to an -/// unsaved drawing's name). The ribbon's title row and the desktop's title bar both show it. -pub fn window_title(app: &CadApp) -> String { - let product = format!("DraftCraft {}", env!("CARGO_PKG_VERSION")); - match app.session.state() { - Ok(st) if !app.ui.start_tab => format!("{product} {}{}", st.title, if st.title.contains('.') { "" } else { ".dwg" }), - _ => format!("{product} {}", crate::tl!("Start")), - } -} - -/// Keep the desktop's window title (macOS, Linux, a system frame) the same as [`window_title`]. +/// Keep the desktop's window title (macOS, Linux, a system frame) the same as [`crate::chrome::window_title`]. /// Sent only when it changes. pub fn sync_os_title(app: &CadApp, ctx: &egui::Context) { - let title = window_title(app); + let title = crate::chrome::window_title(app); let id = egui::Id::unique("draftcraft_os_window_title"); if ctx.data(|d| d.get_temp::(id)).as_deref() != Some(title.as_str()) { ctx.send_viewport_cmd(ViewportCommand::Title(title.clone())); @@ -79,7 +68,7 @@ pub fn title_bar(app: &mut CadApp, ui: &mut egui::Ui) { let buttons = Rect::from_min_max(pos2(r.right() - BUTTON_W * 3.0, r.top()), r.max); let free = Rect::from_min_max(r.min, pos2(buttons.left(), r.bottom())); // First, so the controls drawn over it keep their own clicks. - let title = window_title(app); + let title = crate::chrome::window_title(app); craft_window::title_bar::empty_area(ui, free).on_hover_text(title.clone()); let p = ui.painter().clone(); let logo_left = r.left() + 8.0; @@ -224,18 +213,6 @@ pub fn edges(ctx: &egui::Context) { mod tests { use super::*; - #[test] - fn the_window_title_names_the_version_and_the_drawing() { - let v = env!("CARGO_PKG_VERSION"); - let mut app = CadApp::new(draftcraft_engine::Session::new(), crate::Services::default()); - app.ui.start_tab = true; - assert_eq!(window_title(&app), format!("DraftCraft {v} Start")); - app.ui.start_tab = false; - let name = app.session.state().map(|s| s.title.clone()).unwrap_or_default(); - assert!(!name.is_empty()); - assert_eq!(window_title(&app), format!("DraftCraft {v} {name}.dwg")); - } - #[test] fn the_frame_is_drawn_on_windows_unless_asked_otherwise() { assert!(draws_own_frame(Some("app")) && draws_own_frame(Some(" APP ")));