DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge origin/main into codex/windows-integrated-titlebar
moppeeer6f127f9a4f0e
diff --cc crates/ui-egui/src/chrome.rsindex fdfb383ea,439fb3932..44e325394--- a/crates/ui-egui/src/chrome.rs+++ b/crates/ui-egui/src/chrome.rs@@@ -26,160 -28,108 +33,148 @@@ pub fn app_bar(app: &mut DesignApp, uilet full = ui.max_rect();let mut menus_end = full.min.x;let mut tools_start = full.max.x;- // The right-hand controls' width, measured last frame: in a window too narrow for them- // and the menus they follow the menus, and the bar scrolls sideways.- let tools_w_id = ui.id().with("tools_width");- let tools_w: f32 = ui.data(|d| d.get_temp(tools_w_id)).unwrap_or(0.0);- crate::widgets::overflow_scrolling(ui);- egui::ScrollArea::horizontal().id_salt("app_bar_scroll").auto_shrink([false, false]).show(ui, |ui| {- ui.horizontal_centered(|ui| {- if icons::button(ui, "home", 24.0, app.session.active().is_none(), crate::i18n::tr(&app.ui.language, "Home")).clicked() {- app.session_home();- }- ui.add_space(6.0);- if !app.native_menu {- ui.style_mut().visuals.widgets.inactive.weak_bg_fill = Color32::TRANSPARENT;- ui.style_mut().visuals.widgets.inactive.bg_stroke = Stroke::NONE;- ui.style_mut().visuals.widgets.hovered.bg_stroke = Stroke::NONE;- ui.style_mut().spacing.button_padding = vec2(7.0, 3.0);- crate::menus::menu_bar(app, ui);- }- menus_end = ui.min_rect().max.x;- let size = vec2(tools_slot_width(ui.available_width(), tools_w), ui.available_height());- let tools = ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| {- ui.add_space(4.0);- // Search field.- let (r, _) = ui.allocate_exact_size(vec2(125.0, 18.0), Sense::click());- ui.painter().rect(r, 1.0, t.input, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);- icons::paint(ui.painter(), egui::Rect::from_min_size(r.min + vec2(3.0, 2.0), vec2(14.0, 14.0)), "search", t.icon);- crate::rtl::paint(- ui.painter(),- r.min + vec2(20.0, 9.0),- egui::Align2::LEFT_CENTER,- crate::i18n::tr(&app.ui.language, "Search"),- egui::FontId::proportional(11.0),- t.text_dim,- );- ui.add_space(8.0);- let current = app.ui.workspace.clone();- let shown = crate::i18n::workspace_name(&app.ui.language, ¤t);- crate::menus::menu_button(- ui,- crate::rtl::widget(ui, egui::RichText::new(format!("{shown} ▾")).font(semibold(11.5)).color(t.text)),- |ui| {- let customs: Vec<String> = app.ui.custom_workspaces.iter().map(|w| w.name.clone()).collect();- for w in crate::menus::WORKSPACES.iter().map(|w| w.to_string()).chain(customs.iter().cloned()) {+ // Windows caption buttons stay at the right edge; the rest of the bar scrolls.+ let caption_w = if app.custom_titlebar { CAPTION_W } else { 0.0 };+ // Undecorated window: the bar moves it. The drag area is the whole bar but the caption+ // buttons, lower band included, registered before the menus and tools so they stay on+ // top of it: any gap drags, and the lower band is always there, however narrow the+ // window (the menus and tools scroll).+ if app.custom_titlebar {+ let drag = egui::Rect::from_min_max(+ egui::pos2(full.min.x - left as f32, full.min.y),+ egui::pos2(full.max.x - caption_w, full.min.y + BAR_H + LOWER_BAND),+ );+ let response = ui.interact(drag, egui::Id::new("window_title_drag"), Sense::click_and_drag());+ // Only from an empty part of the bar: the lower band, or the gap between the menus+ // and the tools (as they were last frame). A menu title pressed and dragged doesn't+ // move the window, as with native title bars.+ let (gap0, gap1) =+ ui.data(|d| (d.get_temp::<f32>(egui::Id::new("app_bar_menus_end")), d.get_temp::<f32>(egui::Id::new("app_bar_tools_start"))));+ let empty = |p: egui::Pos2| p.y >= full.min.y + BAR_H || matches!((gap0, gap1), (Some(a), Some(b)) if p.x >= a && p.x <= b);+ let from_empty = ui.input(|i| i.pointer.press_origin().or(i.pointer.interact_pos())).is_some_and(empty);+ if response.double_clicked() && from_empty {+ let on = !ui.input(|i| i.viewport().maximized.unwrap_or(false));+ let _ = app.run("window.maximize", json!({"on": on}));+ } else if response.drag_started_by(egui::PointerButton::Primary) && from_empty {+ let _ = app.run("window.drag", json!({}));+ }+ app.flush_window_commands(ui.ctx());+ }+ if app.custom_titlebar {+ let caption = egui::Rect::from_min_max(egui::pos2(full.max.x - caption_w, full.min.y), full.max);+ ui.scope_builder(egui::UiBuilder::new().max_rect(caption).layout(egui::Layout::right_to_left(egui::Align::Center)), |ui| {+ caption_buttons(app, ui);+ });+ }+ let scrolled = egui::Rect::from_min_max(full.min, egui::pos2(full.max.x - caption_w, full.max.y));+ ui.scope_builder(egui::UiBuilder::new().max_rect(scrolled), |ui| {+ // The right-hand controls' width, measured last frame: in a window too narrow for them+ // and the menus they follow the menus, and the bar scrolls sideways.+ let tools_w_id = ui.id().with("tools_width");+ let tools_w: f32 = ui.data(|d| d.get_temp(tools_w_id)).unwrap_or(0.0);+ crate::widgets::overflow_scrolling(ui);+ // (Drag-scrolling is touch-only by default, so a mouse drag on the bar moves the window.)+ egui::ScrollArea::horizontal().id_salt("app_bar_scroll").auto_shrink([false, false]).show(ui, |ui| {+ ui.horizontal_centered(|ui| {+ if icons::button(ui, "home", 24.0, app.session.active().is_none(), crate::i18n::tr(&app.ui.language, "Home")).clicked() {+ app.session_home();+ }+ ui.add_space(6.0);+ if !app.native_menu {+ ui.style_mut().visuals.widgets.inactive.weak_bg_fill = Color32::TRANSPARENT;+ ui.style_mut().visuals.widgets.inactive.bg_stroke = Stroke::NONE;+ ui.style_mut().visuals.widgets.hovered.bg_stroke = Stroke::NONE;+ ui.style_mut().spacing.button_padding = vec2(7.0, 3.0);+ crate::menus::menu_bar(app, ui);+ }+ menus_end = ui.min_rect().max.x;+ // Where the menus end on screen (moves as a narrow bar scrolls).+ ui.data_mut(|d| d.insert_temp(egui::Id::new("app_bar_menus_end"), menus_end));- let size = vec2(ui.available_width().max(tools_w), ui.available_height());++ let size = vec2(tools_slot_width(ui.available_width(), tools_w), ui.available_height());+ let tools = ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| {+ ui.add_space(4.0);+ // Search field.+ let (r, _) = ui.allocate_exact_size(vec2(125.0, 18.0), Sense::click());+ ui.painter().rect(r, 1.0, t.input, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);+ icons::paint(ui.painter(), egui::Rect::from_min_size(r.min + vec2(3.0, 2.0), vec2(14.0, 14.0)), "search", t.icon);+ crate::rtl::paint(+ ui.painter(),+ r.min + vec2(20.0, 9.0),+ egui::Align2::LEFT_CENTER,+ crate::i18n::tr(&app.ui.language, "Search"),+ egui::FontId::proportional(11.0),+ t.text_dim,+ );+ ui.add_space(8.0);+ let current = app.ui.workspace.clone();+ let shown = crate::i18n::workspace_name(&app.ui.language, ¤t);+ crate::menus::menu_button(+ ui,+ crate::rtl::widget(ui, egui::RichText::new(format!("{shown} ▾")).font(semibold(11.5)).color(t.text)),+ |ui| {+ let customs: Vec<String> = app.ui.custom_workspaces.iter().map(|w| w.name.clone()).collect();- for w in [- "Essentials",- "Advanced",- "Book",- "Digital Publishing",- "Interactive for PDF",- "Printing and Proofing",- "Typography",- ]- .into_iter()- .map(str::to_string)- .chain(customs.iter().cloned())- {++ for w in crate::menus::WORKSPACES.iter().map(|w| w.to_string()).chain(customs.iter().cloned()) {+ if ui+ .selectable_label(w == current, crate::rtl::widget(ui, crate::i18n::workspace_name(&app.ui.language, &w)))+ .clicked()+ {+ let _ = app.run("window.workspace", json!({"name": w}));+ ui.close();+ }+ }+ ui.separator();if ui- .selectable_label(w == current, crate::rtl::widget(ui, crate::i18n::workspace_name(&app.ui.language, &w)))+ .button(crate::rtl::widget(+ ui,+ format!(+ "{} {}",+ crate::i18n::tr(&app.ui.language, "Reset"),+ crate::i18n::workspace_name(&app.ui.language, ¤t)+ ),+ )).clicked(){- let _ = app.run("window.workspace", json!({"name": w}));+ let _ = app.run("window.resetWorkspace", json!({}));+ ui.close();+ }+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "New Workspace…"))).clicked() {+ let _ = app.run("window.newWorkspace", json!({}));ui.close();}- }- ui.separator();- if ui- .button(crate::rtl::widget(- ui,- format!(- "{} {}",- crate::i18n::tr(&app.ui.language, "Reset"),- crate::i18n::workspace_name(&app.ui.language, ¤t)- ),- ))- .clicked()- {- let _ = app.run("window.resetWorkspace", json!({}));- ui.close();- }- if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "New Workspace…"))).clicked() {- let _ = app.run("window.newWorkspace", json!({}));- ui.close();- }- if !customs.is_empty() {- crate::menus::menu_button(- ui,- crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Delete Workspace")),- |ui| {- for w in &customs {- if ui.button(w).clicked() {- let _ = app.run("window.deleteWorkspace", json!({"name": w}));- ui.close();+ if !customs.is_empty() {+ crate::menus::menu_button(+ ui,+ crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Delete Workspace")),+ |ui| {+ for w in &customs {+ if ui.button(w).clicked() {+ let _ = app.run("window.deleteWorkspace", json!({"name": w}));+ ui.close();+ }}- }- },- );- }- },- );- ui.add_space(6.0);- if icons::button(ui, "share", 22.0, false, crate::i18n::tr(&app.ui.language, "Share")).clicked() {- app.status("Export a PDF, IDML or package to share — no cloud account needed.");- }- ui.add_space(8.0);- // Always one click away: the ArtCraft community Discord.- if crate::about::discord_button(ui, "Discord", vec2(78.0, 22.0)) {- let _ = app.run("help.discord", json!({}));+ },+ );+ }+ },+ );+ ui.add_space(6.0);+ if icons::button(ui, "share", 22.0, false, crate::i18n::tr(&app.ui.language, "Share")).clicked() {+ app.status("Export a PDF, IDML or package to share — no cloud account needed.");+ }+ ui.add_space(8.0);+ // Always one click away: the ArtCraft community Discord.+ if crate::about::discord_button(ui, "Discord", vec2(78.0, 22.0)) {+ let _ = app.run("help.discord", json!({}));+ }+ tools_start = ui.min_rect().min.x;+ ui.data_mut(|d| d.insert_temp(egui::Id::new("app_bar_tools_start"), tools_start));+ ui.min_rect().width()+ });+ if (tools.inner - tools_w).abs() > 0.5 {+ ui.data_mut(|d| d.insert_temp(tools_w_id, tools.inner));+ ui.ctx().request_discard("app bar: the right-hand controls changed width");}- tools_start = ui.min_rect().min.x;- ui.min_rect().width()});- if (tools.inner - tools_w).abs() > 0.5 {- ui.data_mut(|d| d.insert_temp(tools_w_id, tools.inner));- ui.ctx().request_discard("app bar: the right-hand controls changed width");- }});});// Centred title.diff --cc crates/ui-egui/src/lib.rsindex 2b0cf6ee6,59c7ebb59..71d4bbfbe--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@@ -941,12 -978,14 +986,15 @@@ impl DesignAppif self.fonts_ready {menus::shortcuts(self, ctx);}+ self.flush_window_commands(ctx);#[cfg(not(target_arch = "wasm32"))]- for f in ctx.input(|i| i.raw.dropped_files.clone()) {- let p = f.path().to_string_lossy().to_string();- if !p.is_empty() {- let _ = self.open_dropped(&p);+ {+ let (dropped, pointer) = ctx.input(|i| (i.raw.dropped_files.clone(), i.pointer.hover_pos()));+ for f in dropped {+ let p = f.path().to_string_lossy().to_string();+ if !p.is_empty() {+ let _ = self.open_dropped_at(&p, pointer);+ }}}self.handle_quit(ctx);diff --cc crates/ui-egui/src/menus.rsindex 0900391d4,a35261d59..2303f11ea--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@@ -169,13 -183,14 +183,19 @@@ pub const UI_COMMANDS: &[(&str, &str, O("window.panel.close", "Close Panel", None, "{panel} — hide a panel"),("window.dockPanel", "Dock Panel", None, "{panel} — back into the dock's icon column"),("window.controlBar", "Control", Some("Cmd+Alt+6"), "{}"),+ // Object › Fitting with InDesign's shortcuts (one `object.fit` mode each).+ ("fit.fillFrameProportionally", "Fill Frame Proportionally", Some("Cmd+Alt+Shift+C"), "{} — object.fit {mode: fillProportionally}"),+ ("fit.contentProportionally", "Fit Content Proportionally", Some("Cmd+Alt+Shift+E"), "{} — object.fit {mode: fitProportionally}"),+ ("fit.frameToContent", "Fit Frame to Content", Some("Cmd+Alt+C"), "{} — object.fit {mode: fitFrameToContent}"),+ ("fit.contentToFrame", "Fit Content to Frame", Some("Cmd+Alt+E"), "{} — object.fit {mode: fitContentToFrame}"),+ ("fit.centerContent", "Center Content", Some("Cmd+Shift+E"), "{} — object.fit {mode: centerContent}"),("window.split", "Split Window", None, "{on?: bool} — two views of the document side by side, each with its own zoom and scroll"),("window.newWindow", "New Window", None, "{on?: bool} — another view of the active document in its own window"),+ ("window.minimize", "Minimize Window", None, "{} — minimize the desktop window"),+ ("window.maximize", "Maximize/Restore Window", None, "{on?: bool} — toggle maximization when omitted"),+ ("window.close", "Close Window", None, "{} — request that the desktop window close"),+ ("window.drag", "Move Window", None, "{} — begin a native window drag while the primary mouse button is held"),+ ("window.resize", "Resize Window", None, "{edge: north|south|east|west|northEast|southEast|northWest|southWest} — begin a native edge drag"),("window.taskBar", "Contextual Task Bar", None, "{}"),("window.taskBarPin",@@@ -763,9 -850,15 +855,18 @@@ pub fn ui_label(id: &str) -> Option<(&'/// Run a UI command; `None` if `id` isn't one.pub fn run_ui(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value, String>> {+ let was_find = app.ui.dialog.as_ref().is_some_and(|d| d.id == "findChange");+ let result = run_ui_inner(app, id, p);+ if was_find && app.ui.dialog.as_ref().is_none_or(|d| d.id != "findChange") {+ app.session.reset_find_scope();+ }+ result+ }++ fn run_ui_inner(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value, String>> {+ if matches!(id, "window.minimize" | "window.maximize" | "window.close" | "window.drag" | "window.resize") && !app.custom_titlebar {+ return Some(Err("custom window controls are not available in this host".into()));+ }if let Some(result) = crate::panel_docking::command(app, id, p) {return Some(result);}@@@ -1909,11 -2012,11 +2055,14 @@@ pub fn checked(app: &DesignApp, id: &st/// Enablement for menu display (UI commands need a document unless they're app/window-level).pub fn menu_enabled(app: &DesignApp, id: &str) -> bool {+ if matches!(id, "window.minimize" | "window.maximize" | "window.close" | "window.drag" | "window.resize") {+ return app.custom_titlebar;+ }+ if id.starts_with("fit.") {+ return enabled(app, "object.fit");+ }if ui_label(id).is_some() {- return app.session.active().is_some() || id.starts_with("app.") || id.starts_with("window.");+ return app.session.active().is_some() || id.starts_with("app.") || id.starts_with("window.") || id.starts_with("help.");}enabled(app, id)}