pub struct LinearGradient {
pub begin: AlignmentGeometry,
pub end: AlignmentGeometry,
pub colors: Vec<Color>,
pub stops: Option<Vec<f64>>,
pub tile_mode: TileMode,
pub transform: Option<Rc<dyn GradientTransform>>,
}Expand description
A 2D linear gradient.
This class is used by BoxDecoration to represent linear gradients. This
abstracts out the arguments to the dart:ui Gradient.linear constructor.
A gradient has two anchor points, begin and end. The
begin point corresponds to 0.0, and the end point corresponds
to 1.0. These points are expressed in fractions, so that the same gradient can be reused with
varying sized boxes without changing the parameters. (This contrasts with dart:ui
Gradient.linear, whose arguments are expressed in logical pixels.)
The colors are described by a list of Color objects. There must be at
least two colors. The stops list, if specified, must have the same length
as colors. It specifies fractions of the vector from start to end, between
0.0 and 1.0, for each color. If it is null, a uniform distribution is
assumed.
The region of the canvas before begin and after end is
colored according to tile_mode.
Typically this class is used with BoxDecoration, which does the painting.
To use a LinearGradient to paint on a canvas directly, see
create_shader.
Fields§
§begin: AlignmentGeometryThe offset at which stop 0.0 of the gradient is placed.
If this is an Alignment, then it is expressed as a vector from
coordinate (0.0, 0.0), in a coordinate space that maps the center of the
paint box at (0.0, 0.0) and the bottom right at (1.0, 1.0).
It can also be an AlignmentDirectional, where the start is the
left in left-to-right contexts and the right in right-to-left contexts. If
a text-direction-dependent value is provided here, then the
create_shader method will need to be given a
TextDirection.
end: AlignmentGeometryThe offset at which stop 1.0 of the gradient is placed.
See begin for how the coordinates are mapped.
colors: Vec<Color>The colors the gradient should obtain at each of the stops.
stops: Option<Vec<f64>>A list of values from 0.0 to 1.0 that denote fractions along the gradient.
tile_mode: TileMode§transform: Option<Rc<dyn GradientTransform>>The transform, if any, to apply to the gradient.
Implementations§
Source§impl LinearGradient
impl LinearGradient
Sourcepub fn new(colors: Vec<Color>) -> LinearGradient
pub fn new(colors: Vec<Color>) -> LinearGradient
Sourcepub fn begin(self, begin: impl Into<AlignmentGeometry>) -> LinearGradient
pub fn begin(self, begin: impl Into<AlignmentGeometry>) -> LinearGradient
Dart LinearGradient(begin:).
Sourcepub fn end(self, end: impl Into<AlignmentGeometry>) -> LinearGradient
pub fn end(self, end: impl Into<AlignmentGeometry>) -> LinearGradient
Dart LinearGradient(end:).
Sourcepub fn stops(self, stops: Vec<f64>) -> LinearGradient
pub fn stops(self, stops: Vec<f64>) -> LinearGradient
Dart LinearGradient(stops:).
Sourcepub fn tile_mode(self, tile_mode: TileMode) -> LinearGradient
pub fn tile_mode(self, tile_mode: TileMode) -> LinearGradient
Dart LinearGradient(tileMode:).
Sourcepub fn transform(
self,
transform: impl Into<Rc<dyn GradientTransform>>,
) -> LinearGradient
pub fn transform( self, transform: impl Into<Rc<dyn GradientTransform>>, ) -> LinearGradient
Dart LinearGradient(transform:).
Sourcepub fn scale(&self, factor: f64) -> LinearGradient
pub fn scale(&self, factor: f64) -> LinearGradient
Returns a new LinearGradient with its colors scaled by the given factor.
Since the alpha component of the Color is what is scaled, a factor of 0.0 or less results in a gradient that is fully transparent.
Sourcepub fn from_color(&self, color: Color) -> LinearGradient
pub fn from_color(&self, color: Color) -> LinearGradient
Dart’s LinearGradient.fromColor: the geometry kept, every color replaced by color.
Sourcepub fn lerp(
a: Option<&LinearGradient>,
b: Option<&LinearGradient>,
t: f64,
) -> Option<LinearGradient>
pub fn lerp( a: Option<&LinearGradient>, b: Option<&LinearGradient>, t: f64, ) -> Option<LinearGradient>
Linearly interpolate between two LinearGradients.
If either gradient is None, this function linearly interpolates from
a gradient that matches the other gradient in begin,
end, stops and tile_mode and with the
same colors but transparent (using scale).
If neither gradient is None, they must have the same number of colors.
Sourcepub fn with_opacity(&self, opacity: f64) -> LinearGradient
pub fn with_opacity(&self, opacity: f64) -> LinearGradient
Returns a new LinearGradient with each color set to the given opacity.
Trait Implementations§
Source§impl Clone for LinearGradient
impl Clone for LinearGradient
Source§fn clone(&self) -> LinearGradient
fn clone(&self) -> LinearGradient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LinearGradient
impl Debug for LinearGradient
Source§impl Gradient for LinearGradient
impl Gradient for LinearGradient
Source§fn colors(&self) -> &[Color]
fn colors(&self) -> &[Color]
Source§fn stops(&self) -> Option<&[f64]>
fn stops(&self) -> Option<&[f64]>
Source§fn transform(&self) -> Option<&Rc<dyn GradientTransform>>
fn transform(&self) -> Option<&Rc<dyn GradientTransform>>
Source§fn create_shader(
&self,
rect: Rect,
text_direction: Option<TextDirection>,
) -> Shader
fn create_shader( &self, rect: Rect, text_direction: Option<TextDirection>, ) -> Shader
Source§fn scale(&self, factor: f64) -> GradientRef
fn scale(&self, factor: f64) -> GradientRef
Source§fn with_opacity(&self, opacity: f64) -> GradientRef
fn with_opacity(&self, opacity: f64) -> GradientRef
Gradient with each color set to the given opacity.Source§fn from_color(&self, color: Color) -> GradientRef
fn from_color(&self, color: Color) -> GradientRef
Source§fn eq_gradient(&self, other: &(dyn Gradient + 'static)) -> bool
fn eq_gradient(&self, other: &(dyn Gradient + 'static)) -> bool
== is identity; subclasses that override
== implement this.