diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs index 289f2b20..5419f437 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs @@ -3450,8 +3450,8 @@ impl Workspace { } else { if method == "configure" { if !self.onboarding.is_open() { + self.open_model_settings(); self.key_settings = true; - self.model_settings = true; } self.model_ready = false; self.image_ready = false; @@ -5180,9 +5180,11 @@ pub(crate) fn product_form_open(app: &PhotocraftApp) -> bool { } pub fn center(app: &mut PhotocraftApp, ui: &mut Ui) -> bool { + let composer_visible = app.ui.panels.dock && composer_surface_visible(app); let Some(mut w) = app.jiansun.take() else { return false; }; + let settings_corner = ui.max_rect().left_bottom(); if !w.professional_child_active(app) && !w.material && !w.library && app.session.active().is_some() && (!w.creation_open || w.creation_step == 3) { egui::Panel::top("jiansun-creation-stages") .frame(egui::Frame::NONE.inner_margin(egui::Margin { left: 14, right: 14, top: 5, bottom: 5 })) @@ -5215,14 +5217,21 @@ pub fn center(app: &mut PhotocraftApp, ui: &mut Ui) -> bool { } } } - let used = w.material || w.library || (w.creation_open && w.creation_step != 3) || app.session.active().is_none(); + let creation_open = !w.library && w.creation_open && w.creation_step != 3; + let show_library = w.library || app.session.active().is_none(); + let library_hosts_settings = !w.material && show_library && !creation_open; + let composer_hosts_settings = composer_visible && matches!(w.agent_page(app), "canvas" | "professional"); + let used = w.material || show_library || creation_open; if w.material { w.materials_ui(app, ui); - } else if w.library || app.session.active().is_none() { + } else if show_library { w.library_ui(app, ui); - } else if w.creation_open && w.creation_step != 3 { + } else if creation_open { w.creation_ui(app, ui); } + if !library_hosts_settings && !composer_hosts_settings { + w.workspace_settings_ui(app, ui, settings_corner); + } app.jiansun = Some(w); used } @@ -5780,7 +5789,7 @@ fn action_impl(app: &mut PhotocraftApp, ctx: Option<&egui::Context>, method: &st { w.error = error; } - w.model_settings = true; + w.open_model_settings(); w.key_settings = true; } _ => { diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs index 0583c378..6154c42e 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs @@ -3304,9 +3304,7 @@ impl Workspace { if ultra { if super::stitch_ui::command_menu_item(ui, "sparkles", "生图", self.can_send_with(app, true)).clicked() { self.send_image_once(app); ui.close(); } if super::stitch_ui::command_menu_item(ui, "sliders-horizontal", "连接设置、通知与警告", true).clicked() { - self.model_settings = true; - self.prompt_library.close(); - self.maybe_check_update_on_settings_open(); + self.open_model_settings(); ui.close(); } } @@ -3355,14 +3353,12 @@ impl Workspace { } self.panel_geometry["settings"] = rect_value(response.rect); if response.clicked() { - self.model_settings = !self.model_settings; if self.model_settings { - self.prompt_library.close(); - self.maybe_check_update_on_settings_open(); - } - if !self.model_settings { + self.model_settings = false; self.api_key.clear(); self.key_settings = false; + } else { + self.open_model_settings(); } } self.settings_popup(ui, &response); @@ -3419,8 +3415,9 @@ impl Workspace { } self.panel_geometry["composerLightMode"] = json!(super::stitch_ui::composer_glow_mode(ui,self.reduce_motion)); if !self.needs_library_login() && !self.library_blocked() && !self.key_saved && super::stitch_ui::action_button(ui, "连接个人模型", super::stitch_ui::ButtonRole::Quiet, true).clicked() { - self.model_settings = true; + self.open_model_settings(); self.key_settings = true; + ui.ctx().request_repaint(); } } @@ -3744,8 +3741,8 @@ impl Workspace { self.copy_ready = false; self.image_ready = false; if !self.onboarding.is_open() { + self.open_model_settings(); self.key_settings = true; - self.model_settings = true; } } } @@ -3914,7 +3911,41 @@ impl Workspace { }); } + pub(super) fn open_model_settings(&mut self) { + if !self.model_settings { + self.model_settings = true; + self.prompt_library.close(); + self.maybe_check_update_on_settings_open(); + } + } + + pub(super) fn workspace_settings_ui(&mut self, app: &PhotocraftApp, ui: &mut Ui, corner: egui::Pos2) { + // The brief's buttons disappear when the models are ready. Anchor the + // popup and its exit animation to the workspace instead. + let inset = crate::theme::agent_scale::space::MD; + let anchor = ui.interact( + Rect::from_min_size(corner + vec2(inset, -inset), Vec2::ZERO), + ui.make_persistent_id("workspace-settings-anchor"), + Sense::hover(), + ); + let mounted = ui.ctx().read_response(egui::Popup::default_response_id(&anchor)).is_some(); + if self.model_settings || self.key_settings || mounted { + self.settings_popup(ui, &anchor); + } + self.flush_client_update_request(app); + if self.notifications_ui(ui) { + self.show_center(super::CenterView::Canvas, app.session.active().is_some()); + } + } + pub(super) fn settings_popup(&mut self, ui: &mut Ui, anchor: &Response) { + // The dock layout can change mid-pass. A mounted popup claims the pass + // so another host cannot draw a second copy during the handoff. + let host = Id::unique(("jiansun-settings-host", ui.ctx().viewport_id())); + let pass = ui.ctx().cumulative_pass_nr(); + if ui.data(|data| data.get_temp::(host)) == Some(pass) { + return; + } let open = self.model_settings || self.key_settings; let t = Tokens::get(ui.ctx()).agent(); let (visual, transform) = super::stitch_ui::floating_panel_motion(ui.ctx(), anchor.id.with("popup"), anchor, open, self.reduce_motion); @@ -3929,6 +3960,7 @@ impl Workspace { if !visual.render { return; } + ui.data_mut(|data| data.insert_temp(host, pass)); let frame = super::stitch_ui::overlay_frame(ui.ctx(), super::stitch_ui::SurfaceRole::Dialog, visual.opacity).inner_margin(18); let global_anchor = ui.ctx().layer_transform_to_global(anchor.layer_id).map_or(anchor.rect, |transform| transform * anchor.rect); let body_height = super::stitch_ui::floating_body_height(ui.ctx().content_rect(), global_anchor); diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/creation.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/creation.rs index a2768401..34335e58 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/creation.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/creation.rs @@ -1884,6 +1884,10 @@ impl Workspace { } return; } + // The workspace settings popup handles Escape before the brief does. + if self.model_settings || self.key_settings { + return; + } let editor = ui.ctx().memory(|memory| previous_editors.iter().copied().find(|id| memory.has_focus(*id) || memory.had_focus_last_frame(*id))); if let Some(id) = editor { if ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) { @@ -3562,7 +3566,7 @@ impl Workspace { let pick_model = stitch_ui::action_button(ui, "选择模型", stitch_ui::ButtonRole::Secondary, true); self.control_geometry("select-model", pick_model.rect); if pick_model.clicked() { - self.model_settings = true; + self.open_model_settings(); } } else if new_project && model_ok { stitch_kit::label(ui, "模型已就绪", Type::Meta, Tone::Quiet); @@ -7597,6 +7601,113 @@ mod tests { assert!(w.model_settings); } + fn brief_settings_harness(size: egui::Vec2) -> (egui_kittest::Harness<'static, PhotocraftApp>, mpsc::Receiver) { + let (tx, requests) = mpsc::channel(); + let (_, rx) = mpsc::channel(); + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let mut w = Workspace::new(tx, rx); + w.account = json!({"id":"qa"}); + w.origin = "http://localhost:3138".into(); + w.busy = None; + w.reduce_motion = true; + w.creation_catalog.insert("brands".into(), vec![]); + w.creation_catalog.insert("materials".into(), vec![]); + w.configure_client_update(json!({"version":"1.0.0"}), true, |_| Ok(())); + w.begin_staged_new_project(&app); + app.jiansun = Some(w); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(crate::cjk_fonts::install_system_provider_for_tests) + .with_size(size) + .build_ui_state(|ui, app| { + if stitch_ui::ui_fonts_ready(ui) { + crate::panels::right_dock(app, ui); + } + }, app); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ProMedium); + h.run_steps(5); + (h, requests) + } + + #[test] + fn brief_footer_settings_stays_open_after_models_become_ready() { + use egui_kittest::kittest::{NodeT, Queryable}; + + let (mut h, requests) = brief_settings_harness(vec2(1440.0, 900.0)); + let footer = control_rect(h.state().jiansun.as_ref().unwrap(), "select-model"); + h.query_all_by_label("选择模型") + .find(|button| footer.contains(button.rect().center())).unwrap().click(); + h.run_steps(4); + let title = h.get_by_label("小壹设置").accesskit_node().locate(); + assert!(h.query_by_label("对话模型").is_some()); + assert!(h.query_by_label("生图模型").is_some()); + let checks = requests.try_iter().filter(|request| { + matches!(request, Request::Action(method, input) if method == "client-update" && input["op"] == "check") + }).count(); + assert_eq!(checks, 1); + + let w = h.state_mut().jiansun.as_mut().unwrap(); + w.model_ready = true; + w.image_ready = true; + for _ in 0..4 { + h.step(); + assert_eq!(h.get_by_label("小壹设置").accesskit_node().locate(), title); + } + assert!(h.state().jiansun.as_ref().unwrap().creation_view_geometry["controls"]["select-model"].is_null()); + + h.get_by_label("关闭模型设置").click(); + h.run_steps(3); + assert!(h.query_by_label("小壹设置").is_none()); + let w = h.state().jiansun.as_ref().unwrap(); + assert!(!w.model_settings); + assert_eq!(w.agent_page(h.state()), "brief"); + } + + #[test] + fn brief_copilot_opens_one_settings_popup() { + use egui_kittest::kittest::Queryable; + + let (mut h, _requests) = brief_settings_harness(vec2(1440.0, 900.0)); + let footer = control_rect(h.state().jiansun.as_ref().unwrap(), "select-model"); + assert!(h.query_by_label("建项协作者").is_some()); + assert_eq!(h.query_all_by_label("选择模型").count(), 2); + h.query_all_by_label("选择模型") + .find(|button| !footer.contains(button.rect().center())).unwrap().click(); + h.run_steps(4); + assert_eq!(h.query_all_by_label("小壹设置").count(), 1); + assert!(h.query_by_label("对话模型").is_some()); + assert!(h.query_by_label("生图模型").is_some()); + } + + #[test] + fn brief_footer_opens_settings_with_the_agent_dock_collapsed_or_switched() { + use egui_kittest::kittest::Queryable; + + for collapsed in [true, false] { + let size = vec2(760.0, 650.0); + let (mut h, _requests) = brief_settings_harness(size); + let app = h.state_mut(); + if collapsed { + app.ui.dock.set_collapsed(crate::dock::Group::Color, true); + } else { + app.ui.dock_tabs.color = 0; + } + h.run_steps(4); + assert!(h.query_by_label("建项协作者").is_none()); + h.get_by_label("选择模型").click(); + h.run_steps(4); + let viewport = egui::Rect::from_min_size(egui::Pos2::ZERO, size); + assert!(viewport.contains_rect(h.get_by_label("小壹设置").rect())); + assert!(viewport.contains_rect(h.get_by_label("关闭模型设置").rect())); + assert!(h.query_by_label("对话模型").is_some()); + assert!(h.query_by_label("生图模型").is_some()); + + h.key_press(egui::Key::Escape); + h.run_steps(3); + assert!(h.query_by_label("小壹设置").is_none()); + assert_eq!(h.state().jiansun.as_ref().unwrap().agent_page(h.state()), "brief"); + } + } + #[test] fn staged_new_project_defers_document_creation_until_entering_canvas() { let (tx, requests) = mpsc::channel(); diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/workspace_navigation.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/workspace_navigation.rs index 0397ddd2..d0d0184e 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/workspace_navigation.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/workspace_navigation.rs @@ -381,15 +381,13 @@ impl Workspace { } if new_project && !model_ok { - let mut open_models = false; stitch_kit::inline_notice(ui, "triangle-alert", Tone::Warning, "尚未配置对话或生图模型", |ui| { if stitch_ui::action_button(ui, "选择模型", stitch_ui::ButtonRole::Secondary, true).clicked() { - open_models = true; + self.open_model_settings(); + // The center pane may already have been drawn this pass. + ui.ctx().request_repaint(); } }); - if open_models { - self.model_settings = true; - } } // Section B: Platform Data Audit Notes