Enum Fill

Source
pub enum Fill {
    Solid(Color),
    Linear {
        from: Vec2,
        to: Vec2,
        start: Color,
        end: Color,
    },
    Radial {
        center: Vec2,
        radius: f32,
        inner: Color,
        outer: Color,
    },
}
Expand description

Paint for filled shapes. Gradients are evaluated per vertex and interpolated by the GPU; linear gradients are exact on these convex fans. A radial gradient on a circle it is centered on (reaching at least its edge) is exact along every spoke; on any other shape the fill is drawn on a subdivided mesh (four bands, long edges split) so the gradient follows its own circles instead of stretching to the outline.

use ferravex_render::{Color, Rect, vec2, shapes::Fill};
let fill = Fill::linear(vec2(0., 0.), vec2(10., 0.), Color::new(0., 0., 0., 1.),
    Color::new(1., 1., 1., 1.));
assert_eq!(fill.at(vec2(5., 3.)).r, 0.5);
let solid: Fill = Color::new(1., 0., 0., 1.).into();
assert_eq!(solid.at(vec2(99., 99.)).r, 1.);
let bar = Fill::vertical(Rect::new(0., 10., 4., 20.), Color::new(0., 0., 0., 1.),
    Color::new(1., 1., 1., 1.));
assert_eq!(bar.at(vec2(2., 30.)).g, 1.);

Variants§

§

Solid(Color)

One color everywhere.

§

Linear

Interpolates start at from to end at to, clamped beyond them.

Fields

§from: Vec2
§to: Vec2
§start: Color
§end: Color
§

Radial

Interpolates inner at center to outer at radius, clamped beyond.

Fields

§center: Vec2
§radius: f32
§inner: Color
§outer: Color

Implementations§

Source§

impl Fill

Source

pub fn linear(from: Vec2, to: Vec2, start: Color, end: Color) -> Fill

Linear gradient between two points.

Source

pub fn vertical(rect: Rect, top: Color, bottom: Color) -> Fill

Top-to-bottom gradient across rect.

Source

pub fn horizontal(rect: Rect, left: Color, right: Color) -> Fill

Left-to-right gradient across rect.

Source

pub fn radial(center: Vec2, radius: f32, inner: Color, outer: Color) -> Fill

Radial gradient from center outward to radius.

Source

pub fn at(&self, p: Vec2) -> Color

Color at a point.

Trait Implementations§

Source§

impl Clone for Fill

Source§

fn clone(&self) -> Fill

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Fill

Source§

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

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

impl From<Color> for Fill

Source§

fn from(color: Color) -> Fill

Converts to this type from the input type.
Source§

impl PartialEq for Fill

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Fill

Source§

impl StructuralPartialEq for Fill

Auto Trait Implementations§

§

impl Freeze for Fill

§

impl RefUnwindSafe for Fill

§

impl Send for Fill

§

impl Sync for Fill

§

impl Unpin for Fill

§

impl UnwindSafe for Fill

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 = Infallible

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.