2019-11-21 13:47:20 +01:00
|
|
|
use iced_native::{
|
2020-02-12 08:49:42 +01:00
|
|
|
image, svg, Background, Color, Font, HorizontalAlignment, Point, Rectangle,
|
2019-12-15 06:19:07 +01:00
|
|
|
Vector, VerticalAlignment,
|
2019-11-21 13:47:20 +01:00
|
|
|
};
|
2019-10-05 19:22:51 +02:00
|
|
|
|
2020-01-02 19:25:00 +01:00
|
|
|
use crate::triangle;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2019-11-22 22:14:24 +01:00
|
|
|
/// A rendering primitive.
|
2019-10-05 19:22:51 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum Primitive {
|
2019-11-22 22:14:24 +01:00
|
|
|
/// An empty primitive
|
2019-10-05 19:22:51 +02:00
|
|
|
None,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// A group of primitives
|
2019-10-05 19:22:51 +02:00
|
|
|
Group {
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The primitives of the group
|
2019-10-05 19:22:51 +02:00
|
|
|
primitives: Vec<Primitive>,
|
|
|
|
|
},
|
2019-11-22 22:14:24 +01:00
|
|
|
/// A text primitive
|
2019-10-05 19:22:51 +02:00
|
|
|
Text {
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The contents of the text
|
2019-10-05 19:22:51 +02:00
|
|
|
content: String,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The bounds of the text
|
2019-10-05 19:22:51 +02:00
|
|
|
bounds: Rectangle,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The color of the text
|
2019-10-08 03:13:41 +02:00
|
|
|
color: Color,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The size of the text
|
2019-10-05 19:22:51 +02:00
|
|
|
size: f32,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The font of the text
|
2019-11-13 07:22:21 +01:00
|
|
|
font: Font,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The horizontal alignment of the text
|
2019-11-21 13:47:20 +01:00
|
|
|
horizontal_alignment: HorizontalAlignment,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The vertical alignment of the text
|
2019-11-21 13:47:20 +01:00
|
|
|
vertical_alignment: VerticalAlignment,
|
2019-10-05 19:22:51 +02:00
|
|
|
},
|
2019-11-22 22:14:24 +01:00
|
|
|
/// A quad primitive
|
2019-10-07 02:17:40 +02:00
|
|
|
Quad {
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The bounds of the quad
|
2019-10-06 19:22:25 +02:00
|
|
|
bounds: Rectangle,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The background of the quad
|
2019-10-06 19:22:25 +02:00
|
|
|
background: Background,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The border radius of the quad
|
2019-10-08 03:13:41 +02:00
|
|
|
border_radius: u16,
|
2019-12-31 21:35:42 +01:00
|
|
|
/// The border width of the quad
|
|
|
|
|
border_width: u16,
|
|
|
|
|
/// The border color of the quad
|
|
|
|
|
border_color: Color,
|
2019-10-06 19:22:25 +02:00
|
|
|
},
|
2019-11-22 22:14:24 +01:00
|
|
|
/// An image primitive
|
2019-10-23 01:21:23 +02:00
|
|
|
Image {
|
2019-11-29 21:44:39 +01:00
|
|
|
/// The handle of the image
|
|
|
|
|
handle: image::Handle,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The bounds of the image
|
2019-10-23 01:21:23 +02:00
|
|
|
bounds: Rectangle,
|
|
|
|
|
},
|
2019-12-15 06:19:07 +01:00
|
|
|
/// An SVG primitive
|
|
|
|
|
Svg {
|
|
|
|
|
/// The path of the SVG file
|
|
|
|
|
handle: svg::Handle,
|
|
|
|
|
|
|
|
|
|
/// The bounds of the viewport
|
|
|
|
|
bounds: Rectangle,
|
|
|
|
|
},
|
2019-11-22 22:14:24 +01:00
|
|
|
/// A clip primitive
|
2019-10-29 19:50:34 +01:00
|
|
|
Clip {
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The bounds of the clip
|
2019-10-25 03:47:34 +02:00
|
|
|
bounds: Rectangle,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The offset transformation of the clip
|
2019-11-05 03:16:46 +01:00
|
|
|
offset: Vector<u32>,
|
2019-11-22 22:14:24 +01:00
|
|
|
/// The content of the clip
|
2019-10-25 03:47:34 +02:00
|
|
|
content: Box<Primitive>,
|
|
|
|
|
},
|
2020-01-02 19:25:00 +01:00
|
|
|
/// A low-level primitive to render a mesh of triangles.
|
|
|
|
|
///
|
|
|
|
|
/// It can be used to render many kinds of geometry freely.
|
2020-02-12 08:49:42 +01:00
|
|
|
Mesh2D {
|
|
|
|
|
/// The top-left coordinate of the mesh
|
|
|
|
|
origin: Point,
|
|
|
|
|
|
|
|
|
|
/// The vertex and index buffers of the mesh
|
2020-03-07 23:45:54 +01:00
|
|
|
buffers: triangle::Mesh2D,
|
|
|
|
|
},
|
|
|
|
|
/// A cached primitive.
|
|
|
|
|
///
|
|
|
|
|
/// This can be useful if you are implementing a widget where primitive
|
|
|
|
|
/// generation is expensive.
|
|
|
|
|
Cached {
|
|
|
|
|
/// The origin of the coordinate system of the cached primitives
|
|
|
|
|
origin: Point,
|
|
|
|
|
|
|
|
|
|
/// The cached primitive
|
|
|
|
|
cache: Arc<Primitive>,
|
2020-02-12 08:49:42 +01:00
|
|
|
},
|
2019-10-06 19:22:25 +02:00
|
|
|
}
|
2019-12-30 19:17:00 +01:00
|
|
|
|
|
|
|
|
impl Default for Primitive {
|
|
|
|
|
fn default() -> Primitive {
|
|
|
|
|
Primitive::None
|
|
|
|
|
}
|
|
|
|
|
}
|