use crate::{ExportModel, MainWindow};
use slint::ComponentHandle;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct HiddenExportSettings {
pub color_space_index: i32,
pub transfer_index: i32,
pub remote_available: bool,
}
impl HiddenExportSettings {
#[must_use]
pub const fn in_use(&self) -> bool {
self.color_space_index != 0 || (self.remote_available && self.transfer_index == 1)
}
}
pub(super) fn setup_advanced_in_use_callback(ui: &MainWindow) {
ui.global::<ExportModel>().on_advanced_in_use(
|color_space_index, transfer_index, remote_available| {
HiddenExportSettings {
color_space_index,
transfer_index,
remote_available,
}
.in_use()
},
);
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{gui::color_space_from_index, settings::ExportTransfer};
use indicatrix::color::ColorSpace;
const DEFAULT: HiddenExportSettings = HiddenExportSettings {
color_space_index: 0,
transfer_index: 0,
remote_available: true,
};
#[test]
fn the_default_export_is_not_advanced() {
assert!(!DEFAULT.in_use());
assert!(
!HiddenExportSettings {
remote_available: false,
..DEFAULT
}
.in_use()
);
}
#[test]
fn a_wide_gamut_colour_space_counts_as_in_use() {
for color_space_index in [1, 2] {
let settings = HiddenExportSettings {
color_space_index,
..DEFAULT
};
assert!(settings.in_use(), "{settings:?}");
}
}
#[test]
fn a_final_picture_transfer_counts_only_while_a_remote_is_reachable() {
let with_remote = HiddenExportSettings {
transfer_index: 1,
..DEFAULT
};
assert!(with_remote.in_use());
let without_remote = HiddenExportSettings {
remote_available: false,
..with_remote
};
assert!(!without_remote.in_use());
}
#[test]
fn the_default_pills_are_srgb_and_full_data() {
assert_eq!(
color_space_from_index(DEFAULT.color_space_index),
ColorSpace::Srgb
);
assert_eq!(
ExportTransfer::from_index(DEFAULT.transfer_index),
ExportTransfer::default()
);
assert_eq!(ExportTransfer::default().index(), DEFAULT.transfer_index);
}
}