mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-02 16:29:34 -06:00
M3: bind line height and letter spacing to variables (#53)
The Typography section's line height and letter spacing fields now take number variables (in pixels) like the other number fields: a variable button on hover opens the picker (scoped to line height or letter spacing), and a bound field shows the variable's chip to change or detach it. While a text range is selected they keep taking plain values. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -66,3 +66,19 @@ fn opacity_padding_text_and_visibility_follow_their_variables() {
|
||||
assert_eq!(doc.node(f).unwrap().opacity, 1.0);
|
||||
assert!(doc.node(t).unwrap().visible);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_height_and_letter_spacing_follow_number_variables_in_pixels() {
|
||||
let mut s = Session::new();
|
||||
let t = id_of(&s.execute("text.create", &json!({"text": "Hello", "x": 0, "y": 0})).unwrap()["id"]).unwrap();
|
||||
s.execute("variable.createCollection", &json!({"name": "Type"})).unwrap();
|
||||
s.execute("variable.create", &json!({"collection": "Type", "name": "leading", "type": "number", "value": 24})).unwrap();
|
||||
s.execute("variable.create", &json!({"collection": "Type", "name": "tracking", "type": "number", "value": 2})).unwrap();
|
||||
s.execute("variable.bind", &json!({"ids": [t], "field": "lineHeight", "variable": "leading"})).unwrap();
|
||||
s.execute("variable.bind", &json!({"ids": [t], "field": "letterSpacing", "variable": "tracking"})).unwrap();
|
||||
let style = |s: &Session| s.doc().unwrap().node(t).unwrap().kind.text().unwrap().style.clone();
|
||||
assert_eq!(style(&s).line_height, figcraft_doc::LineHeight::Pixels(24.0));
|
||||
assert_eq!(style(&s).letter_spacing, figcraft_doc::LetterSpacing::Pixels(2.0));
|
||||
s.execute("variable.set", &json!({"variable": "leading", "value": 30})).unwrap();
|
||||
assert_eq!(style(&s).line_height, figcraft_doc::LineHeight::Pixels(30.0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user