use crate::icons::svg::IconSource;
use crate::image::{Image, ImageFit};
use crate::shader::{ShaderHandle, UniformBlock};
use crate::text::atlas::RunStyle;
use crate::text::metrics::TextLayout;
use crate::tree::{Color, Corners, FontFamily, FontWeight, Rect, TextWrap};
use crate::vector::VectorRenderMode;
#[derive(Clone, Debug)]
pub enum DrawOp {
Quad {
id: String,
rect: Rect,
scissor: Option<Rect>,
shader: ShaderHandle,
uniforms: UniformBlock,
},
GlyphRun {
id: String,
rect: Rect,
scissor: Option<Rect>,
shader: ShaderHandle,
color: Color,
text: String,
size: f32,
line_height: f32,
family: FontFamily,
mono_family: FontFamily,
weight: FontWeight,
mono: bool,
wrap: TextWrap,
anchor: TextAnchor,
layout: TextLayout,
underline: bool,
strikethrough: bool,
link: Option<String>,
},
AttributedText {
id: String,
rect: Rect,
scissor: Option<Rect>,
shader: ShaderHandle,
runs: Vec<(String, RunStyle)>,
size: f32,
line_height: f32,
wrap: TextWrap,
anchor: TextAnchor,
layout: TextLayout,
},
Icon {
id: String,
rect: Rect,
scissor: Option<Rect>,
source: IconSource,
color: Color,
size: f32,
stroke_width: f32,
},
Image {
id: String,
rect: Rect,
scissor: Option<Rect>,
image: Image,
tint: Option<Color>,
radius: Corners,
fit: ImageFit,
},
AppTexture {
id: String,
rect: Rect,
scissor: Option<Rect>,
texture: crate::surface::AppTexture,
alpha: crate::surface::SurfaceAlpha,
fit: ImageFit,
transform: crate::affine::Affine2,
},
Vector {
id: String,
rect: Rect,
scissor: Option<Rect>,
asset: std::sync::Arc<crate::vector::VectorAsset>,
render_mode: VectorRenderMode,
},
BackdropSnapshot,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum TextAnchor {
Start,
Middle,
End,
}
impl DrawOp {
pub fn id(&self) -> &str {
match self {
DrawOp::Quad { id, .. }
| DrawOp::GlyphRun { id, .. }
| DrawOp::AttributedText { id, .. }
| DrawOp::Icon { id, .. }
| DrawOp::Image { id, .. }
| DrawOp::AppTexture { id, .. }
| DrawOp::Vector { id, .. } => id,
DrawOp::BackdropSnapshot => "<backdrop-snapshot>",
}
}
pub fn shader(&self) -> Option<&ShaderHandle> {
match self {
DrawOp::Quad { shader, .. }
| DrawOp::GlyphRun { shader, .. }
| DrawOp::AttributedText { shader, .. } => Some(shader),
DrawOp::Icon { .. }
| DrawOp::Image { .. }
| DrawOp::AppTexture { .. }
| DrawOp::Vector { .. } => None,
DrawOp::BackdropSnapshot => None,
}
}
pub fn scissor(&self) -> Option<Rect> {
match self {
DrawOp::Quad { scissor, .. }
| DrawOp::GlyphRun { scissor, .. }
| DrawOp::AttributedText { scissor, .. }
| DrawOp::Icon { scissor, .. }
| DrawOp::Image { scissor, .. }
| DrawOp::AppTexture { scissor, .. }
| DrawOp::Vector { scissor, .. } => *scissor,
DrawOp::BackdropSnapshot => None,
}
}
}