fix(ui): keep 32-bit Preview Options within the window (#2081) (#2105)

This commit is contained in:
zenjabba authored and GitHub committed 2026-10-09 18:29:57 -04:00
1 parent 9200786605
commit 48fc0279e7
1 file changed
+36 -2
+36 -2
View File
@@ -417,6 +417,9 @@ fn dialog(app: &mut PhotocraftApp, ctx: &egui::Context) {
number(ui, &mut f, "ratio", tl!("Factor:"), 0.1..=10.0);
}
"preview32" => {
// A slider fills its available width. Keep its field above it, so the
// field cannot grow an auto-sized window beyond that width each frame.
ui.set_width((ctx.content_rect().width() - 32.0).clamp(0.0, 320.0));
let mut m = f.get("method").and_then(Value::as_str).unwrap_or("exposureGamma").to_string();
if crate::widgets::dropdown(
ui,
@@ -428,8 +431,12 @@ fn dialog(app: &mut PhotocraftApp, ctx: &egui::Context) {
f.insert("method".into(), json!(m));
}
ui.add_enabled_ui(m == "exposureGamma", |ui| {
number(ui, &mut f, "exposure", tl!("Exposure:"), -20.0..=20.0);
number(ui, &mut f, "gamma", tl!("Gamma:"), 0.1..=9.99);
for (key, label, range) in [("exposure", tl!("Exposure:"), -20.0..=20.0), ("gamma", tl!("Gamma:"), 0.1..=9.99)] {
let mut v = f.get(key).and_then(Value::as_f64).unwrap_or(0.0) as f32;
if crate::widgets::slider_row(ui, label, &mut v, range, "", None).changed() {
f.insert(key.into(), json!(v));
}
}
});
}
_ => {
@@ -596,6 +603,33 @@ mod tests {
}
}
#[test]
fn thirty_two_bit_preview_window_fits_and_stops_growing() {
use egui_kittest::{Harness, kittest::Queryable};
for (size, scale) in [(vec2(760.0, 480.0), 1.0), (vec2(420.0, 360.0), 2.0)] {
for theme in crate::theme::ThemeKind::ALL {
let (mut app, _) = app();
app.run("file.new", json!({"width": 20, "height": 20, "depth": 32})).unwrap();
let mut h = Harness::builder().with_size(size).with_pixels_per_point(scale).build_ui_state(|ui, app| windows(app, ui.ctx()), app);
PhotocraftApp::setup_context(&h.ctx, theme);
let ctx = h.ctx.clone();
crate::menus::invoke(h.state_mut(), &ctx, "view.thirtyTwoBitPreviewOptions", json!({})).unwrap();
h.run_steps(4);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, size);
let first = h.ctx.memory(|m| m.area_rect(egui::Id::new("shell-dialog"))).unwrap();
h.run_steps(20);
let last = h.ctx.memory(|m| m.area_rect(egui::Id::new("shell-dialog"))).unwrap();
assert!(screen.contains_rect(last), "{theme:?} at {size:?}: dialog {last:?} must fit");
assert!((last.width() - first.width()).abs() < 1.0, "{theme:?}: width grew from {first:?} to {last:?}");
for label in ["Exposure:", "Gamma:", "OK", "Cancel"] {
let rect = h.get_by_label(label).rect();
assert!(last.contains_rect(rect) && screen.contains_rect(rect), "{label} must remain visible: {rect:?}");
}
}
}
}
#[test]
fn thirty_two_bit_preview_dialog() {
let (mut app, ctx) = app();