Skip to main content

SdfVertex

Struct SdfVertex 

Source
#[repr(C)]
pub struct SdfVertex { pub position: [f32; 2], pub local_uv: [f32; 2], pub color: [f32; 4], pub corner_radii: [f32; 4], pub shape_params: [f32; 4], pub gradient_geo: [f32; 4], pub gradient_color0: [f32; 4], pub gradient_color1: [f32; 4], pub gradient_color2: [f32; 4], pub gradient_color3: [f32; 4], pub gradient_offsets: [f32; 4], }
Expand description

Vertex for the SDF shape pipeline (rounded rects, circles).

Fields§

§position: [f32; 2]§local_uv: [f32; 2]

Local UV coordinates (0..1) within the shape bounds.

§color: [f32; 4]§corner_radii: [f32; 4]§shape_params: [f32; 4]

Shape bounds in pixels: [width, height, stroke_width, paint_type]. paint_type: 0=solid, 1=linear, 2=radial, 3=conic

§gradient_geo: [f32; 4]

Gradient geometry: [start_x, start_y, end_x, end_y] (or center/radius for radial)

§gradient_color0: [f32; 4]

Gradient stop 0: [r, g, b, a]

§gradient_color1: [f32; 4]

Gradient stop 1: [r, g, b, a]

§gradient_color2: [f32; 4]

Gradient stop 2: [r, g, b, a]

§gradient_color3: [f32; 4]

Gradient stop 3: [r, g, b, a]

§gradient_offsets: [f32; 4]

Gradient stop offsets: [offset0, offset1, offset2, offset3]

Implementations§

Source§

impl SdfVertex

Source

pub fn from_shape_quad(shape: &ShapeQuad, scale_factor: f32) -> [SdfVertex; 4]

Convert a shape quad to 4 vertices with a logical stroke width — the border scales with the view transform (the default).

The rasterized quad is expanded outward by stroke_width / 2 + 1 on every side. The SDF shader paints strokes centered on the rect edge, so the outer half of the stroke falls outside the shape’s bounds — if the quad isn’t padded, those fragments are never rasterized and the stroke is visibly truncated by 1 dp on every side (most noticeable on focus rings). local_uv is extrapolated past [0, 1] for the padding fragments; the SDF still clips correctly because sd_rounded_rect returns positive distances outside the shape.

Source

pub fn from_shape_quad_cosmetic( shape: &ShapeQuad, scale_factor: f32, zoom: f32, ) -> [SdfVertex; 4]

Convert a shape quad to 4 vertices with a cosmetic stroke: the border width is held constant in device pixels (width × scale_factor) regardless of zoom, while the shape body still scales with the transform. zoom is the uniform scale of the active view transform (hypot(m[0], m[1])).

The shader measures the SDF in shape_params.xy = [w·sf, h·sf] units, and one such unit maps to zoom device px on screen, so baking the stroke param as width·sf / zoom lands the rendered border at exactly width·sf device px at every zoom. Assumes a uniform (non-anisotropic) transform — the scene zoom is uniform and rotation preserves the column norm.

Trait Implementations§

Source§

impl Clone for SdfVertex

Source§

fn clone(&self) -> SdfVertex

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 Copy for SdfVertex

Source§

impl Debug for SdfVertex

Source§

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

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

impl Pod for SdfVertex

Source§

impl Zeroable for SdfVertex

Source§

fn zeroed() -> Self

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> AnyBitPattern for T
where T: Pod,

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> NoUninit for T
where T: Pod,

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, <T as TryFrom<U>>::Error>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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