diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-11-25 16:56:29 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-11-25 16:56:29 +0100 |
| commit | 11e44516fae84f907ea992311fcfdc3636101f14 (patch) | |
| tree | ff9b6a04c3accd5c0f75f1ceb60e578c389a2606 /src/layout/graphics.rs | |
| parent | 761931405c68efe0a35d96524df797dda7155723 (diff) | |
Merge some modules 🥞
Diffstat (limited to 'src/layout/graphics.rs')
| -rw-r--r-- | src/layout/graphics.rs | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/src/layout/graphics.rs b/src/layout/graphics.rs deleted file mode 100644 index 1fa05605..00000000 --- a/src/layout/graphics.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::fmt::{self, Debug, Formatter}; - -use super::*; - -/// An image node. -#[derive(Clone, PartialEq)] -pub struct Image { - /// The image. - pub buf: RgbaImage, - /// The fixed width, if any. - pub width: Option<Linear>, - /// The fixed height, if any. - pub height: Option<Linear>, - /// How to align this image node in its parent. - pub align: BoxAlign, -} - -impl Layout for Image { - fn layout(&self, _: &mut LayoutContext, areas: &Areas) -> Layouted { - let Area { rem, full } = areas.current; - let (pixel_width, pixel_height) = self.buf.dimensions(); - let pixel_ratio = (pixel_width as f64) / (pixel_height as f64); - - let width = self.width.map(|w| w.resolve(full.width)); - let height = self.height.map(|w| w.resolve(full.height)); - - 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) => { - let ratio = rem.width / rem.height; - if ratio < pixel_ratio { - Size::new(rem.width, rem.width / pixel_ratio) - } else { - // TODO: Fix issue with line spacing. - Size::new(rem.height * pixel_ratio, rem.height) - } - } - }; - - let mut boxed = BoxLayout::new(size); - boxed.push( - Point::ZERO, - LayoutElement::Image(ImageElement { buf: self.buf.clone(), size }), - ); - - Layouted::Layout(boxed, self.align) - } -} - -impl Debug for Image { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.pad("Image") - } -} - -impl From<Image> for LayoutNode { - fn from(image: Image) -> Self { - Self::dynamic(image) - } -} |
