diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-03-25 21:32:33 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-03-25 21:32:33 +0100 |
| commit | 76fc4cca62f5b955200b2c62cc85b69eea491ece (patch) | |
| tree | 5b8492268c996cf23b13e26c7a4356fbd156286d /src/library/image.rs | |
| parent | e8057a53856dc09594c9e5861f1cd328531616e0 (diff) | |
Refactor alignments & directions 📐
- Adds lang function
- Refactors execution context
- Adds StackChild and ParChild enums
Diffstat (limited to 'src/library/image.rs')
| -rw-r--r-- | src/library/image.rs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/library/image.rs b/src/library/image.rs index 9f39073b..020f7d50 100644 --- a/src/library/image.rs +++ b/src/library/image.rs @@ -2,9 +2,7 @@ use ::image::GenericImageView; use super::*; use crate::env::{ImageResource, ResourceId}; -use crate::layout::{ - AnyNode, Areas, Element, Fragment, Frame, Image, Layout, LayoutContext, -}; +use crate::layout::{AnyNode, Areas, Element, Frame, Image, Layout, LayoutContext}; /// `image`: An image. /// @@ -25,13 +23,7 @@ pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { let loaded = ctx.env.resources.load(&path.v, ImageResource::parse); if let Some((res, img)) = loaded { let dimensions = img.buf.dimensions(); - ctx.push(ImageNode { - res, - dimensions, - width, - height, - aligns: ctx.state.aligns, - }); + ctx.push_into_par(ImageNode { res, dimensions, width, height }); } else { ctx.diag(error!(path.span, "failed to load image")); } @@ -42,8 +34,6 @@ pub fn image(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { /// An image node. #[derive(Debug, Clone, PartialEq)] struct ImageNode { - /// How to align this image node in its parent. - aligns: LayoutAligns, /// The resource id of the image file. res: ResourceId, /// The pixel dimensions of the image. @@ -55,7 +45,7 @@ struct ImageNode { } impl Layout for ImageNode { - fn layout(&self, _: &mut LayoutContext, areas: &Areas) -> Fragment { + fn layout(&self, _: &mut LayoutContext, areas: &Areas) -> Vec<Frame> { let Areas { current, full, .. } = areas; let pixel_width = self.dimensions.0 as f64; @@ -86,7 +76,7 @@ impl Layout for ImageNode { let mut frame = Frame::new(size); frame.push(Point::ZERO, Element::Image(Image { res: self.res, size })); - Fragment::Frame(frame, self.aligns) + vec![frame] } } |
