Style primitives

This commit is contained in:
2026-03-21 03:08:19 -04:00
parent c70f42704c
commit a70a08297e
7 changed files with 1306 additions and 178 deletions

View File

@@ -8,7 +8,7 @@ use tracing::debug;
use crate::ImageResource;
use crate::text::TextSelectionStyle;
use crate::trace_targets;
use crate::tree::ElementId;
use crate::tree::{BoxShadowKind, ElementId};
pub type SceneVersion = u64;
@@ -100,6 +100,32 @@ impl Quad {
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct RoundedRect {
pub rect: Rect,
pub fill: Option<Color>,
pub border_color: Option<Color>,
pub border_width: f32,
pub radius: f32,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ShadowRect {
pub rect: Rect,
pub source_rect: Rect,
pub color: Color,
pub blur: f32,
pub radius: f32,
pub source_radius: f32,
pub kind: BoxShadowKind,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ClipRegion {
pub rect: Rect,
pub radius: f32,
}
#[derive(Clone, Debug, PartialEq)]
pub struct GlyphInstance {
pub position: Point,
@@ -465,9 +491,11 @@ fn classify_word_char(ch: char) -> WordClass {
#[derive(Clone, Debug, PartialEq)]
pub enum DisplayItem {
Quad(Quad),
RoundedRect(RoundedRect),
ShadowRect(ShadowRect),
Image(PreparedImage),
Text(PreparedText),
PushClip(Rect),
PushClip(ClipRegion),
PopClip,
PushTransform(Translation),
PopTransform,
@@ -512,6 +540,14 @@ impl SceneSnapshot {
self.push_item(DisplayItem::Quad(Quad::new(rect, color)))
}
pub fn push_rounded_rect(&mut self, rounded_rect: RoundedRect) -> &mut Self {
self.push_item(DisplayItem::RoundedRect(rounded_rect))
}
pub fn push_shadow_rect(&mut self, shadow_rect: ShadowRect) -> &mut Self {
self.push_item(DisplayItem::ShadowRect(shadow_rect))
}
pub fn push_text(&mut self, text: PreparedText) -> &mut Self {
self.push_item(DisplayItem::Text(text))
}
@@ -520,8 +556,8 @@ impl SceneSnapshot {
self.push_item(DisplayItem::Image(image))
}
pub fn push_clip(&mut self, rect: Rect) -> &mut Self {
self.push_item(DisplayItem::PushClip(rect))
pub fn push_clip(&mut self, rect: Rect, radius: f32) -> &mut Self {
self.push_item(DisplayItem::PushClip(ClipRegion { rect, radius }))
}
pub fn pop_clip(&mut self) -> &mut Self {