diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-02 11:06:45 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-02 11:06:45 +0200 |
| commit | efb78831a7a9fe8c807c326a1bfa338b50579938 (patch) | |
| tree | 7bbba4130ac47809c72efeac796b2ca71b72e659 /src/syntax/func/values.rs | |
| parent | 659248d52ff9e6be4dad7c4555bd62899671ad55 (diff) | |
Unify font and page functions 💕
- Removes font weight and width warnings for now, will be added again later
- Adds a bit hacky get_first function for tuples, will be refactored soon anyway
Diffstat (limited to 'src/syntax/func/values.rs')
| -rw-r--r-- | src/syntax/func/values.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/syntax/func/values.rs b/src/syntax/func/values.rs index 64d4d345..d5e9c6e8 100644 --- a/src/syntax/func/values.rs +++ b/src/syntax/func/values.rs @@ -143,22 +143,21 @@ impl Value for FontStyle { /// The additional boolean specifies whether a number was clamped into the range /// 100 - 900 to make it a valid font weight. -impl Value for (FontWeight, bool) { +impl Value for FontWeight { fn parse(expr: Spanned<Expr>) -> Result<Self, Diagnostic> { match expr.v { Expr::Number(weight) => { let weight = weight.round(); if weight >= 100.0 && weight <= 900.0 { - Ok((FontWeight(weight as u16), false)) + Ok(FontWeight(weight as u16)) } else { let clamped = weight.min(900.0).max(100.0); - Ok((FontWeight(clamped as u16), true)) + Ok(FontWeight(clamped as u16)) } } Expr::Ident(id) => { FontWeight::from_name(id.as_str()) .ok_or_else(|| error!("invalid font weight")) - .map(|weight| (weight, false)) } other => Err( error!("expected identifier or number, found {}", other.name()) @@ -169,22 +168,21 @@ impl Value for (FontWeight, bool) { /// The additional boolean specifies whether a number was clamped into the range /// 1 - 9 to make it a valid font width. -impl Value for (FontWidth, bool) { +impl Value for FontWidth { fn parse(expr: Spanned<Expr>) -> Result<Self, Diagnostic> { match expr.v { Expr::Number(width) => { let width = width.round(); if width >= 1.0 && width <= 9.0 { - Ok((FontWidth::new(width as u16).unwrap(), false)) + Ok(FontWidth::new(width as u16).unwrap()) } else { let clamped = width.min(9.0).max(1.0); - Ok((FontWidth::new(clamped as u16).unwrap(), true)) + Ok(FontWidth::new(clamped as u16).unwrap()) } } Expr::Ident(id) => { FontWidth::from_name(id.as_str()) .ok_or_else(|| error!("invalid font width")) - .map(|width| (width, false)) } other => Err( error!("expected identifier or number, found {}", other.name()) |
