use crate::shader::{ShaderHandle, UniformBlock};
use crate::text::atlas::RunStyle;
use crate::text::metrics::TextLayout;
use crate::tree::{Color, FontWeight, IconName, Rect, TextWrap};
#[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,
weight: FontWeight,
mono: bool,
wrap: TextWrap,
anchor: TextAnchor,
layout: TextLayout,
},
AttributedText {
id: String,
rect: Rect,
scissor: Option<Rect>,
shader: ShaderHandle,
runs: Vec<(String, RunStyle)>,
size: f32,
wrap: TextWrap,
anchor: TextAnchor,
layout: TextLayout,
},
Icon {
id: String,
rect: Rect,
scissor: Option<Rect>,
name: IconName,
color: Color,
size: f32,
stroke_width: f32,
},
BackdropSnapshot,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
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, .. } => 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 { .. } => None,
DrawOp::BackdropSnapshot => None,
}
}
pub fn scissor(&self) -> Option<Rect> {
match self {
DrawOp::Quad { scissor, .. }
| DrawOp::GlyphRun { scissor, .. }
| DrawOp::AttributedText { scissor, .. }
| DrawOp::Icon { scissor, .. } => *scissor,
DrawOp::BackdropSnapshot => None,
}
}
}