mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #14493 into the merge queue batch
Reset Brightness and Contrast when toggling Use Legacy
This commit is contained in:
commit
1b96d102cb
2 files changed
+29
-3
No files matched your search
@@ -123,7 +123,8 @@ fn cancel(app: &mut PhotocraftApp, ctx: &egui::Context, id: DialogId) {
|
||||
|
||||
fn dialog_harness(app: Box<PhotocraftApp>, size: egui::Vec2) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
// Real frame times: a double-click's two clicks must land within the double-click time.
|
||||
let h = Harness::builder().with_context(app.ctx().clone()).with_size(size).with_step_dt(1.0 / 60.0).build_ui_state(|ui, app| crate::dialogs::run(app, ui), app);
|
||||
let h =
|
||||
Harness::builder().with_context(app.ctx().clone()).with_size(size).with_step_dt(1.0 / 60.0).build_ui_state(|ui, app| crate::dialogs::run(app, ui), app);
|
||||
PhotocraftApp::setup_context(&h.ctx, crate::theme::AppTheme::pro());
|
||||
h
|
||||
}
|
||||
@@ -1000,3 +1001,21 @@ fn selective_color_dialog_folds_the_single_colour_form_into_the_rows() {
|
||||
assert_eq!(shown["method"], json!("absolute"));
|
||||
assert_eq!(shown["reds"][0].as_f64(), Some(10.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggling_legacy_resets_brightness_and_contrast_in_the_dialog() {
|
||||
let mut app = app_with_image();
|
||||
let id = open(&mut app, "image.adjustments.brightnessContrast").unwrap();
|
||||
let mut h =
|
||||
Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1100.0, 760.0)).build_ui_state(|ui, app| crate::dialogs::run(app, ui), app);
|
||||
for (legacy, contrast) in [(false, 30), (true, -80)] {
|
||||
set_params(h.state_mut(), id, &json!({"brightness":40,"contrast":contrast,"legacy":legacy}));
|
||||
h.run_steps(4);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::CheckBox, "Use Legacy").click();
|
||||
h.run_steps(3);
|
||||
let out = params(h.state_mut(), id);
|
||||
assert_eq!(out["legacy"], !legacy);
|
||||
assert_eq!(out["brightness"].as_f64(), Some(0.0));
|
||||
assert_eq!(out["contrast"].as_f64(), Some(0.0));
|
||||
}
|
||||
}
|
||||
@@ -217,13 +217,20 @@ fn lifted<T>(events: EditEvents<T>, wrap: impl Fn(T) -> AdjustValue) -> AdjustOu
|
||||
AdjustOut { ask: None, edit: events.map(wrap) }
|
||||
}
|
||||
|
||||
fn reset_legacy_toggle(value: BrightnessContrast, previous_legacy: bool, reset: bool) -> BrightnessContrast {
|
||||
if reset && value.legacy != previous_legacy { BrightnessContrast::new(0.0, 0.0, value.legacy) } else { value }
|
||||
}
|
||||
|
||||
/// Shows the editor of `kind` over `value` for one pass.
|
||||
fn show(kind: &str, setup: &EditorSetup, ui: &mut Ui, value: &mut AdjustValue, cx: &mut AdjustDialogCx<'_>) -> AdjustOut {
|
||||
let context = cx.context;
|
||||
match (kind, value) {
|
||||
("brightnessContrast", AdjustValue::BrightnessContrast { value }) => {
|
||||
let out = BrightnessContrastEditor::new("Brightness/Contrast", Bind::bound(value)).context(context).show(ui);
|
||||
lifted(out.events, |value| AdjustValue::BrightnessContrast { value })
|
||||
let legacy = value.legacy;
|
||||
let out = BrightnessContrastEditor::new("Brightness/Contrast", Bind::bound(&mut *value)).context(context).show(ui);
|
||||
let reset = context.is_dialog();
|
||||
*value = reset_legacy_toggle(*value, legacy, reset);
|
||||
lifted(out.events.map(|value| reset_legacy_toggle(value, legacy, reset)), |value| AdjustValue::BrightnessContrast { value })
|
||||
}
|
||||
("levels", AdjustValue::Levels { levels }) => {
|
||||
let mut panel = LevelsPanel::new("Levels", Bind::bound(levels), setup.channels.clone())
|
||||
|
||||
Reference in new issue
Block a user