mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
RAW Defaults: name the 1998 space and order the color spaces (#17770)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
cbaa4dfe19
commit
b11aede392
2 files changed
+28
-3
No files matched your search
@@ -87,6 +87,9 @@ fn language_label(ctx: &egui::Context, native: &str, code: &str) -> String {
|
||||
if can_draw { native.to_string() } else { code.to_string() }
|
||||
}
|
||||
|
||||
/// The order RAW Defaults lists its color spaces in; a space not named here comes last.
|
||||
const RAW_SPACE_ORDER: [&str; 4] = ["adobeRgb", "displayP3", "proPhoto", "srgb"];
|
||||
|
||||
/// The rules of every setting from the engine's schema: choices, ranges, colours, hidden settings, the ones read
|
||||
/// at launch, and the labels and groups the window shows.
|
||||
pub(super) fn rules(ctx: &egui::Context) -> Vec<SettingRule> {
|
||||
@@ -108,7 +111,10 @@ pub(super) fn rules(ctx: &egui::Context) -> Vec<SettingRule> {
|
||||
let refs: Vec<(&str, &str)> = pairs.iter().map(|(id, label)| (id.as_str(), label.as_str())).collect();
|
||||
tweak(&mut rules, &path, |r| r.choices(&refs));
|
||||
} else if let Some(options) = prefs::choices(&path) {
|
||||
let labelled: Vec<(&str, String)> = options.iter().map(|id| (*id, choice_label(id))).collect();
|
||||
let mut labelled: Vec<(&str, String)> = options.iter().map(|id| (*id, choice_label(id))).collect();
|
||||
if path == "rawDefaults.colorSpace" {
|
||||
labelled.sort_by_key(|(id, _)| RAW_SPACE_ORDER.iter().position(|o| o == id).unwrap_or(usize::MAX));
|
||||
}
|
||||
let refs: Vec<(&str, &str)> = labelled.iter().map(|(id, label)| (*id, label.as_str())).collect();
|
||||
tweak(&mut rules, &path, |r| r.choices(&refs));
|
||||
} else if let Some((lo, hi)) = prefs::range(&path) {
|
||||
@@ -255,6 +261,8 @@ pub(super) fn choice_label(v: &str) -> String {
|
||||
"ahd" => "AHD (adaptive homogeneity)".into(),
|
||||
"mhc" => "Malvar–He–Cutler".into(),
|
||||
"cpu" => "CPU (no GPU acceleration)".into(),
|
||||
// The print dialog's name for this space, so one catalog key covers both.
|
||||
"adobeRgb" => "Adobe RGB (1998) compatible".into(),
|
||||
"displayP3" => "Display P3".into(),
|
||||
"proPhoto" => "ProPhoto RGB".into(),
|
||||
"srgb" => "sRGB IEC61966-2.1".into(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use craft::i18n::Folder;
|
||||
use craft::i18n::matcher::Matcher;
|
||||
use craft::ui::patterns::preferences::{PreferencesModel, SettingsDocument, row_matches};
|
||||
use craft::ui::patterns::preferences::{PreferencesModel, RowKind, SettingsDocument, row_matches};
|
||||
use photocraft_engine::prefs;
|
||||
|
||||
use super::{PrefPages, choice_label, rules, spelled};
|
||||
@@ -10,7 +10,7 @@ use super::{PrefPages, choice_label, rules, spelled};
|
||||
/// The labels hang on stored ids written as text, so a renamed id would silently fall back to `spelled`.
|
||||
#[test]
|
||||
fn raw_choices_have_names_of_their_own() {
|
||||
for (path, ids) in [("rawDefaults.colorSpace", &["srgb", "proPhoto", "displayP3"][..]), ("rawDefaults.sharpenFor", &["glossy", "matte"][..])] {
|
||||
for (path, ids) in [("rawDefaults.colorSpace", &["adobeRgb", "displayP3", "proPhoto", "srgb"][..]), ("rawDefaults.sharpenFor", &["glossy", "matte"][..])] {
|
||||
let offered = prefs::choices(path).expect("a choice setting");
|
||||
for id in ids {
|
||||
assert!(offered.contains(id), "{path} no longer offers {id}");
|
||||
@@ -27,3 +27,20 @@ fn preferences_search_finds_the_raw_develop_switch() {
|
||||
let found: Vec<&str> = pages.iter().flat_map(|p| &p.groups).flat_map(|g| &g.rows).filter(|r| row_matches(&matcher, r)).map(|r| r.key).collect();
|
||||
assert!(found.contains(&"rawDefaults.openInCameraRaw"), "{found:?}");
|
||||
}
|
||||
|
||||
/// The list is reordered for display only: every stored color space is still offered, each under its own id.
|
||||
#[test]
|
||||
fn raw_color_spaces_are_reordered_without_losing_one() {
|
||||
let doc = SettingsDocument::new(PrefPages::default()).expect("the default preferences").rules(rules(&egui::Context::default()));
|
||||
let pages = PreferencesModel::pages(&doc);
|
||||
let row = pages.iter().flat_map(|p| &p.groups).flat_map(|g| &g.rows).find(|r| r.key == "rawDefaults.colorSpace").expect("the row");
|
||||
let RowKind::Choice { options, .. } = &row.kind else { panic!("not a choice row") };
|
||||
let shown: Vec<String> = options.iter().filter_map(|o| o.value().map(|v| v.to_string())).collect();
|
||||
let stored: Vec<String> = prefs::choices("rawDefaults.colorSpace").expect("a choice setting").iter().map(|id| id.to_string()).collect();
|
||||
assert_ne!(shown, stored, "the stored order is shown");
|
||||
let sorted = |mut ids: Vec<String>| {
|
||||
ids.sort();
|
||||
ids
|
||||
};
|
||||
assert_eq!(sorted(shown), sorted(stored));
|
||||
}
|
||||
Reference in new issue
Block a user