Merge pull request #4264 from davidmann4/fix/new-doc-advanced-options-14035

New Document: Advanced Options holds Color Profile and Pixel Aspect Ratio; the depth reads 32 bit (photocraft#14035)
This commit is contained in:
David Mann authored and GitHub committed 2026-11-29 14:10:52 +01:00
commit f4ebe19d64
3 files changed
+66 -19

No files matched your search

@@ -88,6 +88,8 @@ craft_ui::words! {
/// The Color Profile entry of [`NewDocumentDialog::unmanaged_profile`]: no profile is embedded.
dont_color_manage: "newDocument.dontColorManage" = "Don't Color Manage";
background: "newDocument.background" = "Background Contents";
/// The disclosure under Background Contents that holds Color Profile and Pixel Aspect Ratio.
advanced_options: "newDocument.advancedOptions" = "Advanced Options";
white: "newDocument.white" = "White";
black: "newDocument.black" = "Black";
background_color: "newDocument.backgroundColor" = "Background Color";
@@ -111,7 +113,7 @@ craft_ui::words! {
depth_1: "newDocument.depth1" = "1 bit";
depth_8: "newDocument.depth8" = "8 bit";
depth_16: "newDocument.depth16" = "16 bit";
depth_32: "newDocument.depth32" = "32 bit (float)";
depth_32: "newDocument.depth32" = "32 bit";
orientation: "newDocument.orientation" = "Orientation";
pixel_aspect: "newDocument.pixelAspect" = "Pixel Aspect Ratio";
square_pixels: "newDocument.pixelAspectSquare" = "Square Pixels";
@@ -468,9 +470,10 @@ fn body<S: DocumentSettings>(ui: &mut Ui, form: &mut FormCx<'_, '_>, values: &mu
/// the orientation control. Saved and recent cards restore every setting but the name. A Web or Mobile card turns
/// Artboards on; a card of another category turns it off again only when such a card turned it on.
/// - Details: Name with the Save Document Preset icon, Width and Height with their units, Orientation, Artboards,
/// Resolution, Color Mode, Depth, Color Profile, Pixel Aspect Ratio (the built-in ratios, then the app's
/// [`custom_pixel_aspects`](NewDocumentDialog::custom_pixel_aspects)) and Background Contents. Bitmap takes only 1
/// bit and offers no Transparent background ([`DocumentOptions::fitted`]).
/// Resolution, Color Mode, Depth, Background Contents, then an Advanced Options disclosure (open by default)
/// holding Color Profile and Pixel Aspect Ratio (the built-in ratios, then the app's
/// [`custom_pixel_aspects`](NewDocumentDialog::custom_pixel_aspects)). Bitmap takes only 1 bit and offers no
/// Transparent background ([`DocumentOptions::fitted`]).
/// - Save Document Preset: the icon opens a pane in place of the details with the first free `Saved N` selected;
/// Save Preset or Enter saves the preset and does not create the document, Cancel goes back. The name is checked by
/// the preset library (not blank, different from the saved names ignoring case), and at most 256 presets are kept.
@@ -19,6 +19,7 @@ use crate::runtime::env::{Env, Label, Message, UnitKind, Units};
use crate::runtime::focus::{self, FocusTarget};
use crate::runtime::requests::{ColorRequest, HostAnswer};
use crate::runtime::words::CommonWords;
use crate::sections::{HeaderStrength, Section};
use crate::style::TypeRole;
use crate::text::{NumberField, TextField};
use craft_behavior::{ColumnWidth, EditEvent, EditEvents, IconId, NumberCodec, PixelSize};
@@ -312,20 +313,23 @@ fn raster_rows(ui: &mut Ui, values: &mut DocumentOptions, memory: &mut RasterMem
}
});
});
Field::new(words.profile.clone()).layout(FieldLayout::Above).id_salt("profile").show(ui, |ui, _| {
let current = values.profile.clone().filter(|profile| others.contains(&profile) || Some(profile) == unmanaged);
let shown = Select::new(words.profile.clone(), Bind::given(current), &profiles).sizing(Sizing::FillWidth).show(ui);
if let Some(profile) = shown.value().cloned() {
values.profile = profile;
}
});
Field::new(words.pixel_aspect.clone()).layout(FieldLayout::Above).id_salt("pixel-aspect").show(ui, |ui, _| {
let listed = pixel_aspects.iter().any(|entry| entry.value() == Some(&values.pixel_aspect));
let current = if listed { values.pixel_aspect.clone() } else { SQUARE_PIXELS.to_owned() };
let shown = Select::new(words.pixel_aspect.clone(), Bind::given(current), &pixel_aspects).sizing(Sizing::FillWidth).show(ui);
if let Some(id) = shown.value().cloned() {
values.pixel_aspect = id;
}
// Color Profile and Pixel Aspect Ratio stand under Advanced Options, open by default; collapsing it keeps their values.
Section::new(words.advanced_options.clone()).strength(HeaderStrength::Subheading).id_salt("advanced").show(ui, |ui, _| {
Field::new(words.profile.clone()).layout(FieldLayout::Above).id_salt("profile").show(ui, |ui, _| {
let current = values.profile.clone().filter(|profile| others.contains(&profile) || Some(profile) == unmanaged);
let shown = Select::new(words.profile.clone(), Bind::given(current), &profiles).sizing(Sizing::FillWidth).show(ui);
if let Some(profile) = shown.value().cloned() {
values.profile = profile;
}
});
Field::new(words.pixel_aspect.clone()).layout(FieldLayout::Above).id_salt("pixel-aspect").show(ui, |ui, _| {
let listed = pixel_aspects.iter().any(|entry| entry.value() == Some(&values.pixel_aspect));
let current = if listed { values.pixel_aspect.clone() } else { SQUARE_PIXELS.to_owned() };
let shown = Select::new(words.pixel_aspect.clone(), Bind::given(current), &pixel_aspects).sizing(Sizing::FillWidth).show(ui);
if let Some(id) = shown.value().cloned() {
values.pixel_aspect = id;
}
});
});
if ask_color {
@@ -3,7 +3,7 @@
use craft_behavior::MotionMode;
use craft_ui::buttons::Button;
use craft_ui::contract::{Bind, SaveKey, Show as _, clicked};
use craft_ui::contract::{Bind, Role, SaveKey, Show as _, clicked};
use craft_ui::dialog::DialogHost;
use craft_ui::display::Text;
use craft_ui::patterns::form_dialogs::{
@@ -737,6 +737,46 @@ fn without_unmanaged_profile_there_is_no_dont_color_manage() {
assert!(!shows(&fixture, "Don't Color Manage"));
}
/// Advanced Options starts open under Background Contents; folding it hides Color Profile and Pixel Aspect Ratio and keeps
/// the profile picked under it, and unfolding shows them again.
#[trial]
fn advanced_options_folds_color_profile_and_pixel_aspect_and_keeps_the_profile() {
let mut picked = DocumentOptions::default();
picked.profile = Some("display-p3".to_owned());
let held = Rc::new(RefCell::new(picked));
let shared = held.clone();
let mut fixture = Fixture::new(move |ui| {
let mut options = shared.borrow().clone();
let _ = NewDocumentDialog::new(Bind::bound(&mut options)).profiles(two_mode_profiles()).show(ui);
*shared.borrow_mut() = options;
});
// Without motion the fold finishes at once, rather than mid-animation when the assertions run.
fixture.motion(MotionMode::Off).room(Vec2::new(1400.0, 1000.0)).settle();
let background = fixture.by_label("Background Contents").expect("the Background Contents field").rect;
let tree = fixture.tree();
let advanced =
fixture.by_role(Role::BUTTON).into_iter().find(|button| tree.name_of(button.node) == Some("Advanced Options")).expect("the disclosure");
assert_eq!(tree.expanded_of(advanced.node), Some(true), "Advanced Options starts open");
assert!(background.bottom() <= advanced.rect.top(), "Advanced Options follows Background Contents");
assert!(fixture.by_label("Color Profile").is_some() && fixture.by_label("Pixel Aspect Ratio").is_some(), "open, it shows its fields");
fixture.click(&advanced).settle();
assert_eq!(fixture.tree().expanded_of(advanced.node), Some(false), "a click folds it");
assert!(fixture.by_label("Color Profile").is_none() && fixture.by_label("Pixel Aspect Ratio").is_none(), "folded, its fields are hidden");
assert_eq!(held.borrow().profile.as_deref(), Some("display-p3"), "folding keeps the profile");
// Past the double-click time, so the second click is a click of its own; the header is found again in case the fold
// moved it.
fixture.advance(1.0).frame(Vec::new());
let tree = fixture.tree();
let advanced =
fixture.by_role(Role::BUTTON).into_iter().find(|button| tree.name_of(button.node) == Some("Advanced Options")).expect("the disclosure");
fixture.click(&advanced).settle();
assert_eq!(fixture.tree().expanded_of(advanced.node), Some(true), "a second click unfolds it");
assert!(fixture.by_label("Color Profile").is_some(), "unfolded, Color Profile shows again");
assert!(shows(&fixture, "display-p3"), "with the profile still picked");
}
/// The names of the standard category `id`, in card order.
fn standard_names(id: &str) -> Vec<&'static str> {
let categories = craft_ui::patterns::form_dialogs::PresetCategory::standard();