PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Type: hovering a font previews it with the Character section shown too (#5152) (#5222)
prekabreki0f3d2f133e4f
diff --git a/crates/ui-egui/src/type_font_picker_tests.rs b/crates/ui-egui/src/type_font_picker_tests.rsindex f17032523..176e683a9 100644--- a/crates/ui-egui/src/type_font_picker_tests.rs+++ b/crates/ui-egui/src/type_font_picker_tests.rs@@ -490,3 +490,43 @@ fn wheel_family_index_clamps_to_the_ends() {assert_eq!(super::wheel_family_index(1, 3, 0.0), None);assert_eq!(super::wheel_family_index(0, 0, -1.0), None);}++/// #5152: in the full app the Properties panel's Character section draws a second font picker+/// after the options bar; hovering a font in the options bar still previews it on the canvas.+#[test]+fn options_bar_hover_previews_with_the_character_picker_also_shown() {+ use crate::{PhotocraftApp, Services};+ use photocraft_doc::LayerContent;+ use serde_json::json;++ let theme = crate::theme::ThemeKind::Pro;+ let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_max_steps(64).build_eframe(move |cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, theme);+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Services::default());+ app.ui.theme = theme;+ app.run("file.new", json!({"width": 200, "height": 100})).unwrap();+ app.run("type.create", json!({"text": "Sample", "font": "Inter", "size": 18})).unwrap();+ app.ui.tool = crate::state::Tool::Type;+ app.sync_views();+ app+ });+ h.run_steps(8);+ let layer = h.state().session.active().unwrap().active_layer.unwrap();+ let font = |h: &mut Harness<'static, PhotocraftApp>| {+ let (shown, _) = crate::canvas::display_doc(h.state_mut(), 0);+ let LayerContent::Text(t) = &shown.layer(layer).unwrap().content else { panic!("type layer") };+ t.char_runs()[0].style.font_family.clone()+ };+ let pickers: Vec<_> = h.query_all_by_role(Role::ComboBox).filter(|n| n.value().as_deref() == Some("Inter")).collect();+ assert_eq!(pickers.len(), 2, "options bar and Character section both show the font picker");+ pickers[0].click();+ h.run();+ h.query_all_by_role(Role::TextInput).find(|n| n.is_focused()).expect("search field focused").type_text("JetBrains Mono");+ h.run();+ h.get_by_label("JetBrains Mono").hover();+ h.run();+ assert_eq!(font(&mut h), "JetBrains Mono");+ h.query_all_by_role(Role::TextInput).find(|n| n.is_focused()).expect("search field focused").hover();+ h.run();+ assert_eq!(font(&mut h), "Inter", "leaving the row restores the committed font");+}diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rsindex f00fb5715..bee49293b 100644--- a/crates/ui-egui/src/type_tool.rs+++ b/crates/ui-egui/src/type_tool.rs@@ -1553,7 +1553,9 @@ pub(crate) fn family_picker_in(let hover_id = egui::Id::new("type-font-hover");if let Some(f) = hovered_font {ui.ctx().data_mut(|d| d.insert_temp(hover_id, f));- } else {+ } else if egui::ComboBox::is_open(ui.ctx(), response.response.id) {+ // Only the open menu clears it: the options bar and the Character section both draw+ // this picker, and the closed one must not wipe the other's hover (#5152).ui.ctx().data_mut(|d| d.remove::<String>(hover_id));}}