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.
Radial
Interpolates inner at center to outer at radius, clamped beyond.
Implementations§
Source§impl Fill
impl Fill
Sourcepub fn linear(from: Vec2, to: Vec2, start: Color, end: Color) -> Fill
pub fn linear(from: Vec2, to: Vec2, start: Color, end: Color) -> Fill
Linear gradient between two points.
Sourcepub fn vertical(rect: Rect, top: Color, bottom: Color) -> Fill
pub fn vertical(rect: Rect, top: Color, bottom: Color) -> Fill
Top-to-bottom gradient across rect.
Sourcepub fn horizontal(rect: Rect, left: Color, right: Color) -> Fill
pub fn horizontal(rect: Rect, left: Color, right: Color) -> Fill
Left-to-right gradient across rect.
Trait Implementations§
impl Copy for Fill
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more