mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-28 04:16:46 -06:00
#1378: max lines only while truncation is ENDING, with a REST test for auto height with truncation off
This commit is contained in:
@@ -365,6 +365,17 @@ fn text_styles_and_runs() {
|
||||
assert!(!named(&doc, "NoFills").fills.is_empty(), "text keeps its default fill");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn max_lines_apply_only_while_truncating() {
|
||||
let (doc, _) = one(json!([
|
||||
{"id": "1", "name": "Auto", "type": "TEXT", "relativeTransform": at(0.0, 0.0), "size": {"x": 100, "y": 20}, "characters": "a",
|
||||
"style": {"textAutoResize": "HEIGHT", "textTruncation": "DISABLED", "maxLines": 2}}
|
||||
]));
|
||||
let NodeKind::Text(td) = &named(&doc, "Auto").kind else { panic!() };
|
||||
assert_eq!((td.auto_resize, td.max_lines), (TextAutoResize::Height, 0));
|
||||
assert!(!td.truncates());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auto_layout_constraints_and_grids() {
|
||||
let (doc, _) = one(json!([
|
||||
|
||||
@@ -69,9 +69,11 @@ fn paragraph(s: &Value, td: &mut TextData) {
|
||||
// Missing means a fixed box.
|
||||
_ => TextAutoResize::None,
|
||||
};
|
||||
td.max_lines = num(s, "maxLines").filter(|n| *n >= 1.0).map_or(0, |n| n.min(10_000.0) as u32);
|
||||
// A line limit applies only while truncation is on; a leftover `maxLines` is ignored.
|
||||
let ending = text(s, "textTruncation") == Some("ENDING");
|
||||
td.max_lines = num(s, "maxLines").filter(|n| ending && *n >= 1.0).map_or(0, |n| n.min(10_000.0) as u32);
|
||||
// Auto height with a line limit keeps hugging its lines up to the limit.
|
||||
if text(s, "textTruncation") == Some("ENDING") && !td.truncates() {
|
||||
if ending && !td.truncates() {
|
||||
td.auto_resize = TextAutoResize::Truncate;
|
||||
}
|
||||
td.paragraph_spacing = len(s, "paragraphSpacing").unwrap_or(0.0);
|
||||
|
||||
Reference in New Issue
Block a user