Skip to main content

PaintCommand

Enum PaintCommand 

Source
pub enum PaintCommand {
Show 17 variants Rect { rect: Rect, color: Color, radius: f32, }, TexturedRect { rect: Rect, color: Color, uv: [f32; 4], texture_id: u32, mode: TextureMode, }, Triangles { vertices: Vec<Vertex>, indices: Vec<u32>, }, Text { text: Rc<str>, range: Option<(usize, usize)>, font_size: f32, color: Color, position: Point, max_width: Option<f32>, }, BoxShadow { rect: Rect, color: Color, radius: f32, blur_radius: f32, }, BackdropBlur { rect: Rect, radius: f32, blur_radius: f32, tint: Color, }, InsetShadow { rect: Rect, color: Color, radius: f32, blur_radius: f32, }, LinearGradient { rect: Rect, start: Point, end: Point, from: Color, to: Color, corner_radius: f32, }, RadialGradient { rect: Rect, center: Point, radial_radius: f32, from: Color, to: Color, corner_radius: f32, }, MaskRect { rect: Rect, texture_id: u32, uv: [f32; 4], alpha: f32, }, PushBlendMode(BlendMode), PopBlendMode, PushClip(Rect), PushClipRRect { rect: Rect, radius: f32, }, PopClip, PushClipPath { vertices: Vec<Vertex>, indices: Vec<u32>, }, PopClipPath,
}
Expand description

单条绘制指令。

Variants§

§

Rect

填充矩形(可带圆角)

Fields

§rect: Rect
§color: Color
§radius: f32
§

TexturedRect

纹理矩形(文字字形 / 图片)

uv 是归一化纹理坐标 (u0, v0, u1, v1),左上角原点。 texture_id 在 0..n 范围内,具体含义由 renderer 决定 (本阶段固定为 0 = glyph atlas)。

Fields

§rect: Rect
§color: Color
§uv: [f32; 4]
§texture_id: u32
§mode: TextureMode

纹理采样模式(glyph/SVG tint = Mask;全彩 SVG/PNG = Color)

§

Triangles

三角网格(路径 CPU 三角化结果,PathBuilder → earcut → 本命令)

vertices 按 indices 索引渲染 triangles,与 wgpu vertex pipeline 零拷贝兼容。 renderer 按 vertex[i] 的 x/y 作为屏幕坐标(逻辑像素),color 直接来自 vertex。

Fields

§vertices: Vec<Vertex>
§indices: Vec<u32>
§

Text

Stage T2:核心层 Widget 要画文字时用的高层命令

与 TexturedRect(低层 glyph quad)不同 — Text 让 renderer 自己调 parley shaping + swash 栅格化。核心层 Widget 不需要知道 glyph 细节。

renderer 在 collect_instances_segmented 里会 paint_text_line(...) 把它展开成 N 个 TexturedRect instances(每个 glyph 一个)。

Fields

§text: Rc<str>

文本(Rc<str> 共享:同一整串被多条命令引用时零拷贝, runtime shaping 缓存也直接以它作 key,命中路径不再克隆全文)

§range: Option<(usize, usize)>

可选绘制子区间(字节,相对 text;None = 绘制全文)。 编辑器逐语法 span 绘制时复用整行 Rc<str>,只带区间, 避免“每个 span 一次子串 String 分配“。

§font_size: f32
§color: Color
§position: Point

绘制起点(逻辑像素,layer 本地坐标)

§max_width: Option<f32>

可选 soft wrap 宽度(None = 单行)

§

BoxShadow

T0-2:BoxShadow — 带 GPU SDF blur 的圆角矩形阴影

与 Rect { radius } 的区别:额外携带 blur_radius(高斯模糊半径)。 renderer 复用 Rect pipeline,shader 里 smoothstep AA 区间从 1px 扩展到 1 + blur_radius, 实现单 pass SDF blur(无需额外 render pass 或临时纹理)。

注意:rect 应该已经包含 blur padding(即调用方负责外扩 blur_radius)。 PaintList::box_shadow() helper 已自动处理 rect + offset + spread + blur padding。

Fields

§rect: Rect
§color: Color
§radius: f32
§blur_radius: f32

高斯模糊半径(逻辑像素);0 = 无 blur(等价普通 Rect)

§

BackdropBlur

P2-1.4b:背景模糊 — 对 rect 内已绘制内容做模糊(tint 可选)

GPU 在命令处结束当前 pass → resolve snapshot → 重开 pass 采样 13-tap blur; 软件光栅化对当前目标像素做同参数卷积。矩形为圆角遮罩,外部不受影响。 tint.a > 0 时把模糊结果向 tint.rgb 混合(磨砂玻璃色调)。

Fields

§rect: Rect
§radius: f32
§blur_radius: f32
§tint: Color
§

InsetShadow

P2-1.4:内阴影 — 在矩形内侧沿边缘衰减的阴影(inset shadow)

SDF 单 pass:边缘处 coverage=1,向中心按 exp(-depth² / 2blur²) 衰减; blur_radius=0 时为 1px 内侧描边。绘制在已有内容之上(SourceOver)。

Fields

§rect: Rect
§color: Color
§radius: f32
§blur_radius: f32
§

LinearGradient

两色线性渐变矩形(可带圆角)。

Fields

§rect: Rect
§start: Point

渐变起点(layer 本地坐标)

§end: Point

渐变终点

§from: Color
§corner_radius: f32
§

RadialGradient

两色径向渐变矩形(可带圆角)。

Fields

§rect: Rect
§center: Point
§radial_radius: f32
§from: Color
§corner_radius: f32
§

MaskRect

P2-1.3: 纹理 mask — 用纹理 alpha 裁掉 layer 中已有内容(destination-in)

只影响 rect 范围内已经绘制的内容:new_alpha = old_alpha × tex.a × alpha。 纹理需通过 PaintList::push_texture 或 renderer 的 register_image 注册; uv 是归一化坐标(左上原点)。

Fields

§rect: Rect
§texture_id: u32
§uv: [f32; 4]
§alpha: f32
§

PushBlendMode(BlendMode)

P2-1.3 压入混合模式,作用于后续矩形族命令,直到 PopBlendMode

§

PopBlendMode

恢复上一个混合模式

§

PushClip(Rect)

压入裁剪矩形(layer 本地坐标)

之后的绘制命令都被裁在该矩形内,直到配对的 PopClip。 嵌套时与外层 clip 求交(即当前 clip = 所有未弹出 clip 的交集)。 GPU 侧由 render pass 的 scissor_rect 精确实现。

§

PushClipRRect

P2-1.3 压入圆角矩形裁剪(layer 本地坐标),配对 PopClip

与 PushClip 共用同一剪裁栈;GPU 用 stencil SDF 三角形精确裁角, 软件光栅化用 tiny-skia 圆角路径 mask。radius <= 0 等价直角。

Fields

§rect: Rect
§radius: f32
§

PopClip

弹出最近一次 PushClip / PushClipRRect(与 push 严格配对)

§

PushClipPath

路径裁剪 — 压入一个 PathBuilder.fill() 产出的三角形网格作为裁剪区域

  • vertices + indices 与 Triangles 完全同结构(PathBuilder.fill() 的 earcut 输出)
  • GPU 用 stencil mask 精确裁剪(支持嵌套,见 PushClipRRect 同机制)
  • 嵌套时与外层 clip 求交

Fields

§vertices: Vec<Vertex>
§indices: Vec<u32>
§

PopClipPath

弹出最近一次 PushClipPath(也接受 PushClipRRect;与 push 严格配对)

Trait Implementations§

Source§

impl Clone for PaintCommand

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PaintCommand

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.