Merge pull request #3269 from davidmann4/fix/photocraft-16595-own-window-shrink

A full-window container's own window keeps its size (photocraft#16595)
This commit is contained in:
David Mann
2026-11-24 17:29:13 +01:00
committed by GitHub
5 changed files with 81 additions and 15 deletions
+21 -1
View File
@@ -19,7 +19,7 @@ use craft_imaging::ui::wide_angle::PreviewDone;
use craft_imaging::ui::{ChannelColor, HistogramSet, ScopeChannel};
use craft_ui::InstallSpec;
use craft_ui::canvas::{PixelRect, RasterSource};
use craft_ui::dialog::{DialogHost, DialogResult, FullWindowWorkspace as _, HostedWorkspace};
use craft_ui::dialog::{DialogHost, DialogResult, FullWindowWorkspace as _, HostedWorkspace, OWN_WINDOW_MIN_SIZE};
use craft_ui::primitives::Revision;
use craft_ui::runtime::access::Role;
use craft_ui::runtime::pending::Job;
@@ -251,6 +251,26 @@ fn raw_develop_window_keeps_its_size_when_the_saved_screen_is_gone() {
assert!((0.0..=880.0).contains(&pos.x) && (0.0..=320.0).contains(&pos.y), "restored position is in reach: {pos:?}");
}
/// photocraft#16595: while the window shrank each frame, the placement store saved its size, 1 pt wide at 100 %
/// scaling. Restored, the window opens no smaller than a full-window dialog's own window may be, and the OS keeps it
/// there.
#[trial]
fn raw_develop_window_saved_while_shrinking_opens_at_its_minimum() {
let store = Arc::new(Mutex::new(Store::in_memory()));
store.lock().unwrap().set("craft_imaging.raw_develop.window", &Placement::new([1.0, 500.0], 1.0));
let system = Arc::new(FakeSystem::new());
system.set_monitors(vec![Monitor::new(MonitorKey::new("Attached", [1920, 1080]), [0, 0], [1920, 1080], 1.0)]);
let windows = Windows::with(InstallSpec::new(ShellInfo::default(), system).placement(store));
let mut host = DialogHost::new();
host.open(HostedWorkspace::new(RawDevelopWorkspace::new(open(RawTarget::OpenRaw)), Source::new()));
let output = windows.frame(vec![], vec![], |ui| {
host.run(ui);
});
let (_, builder) = output.builders.iter().find(|(id, _)| *id != ViewportId::ROOT).expect("Raw Develop opens a child window");
assert_eq!(builder.inner_size, Some(Vec2::new(OWN_WINDOW_MIN_SIZE.x, 500.0)), "the saved width is raised to the minimum");
assert_eq!(builder.min_inner_size, Some(OWN_WINDOW_MIN_SIZE), "the OS keeps the window at least that big");
}
#[trial]
fn raw_develop_switches_raws_and_finishes_with_each_footer_button() {
let host = Rc::new(RefCell::new(DialogHost::new()));
+10 -4
View File
@@ -16,7 +16,7 @@ use crate::runtime::windows::WindowSpec;
use crate::sections::FooterButton;
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
use craft_behavior::{Metrics, Sense};
use egui::Ui;
use egui::{Ui, Vec2, vec2};
pub use hosted::{FullWindowWorkspace, HostedWorkspace, WorkspaceCx, WorkspacePass};
@@ -26,6 +26,11 @@ pub(crate) mod stories;
#[cfg(feature = "suite")]
pub(crate) mod trials;
/// The least a full-window dialog's own window may be, in points: the OS window's minimum, and the floor a restored
/// placement is fitted to. A placement saved while photocraft#16595 shrank the window could be 1 pt wide; without
/// a floor it opened that small and nothing grew it again.
pub const OWN_WINDOW_MIN_SIZE: Vec2 = vec2(640.0, 480.0);
/// The style of a full-window dialog: the surface comes from the container.
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
#[non_exhaustive]
@@ -121,13 +126,14 @@ impl<'a> FullWindowDialog<'a> {
.label(title)
}
/// Shows the dialog in its own OS window described by `spec`, resizable, opening at the saved placement; where
/// viewports are unavailable it fills the main window. The dialog's focus policy moves into the fallback overlay.
/// Shows the dialog in its own OS window described by `spec`, resizable down to [`OWN_WINDOW_MIN_SIZE`], opening at
/// the saved placement; where viewports are unavailable it fills the main window. The dialog's focus policy moves
/// into the fallback overlay.
#[must_use]
pub fn own_window(mut self, spec: WindowSpec) -> Self {
// A viewport mount takes its scope from the fallback overlay and holds `props.focus` at none.
let focus = std::mem::replace(self.focus_mut(), FocusPolicy::NONE);
self.props.mount = Mount::viewport_with(Overlay::full_window(focus), spec);
self.props.mount = Mount::viewport_with(Overlay::full_window(focus).min_size(OWN_WINDOW_MIN_SIZE), spec);
self
}
+3 -1
View File
@@ -31,7 +31,9 @@ pub mod canvas_controls;
/// Dialog shells and prompts, with the full-window dialog family that shows a canvas.
pub mod dialog {
pub use crate::canvas::full_window::{FullWindowDialog, FullWindowDialogStyle, FullWindowWorkspace, HostedWorkspace, WorkspaceCx, WorkspacePass};
pub use crate::canvas::full_window::{
FullWindowDialog, FullWindowDialogStyle, FullWindowWorkspace, HostedWorkspace, OWN_WINDOW_MIN_SIZE, WorkspaceCx, WorkspacePass,
};
pub use crate::canvas::full_window_parts::{
FullWindowCanvas, FullWindowCanvasOutput, FullWindowSide, FullWindowSideOutput, FullWindowSideStyle, FullWindowStatus,
FullWindowStatusOutput, FullWindowTitle, FullWindowTitleOutput, FullWindowView, FullWindowZoomBar, FullWindowZoomBarOutput, RasterOverlay,
+8 -9
View File
@@ -365,25 +365,24 @@ impl Host for ViewportHost {
let spec = self.spec.clone().unwrap_or_else(by_rank);
let placed = self.overlay.placed;
let full_window = self.overlay.is_full_window();
// A full-window container fills its window, so the window's own layout memory holds the size the user gave
// it; before it has one the window opens at the opener's content size, large enough for a workspace.
let measured = || {
let remembered = layout_memory::read(&ctx, id);
if full_window { remembered.or_else(|| Some(ctx.content_rect().size())) } else { remembered }
};
// A full-window container fills its window and has no content size: its window opens at the opener's content
// size, large enough for a workspace. What its body took is no size for the window: side panels, header and
// footer are no part of it, and a window sent it shrank by them each pass (photocraft#16595).
let measured = || if full_window { Some(ctx.content_rect().size()) } else { layout_memory::read(&ctx, id) };
let open = ViewportOpen {
id,
title: title.as_str(),
// A placed rect is the caller's size for the window, within the window's limits, which the OS would clamp it
// to; then a resizable fallback's default size, as the layer takes it; the measured size is for a window
// sized by content: what its body took in the window, recorded once the window reported its place
// (`steps::record_body_size`).
// (`steps::record_body_size`), or a full-window container's opening size.
size: placed
.map(|rect| self.overlay.size_limits.clamp(rect.size()))
.or(self.overlay.size.filter(|_| self.overlay.fit == overlay::OverlayFit::Resizable))
.or_else(measured),
// A resizable window takes its default or content size to open; from then on its size is the user's.
follows_size: placed.is_some() || self.overlay.fit != overlay::OverlayFit::Resizable,
// A resizable window takes its default or content size to open; from then on its size is the user's, as a
// full-window container's is.
follows_size: placed.is_some() || (!full_window && self.overlay.fit != overlay::OverlayFit::Resizable),
save: self.save.as_deref(),
spec: &spec,
limits: (Some(self.overlay.size_limits.min), self.overlay.size_limits.max),
@@ -867,6 +867,45 @@ fn a_content_sized_window_takes_its_content_size_once_it_reported_its_place() {
);
}
/// photocraft#16595: a full-window container in a window of its own keeps the size the window has. Its body takes
/// less than the window (side panels, header and footer are no part of it), and the window was sent that size each
/// frame, so it shrank until it was a pixel wide.
#[trial]
fn a_full_window_viewport_keeps_its_window_size() {
const GIVEN: Vec2 = Vec2::new(1000.0, 700.0);
let windows = Windows::new();
let frame = || {
windows.frame(vec![], vec![], |ui| {
Palette::full_window("Workspace").show(ui, |ui, _| {
ui.allocate_exact_size(Vec2::new(300.0, 200.0), egui::Sense::hover());
});
})
};
let (dialog, _) = builder_titled(&frame(), "Workspace");
let report = |size: Vec2| {
let rect = Rect::from_min_size(Pos2::new(100.0, 100.0), size);
windows.child_info(ViewportInfo {
inner_rect: Some(rect),
outer_rect: Some(rect),
native_pixels_per_point: Some(1.0),
..ViewportInfo::default()
});
};
let sizes_sent = || -> Vec<Vec2> {
(0..6)
.flat_map(|_| frame().commands)
.filter_map(|(id, command)| match command {
ViewportCommand::InnerSize(size) if id == dialog => Some(size),
_ => None,
})
.collect()
};
report(GIVEN);
assert_eq!(sizes_sent(), Vec::<Vec2>::new(), "the workspace's window keeps the size it has");
report(Vec2::new(1200.0, 820.0));
assert_eq!(sizes_sent(), Vec::<Vec2>::new(), "a size the user gives the window is kept too");
}
/// Placing a minimized window below its smallest inner size restores it and lowers that size to the placed one, so the
/// window takes the place it is given.
#[trial]