Add axis-aware scroll constraints and per-mount limits
Verify Tessera GUI / verify (push) Failing after 7m38s

This commit is contained in:
2026-10-22 19:35:38 +08:00
parent 2b20976658
commit 1885693f7c
13 changed files with 277 additions and 14 deletions
+135
View File
@@ -3889,6 +3889,141 @@ page.render(block)
);
}
#[test]
fn scroll_axes_wrap_shared_text_and_clamp_only_the_enabled_offsets() {
let (mut session, initial) = ReplSession::load(
include_str!("../examples/scroll-axis.endor"),
"app.main",
260,
1,
)
.unwrap();
initial.validate().unwrap();
for expression in [
"vertical.mounts().at(0).scrollPosition().maxX",
"horizontal.mounts().at(0).scrollPosition().maxY",
] {
assert_eq!(session.execute(expression, "app.main").unwrap().value, "0");
}
session
.execute(
"vertical.mounts().at(0).scrollTo(100, 60)\nhorizontal.mounts().at(0).scrollTo(60, 100)",
"app.main",
)
.unwrap();
for (expression, expected) in [
("vertical.mounts().at(0).scrollPosition().x", "0"),
("vertical.mounts().at(0).scrollPosition().y", "60"),
("horizontal.mounts().at(0).scrollPosition().x", "60"),
("horizontal.mounts().at(0).scrollPosition().y", "0"),
] {
assert_eq!(
session.execute(expression, "app.main").unwrap().value,
expected
);
}
let vertical_width: f32 = session
.execute("paragraph.mounts().at(0).bounds().width", "app.main")
.unwrap()
.value
.parse()
.unwrap();
let horizontal_width: f32 = session
.execute("paragraph.mounts().at(1).bounds().width", "app.main")
.unwrap()
.value
.parse()
.unwrap();
assert!(vertical_width <= 244.0);
assert!(horizontal_width > vertical_width);
session
.execute("horizontal.axis = \"vertical\"", "app.main")
.unwrap();
assert_eq!(
session
.execute("horizontal.mounts().at(0).scrollPosition().x", "app.main")
.unwrap()
.value,
"0"
);
}
#[test]
fn scroll_axis_defaults_to_both_and_rejects_unknown_policy() {
let mut session = ReplSession::new(262).unwrap();
session
.execute(
"scroller = ScrollBlock(20, 10, TextBlock(\"default\"))",
"app.main",
)
.unwrap();
assert_eq!(
session.execute("scroller.axis", "app.main").unwrap().value,
"\"both\""
);
let error = ReplSession::load(
r#"
scroller = ScrollBlock(20, 10, TextBlock("bad"))
scroller.axis = "diagonal"
page = Page()
page.render(scroller)
"#,
"app.main",
263,
1,
)
.err()
.expect("invalid axis");
assert!(
error
.to_string()
.contains("ScrollBlock.axis expects both, vertical or horizontal"),
"{error:#}"
);
}
#[test]
fn scroll_axis_uses_source_allocated_viewport_instead_of_constructor_width() {
let source = r#"
class Allocator: Column {
function arrange(self: Allocator, mount: Mount, geometry: Bounds): Arrangement {
result = Column.arrange(self, mount, geometry)
result.children.at(0).width = 120
return result
}
}
text = TextBlock("This text must wrap inside the allocated viewport, not the original constructor width. This text must wrap inside the allocated viewport.")
scroller = ScrollBlock(300, 80, text)
scroller.padding = 10
scroller.axis = "vertical"
page = Page()
page.render(Allocator(0, 0, scroller))
"#;
let (mut session, initial) = ReplSession::load(source, "app.main", 261, 1).unwrap();
initial.validate().unwrap();
assert_eq!(
session
.execute("scroller.mounts().at(0).bounds().width", "app.main")
.unwrap()
.value,
"120"
);
let width: f32 = session
.execute("text.mounts().at(0).bounds().width", "app.main")
.unwrap()
.value
.parse()
.unwrap();
assert!(width <= 100.0);
assert_eq!(
session
.execute("scroller.mounts().at(0).scrollPosition().maxX", "app.main")
.unwrap()
.value,
"0"
);
}
#[test]
fn nested_scroll_into_view_and_source_paint_share_clipped_geometry() {
let mut session = ReplSession::new(241).unwrap();