summaryrefslogtreecommitdiff
path: root/src/layout/image.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout/image.rs')
-rw-r--r--src/layout/image.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/layout/image.rs b/src/layout/image.rs
index eb2fc221..59b4c6ef 100644
--- a/src/layout/image.rs
+++ b/src/layout/image.rs
@@ -13,31 +13,23 @@ pub struct ImageNode {
pub height: Option<Linear>,
}
-impl Layout for ImageNode {
- fn layout(
- &self,
- ctx: &mut LayoutContext,
- regions: &Regions,
- ) -> Vec<Constrained<Rc<Frame>>> {
+impl InlineLevel for ImageNode {
+ fn layout(&self, ctx: &mut LayoutContext, space: Length, base: Size) -> Frame {
let img = ctx.images.get(self.id);
let pixel_size = Spec::new(img.width() as f64, img.height() as f64);
let pixel_ratio = pixel_size.x / pixel_size.y;
- let width = self.width.map(|w| w.resolve(regions.base.w));
- let height = self.height.map(|w| w.resolve(regions.base.h));
-
- let mut cts = Constraints::new(regions.expand);
- cts.set_base_if_linear(regions.base, Spec::new(self.width, self.height));
+ let width = self.width.map(|w| w.resolve(base.w));
+ let height = self.height.map(|w| w.resolve(base.h));
let size = match (width, height) {
(Some(width), Some(height)) => Size::new(width, height),
(Some(width), None) => Size::new(width, width / pixel_ratio),
(None, Some(height)) => Size::new(height * pixel_ratio, height),
(None, None) => {
- cts.exact.x = Some(regions.current.w);
- if regions.current.w.is_finite() {
+ if space.is_finite() {
// Fit to width.
- Size::new(regions.current.w, regions.current.w / pixel_ratio)
+ Size::new(space, space / pixel_ratio)
} else {
// Unbounded width, we have to make up something,
// so it is 1pt per pixel.
@@ -48,12 +40,12 @@ impl Layout for ImageNode {
let mut frame = Frame::new(size, size.h);
frame.push(Point::zero(), Element::Image(self.id, size));
- vec![frame.constrain(cts)]
+ frame
}
}
-impl From<ImageNode> for LayoutNode {
- fn from(image: ImageNode) -> Self {
- Self::new(image)
+impl From<ImageNode> for InlineNode {
+ fn from(node: ImageNode) -> Self {
+ Self::new(node)
}
}