Struct tiny_skia::LinearGradient
source · pub struct LinearGradient { /* private fields */ }
Expand description
A linear gradient shader.
Implementations§
source§impl LinearGradient
impl LinearGradient
sourcepub fn new(
start: Point,
end: Point,
stops: Vec<GradientStop>,
mode: SpreadMode,
transform: Transform
) -> Option<Shader<'static>>
pub fn new( start: Point, end: Point, stops: Vec<GradientStop>, mode: SpreadMode, transform: Transform ) -> Option<Shader<'static>>
Creates a new linear gradient shader.
Returns Shader::SolidColor
when:
stops.len()
== 1start
andend
are very close
Returns None
when:
stops
is emptystart
==end
transform
is not invertible
Examples found in repository?
examples/linear_gradient.rs (lines 5-14)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let mut paint = Paint::default();
paint.shader = LinearGradient::new(
Point::from_xy(100.0, 100.0),
Point::from_xy(900.0, 900.0),
vec![
GradientStop::new(0.0, Color::from_rgba8(50, 127, 150, 200)),
GradientStop::new(1.0, Color::from_rgba8(220, 140, 75, 180)),
],
SpreadMode::Pad,
Transform::identity(),
)
.unwrap();
let mut pb = PathBuilder::new();
pb.move_to(60.0, 60.0);
pb.line_to(160.0, 940.0);
pb.cubic_to(380.0, 840.0, 660.0, 800.0, 940.0, 800.0);
pb.cubic_to(740.0, 460.0, 440.0, 160.0, 60.0, 60.0);
pb.close();
let path = pb.finish().unwrap();
let mut pixmap = Pixmap::new(1000, 1000).unwrap();
pixmap.fill_path(
&path,
&paint,
FillRule::Winding,
Transform::identity(),
None,
);
pixmap.save_png("image.png").unwrap();
}
Trait Implementations§
source§impl Clone for LinearGradient
impl Clone for LinearGradient
source§fn clone(&self) -> LinearGradient
fn clone(&self) -> LinearGradient
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for LinearGradient
impl Debug for LinearGradient
source§impl PartialEq<LinearGradient> for LinearGradient
impl PartialEq<LinearGradient> for LinearGradient
source§fn eq(&self, other: &LinearGradient) -> bool
fn eq(&self, other: &LinearGradient) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl StructuralPartialEq for LinearGradient
Auto Trait Implementations§
impl RefUnwindSafe for LinearGradient
impl Send for LinearGradient
impl Sync for LinearGradient
impl Unpin for LinearGradient
impl UnwindSafe for LinearGradient
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