diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-07 14:32:35 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-07 16:19:51 +0200 |
| commit | 1192132dc0a9e991953fd29e93f87c8437a53ea0 (patch) | |
| tree | 67061e75a5a15c7997a3ac2de349b5e9ce234434 /src/library/graphics | |
| parent | eb22eed31b08874fbbbee68d2ae59f0d02f9e95d (diff) | |
Rename length-related types
`Fractional` => `Fraction`
`Relative` => `Ratio`
`Linear` => `Relative`
Diffstat (limited to 'src/library/graphics')
| -rw-r--r-- | src/library/graphics/line.rs | 16 | ||||
| -rw-r--r-- | src/library/graphics/shape.rs | 10 | ||||
| -rw-r--r-- | src/library/graphics/transform.rs | 4 |
3 files changed, 15 insertions, 15 deletions
diff --git a/src/library/graphics/line.rs b/src/library/graphics/line.rs index a650c76c..1ca25bd9 100644 --- a/src/library/graphics/line.rs +++ b/src/library/graphics/line.rs @@ -3,24 +3,24 @@ use crate::library::prelude::*; /// Display a line without affecting the layout. #[derive(Debug, Hash)] pub struct LineNode { - origin: Spec<Linear>, - delta: Spec<Linear>, + origin: Spec<Relative>, + delta: Spec<Relative>, } #[node] impl LineNode { - /// How the stroke the line. + /// How to stroke the line. pub const STROKE: Paint = Color::BLACK.into(); /// The line's thickness. pub const THICKNESS: Length = Length::pt(1.0); fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { - let origin = args.named::<Spec<Linear>>("origin")?.unwrap_or_default(); - let delta = match args.named::<Spec<Linear>>("to")? { + let origin = args.named::<Spec<Relative>>("origin")?.unwrap_or_default(); + let delta = match args.named::<Spec<Relative>>("to")? { Some(to) => to.zip(origin).map(|(to, from)| to - from), None => { let length = - args.named::<Linear>("length")?.unwrap_or(Length::cm(1.0).into()); + args.named::<Relative>("length")?.unwrap_or(Length::cm(1.0).into()); let angle = args.named::<Angle>("angle")?.unwrap_or_default(); let x = angle.cos() * length; @@ -48,9 +48,9 @@ impl Layout for LineNode { }); let resolved_origin = - self.origin.zip(regions.base).map(|(l, b)| Linear::resolve(l, b)); + self.origin.zip(regions.base).map(|(l, b)| Relative::resolve(l, b)); let resolved_delta = - self.delta.zip(regions.base).map(|(l, b)| Linear::resolve(l, b)); + self.delta.zip(regions.base).map(|(l, b)| Relative::resolve(l, b)); let geometry = Geometry::Line(resolved_delta.to_point()); let shape = Shape { geometry, fill: None, stroke }; diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index 177f466e..3f338d1a 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -23,17 +23,17 @@ pub type EllipseNode = ShapeNode<ELLIPSE>; impl<const S: ShapeKind> ShapeNode<S> { /// How to fill the shape. pub const FILL: Option<Paint> = None; - /// How the stroke the shape. + /// How to stroke the shape. pub const STROKE: Smart<Option<Paint>> = Smart::Auto; /// The stroke's thickness. pub const THICKNESS: Length = Length::pt(1.0); /// How much to pad the shape's content. - pub const PADDING: Linear = Linear::zero(); + pub const PADDING: Relative = Relative::zero(); fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let size = match S { - SQUARE => args.named::<Length>("size")?.map(Linear::from), - CIRCLE => args.named::<Length>("radius")?.map(|r| 2.0 * Linear::from(r)), + SQUARE => args.named::<Length>("size")?.map(Relative::from), + CIRCLE => args.named::<Length>("radius")?.map(|r| 2.0 * Relative::from(r)), _ => None, }; @@ -64,7 +64,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { if let Some(child) = &self.0 { let mut padding = styles.get(Self::PADDING); if is_round(S) { - padding.rel += Relative::new(0.5 - SQRT_2 / 4.0); + padding.rel += Ratio::new(0.5 - SQRT_2 / 4.0); } // Pad the child. diff --git a/src/library/graphics/transform.rs b/src/library/graphics/transform.rs index 0dc50166..1ce91f28 100644 --- a/src/library/graphics/transform.rs +++ b/src/library/graphics/transform.rs @@ -37,8 +37,8 @@ impl<const T: TransformKind> TransformNode<T> { } SCALE | _ => { let all = args.find()?; - let sx = args.named("x")?.or(all).unwrap_or(Relative::one()); - let sy = args.named("y")?.or(all).unwrap_or(Relative::one()); + let sx = args.named("x")?.or(all).unwrap_or(Ratio::one()); + let sy = args.named("y")?.or(all).unwrap_or(Ratio::one()); Transform::scale(sx, sy) } }; |
