Skip to main content

Paint

Enum Paint 

Source
pub enum Paint<'a> {
    Solid(Color),
    LinearGradient {
        start: [f32; 2],
        end: [f32; 2],
        stops: &'a [ColorStop],
        extend: ExtendMode,
        space: GradientSpace,
    },
    RadialGradient {
        center: [f32; 2],
        radius: f32,
        focal: [f32; 2],
        focal_radius: f32,
        stops: &'a [ColorStop],
        extend: ExtendMode,
        space: GradientSpace,
    },
    ConicGradient {
        center: [f32; 2],
        start_angle_deg: f32,
        sweep_deg: f32,
        stops: &'a [ColorStop],
        extend: ExtendMode,
        space: GradientSpace,
    },
}
Expand description

通用填充画刷原语(零堆分配,渐变色标借用自 ScratchArena 或 'static 切片)。

Variants§

§

Solid(Color)

纯色填充。

§

LinearGradient

任意角度/任意起止点多色标线性渐变(start/end 为归一化局部坐标 [0.0..=1.0])。

Fields

§start: [f32; 2]
§end: [f32; 2]
§stops: &'a [ColorStop]
§extend: ExtendMode
§

RadialGradient

支持双圆焦点偏移的多色标径向渐变(所有坐标与半径均为归一化局部坐标,相对元素宽高的最小边或各自轴)。

Fields

§center: [f32; 2]
§radius: f32
§focal: [f32; 2]
§focal_radius: f32
§stops: &'a [ColorStop]
§extend: ExtendMode
§

ConicGradient

多色标锥形/扫描渐变(start_angle_deg 以 12 点钟为 0° 顺时针增加,sweep_deg 默认 360°)。

Fields

§center: [f32; 2]
§start_angle_deg: f32
§sweep_deg: f32
§stops: &'a [ColorStop]
§extend: ExtendMode

Implementations§

Source§

impl<'a> Paint<'a>

Source

pub fn linear_angle(angle_deg: f32, stops: &'a [ColorStop]) -> Self

按 CSS 角度规范构造多色标线性渐变(0° 向上、90° 向右、180° 向下,135° 左上至右下)。

Source

pub const fn radial(stops: &'a [ColorStop]) -> Self

构造居中径向渐变(默认中心 [0.5, 0.5]、半径 0.5)。

Source

pub const fn radial_focal( center: [f32; 2], radius: f32, focal: [f32; 2], focal_radius: f32, stops: &'a [ColorStop], ) -> Self

构造带焦点的双圆径向渐变。

Source

pub const fn conic(start_angle_deg: f32, stops: &'a [ColorStop]) -> Self

构造居中锥形/扫描渐变(start_angle_deg 以 12 点钟为 0° 顺时针)。

Source

pub const fn with_extend(self, mode: ExtendMode) -> Self

设置渐变的延展模式(Pad / Repeat / Reflect)。

Source

pub const fn with_space(self, color_space: GradientSpace) -> Self

设置渐变的色彩插值空间(Srgb / LinearRgb / Oklab)。

Source

pub fn is_fully_transparent(&self) -> bool

判断该画刷是否全范围完全透明(可安全跳过填充绘制)。

Source

pub fn is_fully_opaque(&self) -> bool

判断该画刷是否在所有采样点都 100% 不透明。

Source

pub fn mix_hash(&self, h: &mut u32)

将当前画刷全部字段混入 FNV-1a 哈希(供 DrawOpSnapshot 与 GPU Ramp 缓存使用)。

Source

pub fn eval_gradient_t(&self, u: f32, v: f32) -> Option<f32>

评估归一化局部坐标 (u, v) ∈ [0, 1]² 处的渐变位置参数 t(None 表示退化或双圆锥外无效区)。

Trait Implementations§

Source§

impl<'a> Clone for Paint<'a>

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<'a> Copy for Paint<'a>

Source§

impl<'a> Debug for Paint<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Paint<'a>

Source§

impl<'a> PartialEq for Paint<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Paint<'a>

§

impl<'a> Freeze for Paint<'a>

§

impl<'a> Move for Paint<'a>

§

impl<'a> RefUnwindSafe for Paint<'a>

§

impl<'a> Send for Paint<'a>

§

impl<'a> Sync for Paint<'a>

§

impl<'a> Unpin for Paint<'a>

§

impl<'a> UnsafeUnpin for Paint<'a>

§

impl<'a> UnwindSafe for Paint<'a>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> FluentBuilder for T

Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self

当 condition 为 true 时执行闭包修饰自身,否则原样返回。
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,