Wrap native text within occurrence constraints and preserve paint bounds
Verify Tessera GUI / verify (push) Failing after 7m33s
Verify Tessera GUI / verify (push) Failing after 7m33s
This commit is contained in:
@@ -993,6 +993,145 @@ mod tests {
|
||||
const EXAMPLE: &str = include_str!("../examples/hello.endor");
|
||||
const PAGE: &str = include_str!("../examples/page.endor");
|
||||
|
||||
#[test]
|
||||
fn source_text_paint_rejects_incomplete_wrap_bounds() {
|
||||
let source = r##"
|
||||
class Invalid: TextBlock {
|
||||
function paint(self: Invalid,mount: Mount,geometry: Bounds): DisplayList {
|
||||
command=PaintCommand()
|
||||
command.kind="text"
|
||||
command.x=0
|
||||
command.y=0
|
||||
command.text="invalid"
|
||||
command.size=1
|
||||
command.color="#000000"
|
||||
command.wrapWidth=40
|
||||
return DisplayList(ObjectList(command))
|
||||
}
|
||||
}
|
||||
page=Page()
|
||||
page.render(Invalid("invalid"))
|
||||
"##;
|
||||
let error = compile(source, "app.main", 1).unwrap_err();
|
||||
assert!(error.to_string().contains("wrapHeight"), "{error:#}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrapped_text_tracks_each_occurrence_width_resize_and_sibling_geometry() {
|
||||
let text = "中文段落随着宽度变化而换行,后面的对象跟随段落高度移动。".repeat(8);
|
||||
for custom in [false, true] {
|
||||
let constructor = if custom { "Wrapped" } else { "TextBlock" };
|
||||
let source = format!(
|
||||
r#"
|
||||
class Wrapped: TextBlock {{
|
||||
function measure(self: Wrapped,mount: Mount,constraints: Constraints): MeasureResult {{return TextBlock.measure(self,mount,constraints)}}
|
||||
function paint(self: Wrapped,mount: Mount,geometry: Bounds): DisplayList {{return TextBlock.paint(self,mount,geometry)}}
|
||||
}}
|
||||
paragraph={constructor}("{text}")
|
||||
tail=TextBlock("tail")
|
||||
page=Page()
|
||||
page.render(Column(0,8,Column(0,8,paragraph,tail),Column(50,8,paragraph)))
|
||||
"#
|
||||
);
|
||||
let (mut session, initial) = ReplSession::load_with_viewport(
|
||||
&source,
|
||||
"app.main",
|
||||
1,
|
||||
230,
|
||||
Some(crate::layout::Size {
|
||||
width: 240.0,
|
||||
height: 2000.0,
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
let ids: Vec<_> = initial.frame.mounts.iter().map(|m| m.id).collect();
|
||||
let commands: Vec<_> = initial
|
||||
.frame
|
||||
.commands
|
||||
.iter()
|
||||
.filter_map(|command| match command {
|
||||
RenderCommand::Text {
|
||||
value,
|
||||
wrap_bounds: Some(bounds),
|
||||
..
|
||||
} if value == &text => Some(*bounds),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(commands.len(), 2);
|
||||
assert_eq!(commands[0][0], 240.0);
|
||||
assert_eq!(commands[1][0], 140.0);
|
||||
assert!(commands[1][1] > commands[0][1]);
|
||||
let tail = initial
|
||||
.frame
|
||||
.commands
|
||||
.iter()
|
||||
.find_map(|command| match command {
|
||||
RenderCommand::Text { value, y, .. } if value == "tail" => Some(*y),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
assert!(tail >= commands[0][1] + 8.0);
|
||||
let resized = session
|
||||
.resize(Some(crate::layout::Size {
|
||||
width: 400.0,
|
||||
height: 2000.0,
|
||||
}))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
ids,
|
||||
resized
|
||||
.frame
|
||||
.mounts
|
||||
.iter()
|
||||
.map(|m| m.id)
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
let heights: Vec<_> = resized
|
||||
.frame
|
||||
.commands
|
||||
.iter()
|
||||
.filter_map(|command| match command {
|
||||
RenderCommand::Text {
|
||||
value,
|
||||
wrap_bounds: Some(bounds),
|
||||
..
|
||||
} if value == &text => Some(bounds[1]),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert!(heights[0] < commands[0][1]);
|
||||
let direct = session
|
||||
.execute(
|
||||
"paragraph.measure(paragraph.mounts().at(0),Constraints(0,0,80,2000)).height",
|
||||
"app.main",
|
||||
)
|
||||
.unwrap()
|
||||
.value
|
||||
.parse::<f32>()
|
||||
.unwrap();
|
||||
assert!(direct > heights[0]);
|
||||
session
|
||||
.execute("paragraph.setText(\"short\")", "app.main")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("paragraph.mounts().count", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"2"
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("paragraph.mounts().at(0).bounds().height", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"20"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_signatures_validate_registration_and_deliver_the_event_argument() {
|
||||
let (mut session, _) = ReplSession::load(
|
||||
|
||||
Reference in New Issue
Block a user