diff options
author | 2020-05-19 17:15:44 +0200 | |
---|---|---|
committer | 2020-05-19 17:15:44 +0200 | |
commit | 05af8d00d4c0f7b8e0ece85224fd90a92da86da8 (patch) | |
tree | 98e4774a2c0d4a2a0a01aff1d772f89c4cb0aa5e /graphics/src/primitive.rs | |
parent | d4743183d40c6044ce6fa39e2a52919a32912cda (diff) | |
download | iced-05af8d00d4c0f7b8e0ece85224fd90a92da86da8.tar.gz iced-05af8d00d4c0f7b8e0ece85224fd90a92da86da8.tar.bz2 iced-05af8d00d4c0f7b8e0ece85224fd90a92da86da8.zip |
Draft new `iced_graphics` crate :tada:
Diffstat (limited to 'graphics/src/primitive.rs')
-rw-r--r-- | graphics/src/primitive.rs | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs new file mode 100644 index 00000000..e73227ef --- /dev/null +++ b/graphics/src/primitive.rs @@ -0,0 +1,107 @@ +use iced_native::{ + image, svg, Background, Color, Font, HorizontalAlignment, Rectangle, Size, + Vector, VerticalAlignment, +}; + +use crate::triangle; +use std::sync::Arc; + +/// A rendering primitive. +#[derive(Debug, Clone)] +pub enum Primitive { + /// An empty primitive + None, + /// A group of primitives + Group { + /// The primitives of the group + primitives: Vec<Primitive>, + }, + /// A text primitive + Text { + /// The contents of the text + content: String, + /// The bounds of the text + bounds: Rectangle, + /// The color of the text + color: Color, + /// The size of the text + size: f32, + /// The font of the text + font: Font, + /// The horizontal alignment of the text + horizontal_alignment: HorizontalAlignment, + /// The vertical alignment of the text + vertical_alignment: VerticalAlignment, + }, + /// A quad primitive + Quad { + /// The bounds of the quad + bounds: Rectangle, + /// The background of the quad + background: Background, + /// The border radius of the quad + border_radius: u16, + /// The border width of the quad + border_width: u16, + /// The border color of the quad + border_color: Color, + }, + /// An image primitive + Image { + /// The handle of the image + handle: image::Handle, + /// The bounds of the image + bounds: Rectangle, + }, + /// An SVG primitive + Svg { + /// The path of the SVG file + handle: svg::Handle, + + /// The bounds of the viewport + bounds: Rectangle, + }, + /// A clip primitive + Clip { + /// The bounds of the clip + bounds: Rectangle, + /// The offset transformation of the clip + offset: Vector<u32>, + /// The content of the clip + content: Box<Primitive>, + }, + /// A primitive that applies a translation + Translate { + /// The translation vector + translation: Vector, + + /// The primitive to translate + content: Box<Primitive>, + }, + /// A low-level primitive to render a mesh of triangles. + /// + /// It can be used to render many kinds of geometry freely. + Mesh2D { + /// The size of the drawable region of the mesh. + /// + /// Any geometry that falls out of this region will be clipped. + size: Size, + + /// The vertex and index buffers of the mesh + buffers: triangle::Mesh2D, + }, + /// A cached primitive. + /// + /// This can be useful if you are implementing a widget where primitive + /// generation is expensive. + Cached { + /// The cached primitive + cache: Arc<Primitive>, + }, +} + +impl Default for Primitive { + fn default() -> Primitive { + Primitive::None + } +} |