From 264a7dedd42e27cd9e604037640cf0594b2ec46b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 19 Mar 2021 17:57:31 +0100 Subject: =?UTF-8?q?Scheduled=20maintenance=20=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New naming scheme - TextNode instead of NodeText - CallExpr instead of ExprCall - ... - Less glob imports - Removes Value::Args variant - Removes prelude - Renames Layouted to Fragment - Moves font into env - Moves shaping into layout - Moves frame into separate module --- src/layout/frame.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/layout/frame.rs (limited to 'src/layout/frame.rs') diff --git a/src/layout/frame.rs b/src/layout/frame.rs new file mode 100644 index 00000000..c85d7539 --- /dev/null +++ b/src/layout/frame.rs @@ -0,0 +1,82 @@ +use super::Shaped; +use crate::color::Color; +use crate::env::ResourceId; +use crate::geom::{Point, Size}; + +/// A finished layout with elements at fixed positions. +#[derive(Debug, Clone, PartialEq)] +pub struct Frame { + /// The size of the frame. + pub size: Size, + /// The elements composing this layout. + pub elements: Vec<(Point, Element)>, +} + +impl Frame { + /// Create a new, empty frame. + pub fn new(size: Size) -> Self { + Self { size, elements: vec![] } + } + + /// Add an element at a position. + pub fn push(&mut self, pos: Point, element: Element) { + self.elements.push((pos, element)); + } + + /// Add all elements of another frame, placing them relative to the given + /// position. + pub fn push_frame(&mut self, pos: Point, subframe: Self) { + for (subpos, element) in subframe.elements { + self.push(pos + subpos, element); + } + } +} + +/// The building block frames are composed of. +#[derive(Debug, Clone, PartialEq)] +pub enum Element { + /// Shaped text. + Text(Shaped), + /// A geometric shape. + Geometry(Geometry), + /// A raster image. + Image(Image), +} + +/// A shape with some kind of fill. +#[derive(Debug, Clone, PartialEq)] +pub struct Geometry { + /// The shape to draw. + pub shape: Shape, + /// How the shape looks on the inside. + // + // TODO: This could be made into a Vec or something such that + // the user can compose multiple fills with alpha values less + // than one to achieve cool effects. + pub fill: Fill, +} + +/// Some shape. +#[derive(Debug, Clone, PartialEq)] +pub enum Shape { + /// A rectangle. + Rect(Size), +} + +/// The kind of graphic fill to be applied to a [`Shape`]. +#[derive(Debug, Copy, Clone, PartialEq)] +pub enum Fill { + /// The fill is a color. + Color(Color), + /// The fill is an image. + Image(Image), +} + +/// An image element. +#[derive(Debug, Copy, Clone, PartialEq)] +pub struct Image { + /// The image resource. + pub res: ResourceId, + /// The size of the image in the document. + pub size: Size, +} -- cgit v1.2.3