mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
DocumentWindow: the body takes the window's room and never scrolls
This commit is contained in:
@@ -84,6 +84,8 @@ impl Outcome for DocumentWindowOutput {
|
||||
/// - **Title and focus.** The title is the label given to `new`; it follows the document while the app changes it.
|
||||
/// [`raise`](DocumentWindow::raise) brings the window forward in the pass it is set. With
|
||||
/// [`in_list`](DocumentWindow::in_list) the window makes itself the list's active window when it gains OS focus.
|
||||
/// - **Body.** The body is laid out in the window's room and never scrolls, in the OS window and on the fallback
|
||||
/// layer alike; an app that wants scrolling puts a scroll region in the body.
|
||||
/// - **Fallback.** Where OS windows are unavailable the document shows on a movable, resizable layer with a title row.
|
||||
#[derive(crate::contract::Component, crate::contract::Props)]
|
||||
#[component(container)]
|
||||
@@ -138,7 +140,7 @@ impl<'a> DocumentWindow<'a> {
|
||||
|
||||
/// A window titled `title`, resizable, with the installed decision's frame.
|
||||
pub fn new(title: impl Into<Label>) -> Self {
|
||||
let fallback = Overlay::floating().resizable(true).fit(OverlayFit::Resizable);
|
||||
let fallback = Overlay::floating().resizable(true).fit(OverlayFit::Resizable).body_scroll(false);
|
||||
let props = ContainerProps::new()
|
||||
.surface(SurfaceKind::Background)
|
||||
.pad(Pad::None)
|
||||
|
||||
@@ -8,6 +8,7 @@ use craft_behavior::kurbo::{Point, Size};
|
||||
use craft_behavior::placement::capped;
|
||||
use craft_behavior::{Monitor, MonitorKey};
|
||||
use craft_host::target::{Caps, ShellInfo};
|
||||
use craft_ui::contract::MAX_EXTENT;
|
||||
use craft_ui::contract::{Props as _, ShowContainer as _, SizeLimits};
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::shell::{DocumentWindow, Wrapped};
|
||||
@@ -154,3 +155,31 @@ fn a_wrapped_document_window_takes_the_document_between_its_minimum_and_the_scre
|
||||
assert_eq!(fallback.wrapped, None, "the fallback layer has no OS window to size");
|
||||
assert_eq!(fallback.size, None, "nothing goes out without OS windows");
|
||||
}
|
||||
|
||||
/// A body that fills its room gets the window's room, not a scroll region's unbounded extent, in the OS window and
|
||||
/// on the fallback layer.
|
||||
#[trial]
|
||||
fn a_document_window_body_fills_the_windows_room_and_does_not_scroll() {
|
||||
let inner = Rect::from_min_size(pos2(100.0, 100.0), vec2(600.0, 400.0));
|
||||
let layered_shell = {
|
||||
let shell = ShellInfo::default();
|
||||
shell.clone().caps(shell.caps.difference(Caps::VIEWPORTS))
|
||||
};
|
||||
let system = FakeSystem::new();
|
||||
system.set_monitors(vec![Monitor::new(MonitorKey::new("DP-1", [1920, 1080]), [0, 0], [1920, 1080], 1.0)]);
|
||||
for (mount, windows) in [
|
||||
("OS window", Windows::with(InstallSpec::new(ShellInfo::default(), Arc::new(system)))),
|
||||
("fallback layer", Windows::with(InstallSpec::new(layered_shell, Arc::new(FakeSystem::new())))),
|
||||
] {
|
||||
let mut height = f32::NAN;
|
||||
for _ in 0..4 {
|
||||
windows.child_info(normal(inner));
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
DocumentWindow::new("Landscape.psd").id_salt("landscape").show(ui, |ui, _| {
|
||||
height = ui.max_rect().height();
|
||||
});
|
||||
});
|
||||
}
|
||||
assert!(height < MAX_EXTENT / 2.0, "{mount}: the body's height is the window's room, got {height}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user