PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Properties: the Studio-layout themes show it for every layer (#4246) (#4299)
Dan Hiornse777690ac611
diff --git a/crates/ui-egui/src/mask_props_ui_tests.rs b/crates/ui-egui/src/mask_props_ui_tests.rsindex d02af4f25..1cde90468 100644--- a/crates/ui-egui/src/mask_props_ui_tests.rs+++ b/crates/ui-egui/src/mask_props_ui_tests.rs@@ -213,3 +213,43 @@ fn refine_row_opens_the_select_and_mask_and_color_range_dialogs() {}}}++/// A Studio-layout theme's floating Properties card, with no mask targeted.+fn card_harness(new_layer: bool, theme: crate::theme::ThemeKind) -> Harness<'static, PhotocraftApp> {+ let mut session = photocraft_engine::Session::new();+ session.execute("file.new", json!({"width": 64, "height": 64, "background": "white"})).unwrap();+ if new_layer {+ session.execute("layer.new.layer", json!({})).unwrap();+ }+ let mut app = PhotocraftApp::new(session, crate::Services::default());+ app.ui.panels.properties = true;+ app.last_canvas_rect = Rect::from_min_size(egui::Pos2::ZERO, vec2(800.0, 600.0));+ let mut h = Harness::builder().with_size(vec2(800.0, 600.0)).with_step_dt(1.0 / 60.0).build_ui_state(+ |ui, app: &mut PhotocraftApp| {+ if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("semibold".into()))) {+ properties_window(app, ui.ctx());+ }+ },+ app,+ );+ PhotocraftApp::setup_context(&h.ctx, theme);+ h.run_steps(4);+ h+}++#[test]+fn floating_properties_card_shows_document_properties_for_the_background() {+ for theme in [crate::theme::ThemeKind::Studio, crate::theme::ThemeKind::BreezeDark] {+ let h = card_harness(false, theme);+ assert!(h.query_all_by_label("Document").next().is_some(), "{theme:?}: Document properties in the card");+ }+}++#[test]+fn floating_properties_card_shows_pixel_layer_properties() {+ for theme in [crate::theme::ThemeKind::Studio, crate::theme::ThemeKind::BreezeDark] {+ let h = card_harness(true, theme);+ assert!(h.query_all_by_label("Opacity").next().is_some(), "{theme:?}: layer controls in the card");+ assert!(h.query_all_by_label("Document").next().is_none());+ }+}diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex f0e004671..e8f5803b2 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -3072,7 +3072,8 @@ fn snapshot_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> Option<(&'static// ----------------------------------------------------------------------------- properties-/// Floating Properties card anchored to the canvas' top-right corner.+/// Floating Properties card anchored to the canvas' top-right corner. It shows the same content as+/// the docked panel (`properties_body`): document, layer, adjustment and mask properties.pub fn properties_window(app: &mut PhotocraftApp, ctx: &egui::Context) {if app.ui.docking.is_some() {return;@@ -3081,14 +3082,7 @@ pub fn properties_window(app: &mut PhotocraftApp, ctx: &egui::Context) {if !app.ui.panels.properties || Tokens::get(ctx).pro {return;}- let Some(st) = app.session.active() else { return };- let Some(id) = st.active_layer else { return };- let doc = st.doc.clone();- let Some(layer) = doc.layer(id) else { return };- // Mask controls (pixel or vector) also belong here when their thumbnail is targeted.- let mask_target = crate::mask_props_ui::targeted(app, layer);- let vector_target = crate::mask_props_ui::vector_targeted(app, layer);- if !mask_target && !vector_target && !matches!(layer.content, LayerContent::Adjustment(_) | LayerContent::Fill(_)) {+ if app.session.active().is_none() {return;}let t = Tokens::get(ctx);@@ -3124,41 +3118,9 @@ pub fn properties_window(app: &mut PhotocraftApp, ctx: &egui::Context) {}drag = grip.drag_delta();ui.add_space(6.0);- let icon = match &layer.content {- LayerContent::Adjustment(_) => "sliders-horizontal",- LayerContent::Group(_) => "folder",- LayerContent::Fill(_) => "paint-bucket",- _ => "image",- };- ui.horizontal(|ui| {- let (r, _) = ui.allocate_exact_size(vec2(32.0, 32.0), Sense::hover());- ui.painter().rect_filled(r, t.radius_sm, t.field);- icons::paint(ui, r, icon, 17.0, t.icon);- ui.vertical(|ui| {- ui.label(RichText::new(&layer.name).font(theme::medium(13.0)).color(t.text));- let kind = match &layer.content {- LayerContent::Adjustment(a) => crate::i18n::fmt(tl!("{name} Properties"), &[("name", tl!(a.label()))]),- // Whole phrases ("Type Layer"), as the Properties header translates them.- other => tl!(&format!("{} Layer", other.kind_name())).to_string(),- };- ui.label(RichText::new(kind).small().color(t.text_faint));- });- });- ui.add_space(8.0);widgets::hairline(ui);ui.add_space(8.0);- // Per-layer ids, so text still being typed for one layer can't commit to the next.- ui.push_id((doc.id, id, mask_target), |ui| {- if mask_target {- crate::mask_props_ui::properties(app, ui, layer);- } else if vector_target {- crate::mask_props_ui::vector_properties(app, ui, layer);- } else if let LayerContent::Adjustment(adj) = &layer.content {- adjustment_controls(app, ui, id, adj);- } else {- layer_controls(app, ui, layer);- }- });+ properties_body(app, ui);});});if drag != egui::Vec2::ZERO && canvas.is_positive() {