pub struct SweepGradient {
pub center: AlignmentGeometry,
pub start_angle: f64,
pub end_angle: f64,
pub colors: Vec<Color>,
pub stops: Option<Vec<f64>>,
pub tile_mode: TileMode,
pub transform: Option<Rc<dyn GradientTransform>>,
}Expand description
A 2D sweep gradient.
This class is used by BoxDecoration to represent sweep gradients. This
abstracts out the arguments to the dart:ui Gradient.sweep constructor.
A gradient has a center, a start_angle, and an
end_angle. The start_angle corresponds to 0.0,
and the end_angle corresponds to 1.0. These angles are expressed in
radians.
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 start_angle and after
end_angle is colored according to tile_mode.
Fields§
§center: AlignmentGeometryThe center of the gradient, as an offset into the (-1.0, -1.0) x (1.0, 1.0) square describing the gradient which will be mapped onto the paint box.
For example, an alignment of (0.0, 0.0) will place the sweep gradient in the center of the box.
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.
start_angle: f64The angle in radians at which stop 0.0 of the gradient is placed.
The angle is measured in radians clockwise from the positive x-axis.
Values outside the range [0, 2π] are normalized to the equivalent angle
within this range using modulo arithmetic.
The gradient will be painted in the sector between start_angle
and end_angle. The behavior outside this sector is determined by
tile_mode.
Defaults to 0.0.
end_angle: f64The angle in radians at which stop 1.0 of the gradient is placed.
The angle is measured in radians clockwise from the positive x-axis.
Values outside the range [0, 2π] are normalized to the equivalent angle
within this range using modulo arithmetic.
Defaults to PI * 2 (2π = a full circle).
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: TileModeHow this gradient should tile the plane in the region before
start_angle and after end_angle.
TileMode::Clamp: The edge colors are extended to fill the remaining area.TileMode::Repeat: The gradient is repeated in the angular direction.TileMode::Mirror: The gradient is mirrored in the angular direction.TileMode::Decal: Only the gradient is drawn, leaving the remaining area transparent.
transform: Option<Rc<dyn GradientTransform>>The transform, if any, to apply to the gradient.
Implementations§
Source§impl SweepGradient
impl SweepGradient
Sourcepub fn new(colors: Vec<Color>) -> SweepGradient
pub fn new(colors: Vec<Color>) -> SweepGradient
Sourcepub fn center(self, center: impl Into<AlignmentGeometry>) -> SweepGradient
pub fn center(self, center: impl Into<AlignmentGeometry>) -> SweepGradient
Dart SweepGradient(center:).
Sourcepub fn start_angle(self, start_angle: f64) -> SweepGradient
pub fn start_angle(self, start_angle: f64) -> SweepGradient
Dart SweepGradient(startAngle:).
Sourcepub fn end_angle(self, end_angle: f64) -> SweepGradient
pub fn end_angle(self, end_angle: f64) -> SweepGradient
Dart SweepGradient(endAngle:).
Sourcepub fn stops(self, stops: Vec<f64>) -> SweepGradient
pub fn stops(self, stops: Vec<f64>) -> SweepGradient
Dart SweepGradient(stops:).
Sourcepub fn tile_mode(self, tile_mode: TileMode) -> SweepGradient
pub fn tile_mode(self, tile_mode: TileMode) -> SweepGradient
Dart SweepGradient(tileMode:).
Sourcepub fn transform(
self,
transform: impl Into<Rc<dyn GradientTransform>>,
) -> SweepGradient
pub fn transform( self, transform: impl Into<Rc<dyn GradientTransform>>, ) -> SweepGradient
Dart SweepGradient(transform:).
Sourcepub fn scale(&self, factor: f64) -> SweepGradient
pub fn scale(&self, factor: f64) -> SweepGradient
Returns a new SweepGradient 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) -> SweepGradient
pub fn from_color(&self, color: Color) -> SweepGradient
Dart’s SweepGradient.fromColor: the geometry kept, every color replaced by color.
Sourcepub fn lerp(
a: Option<&SweepGradient>,
b: Option<&SweepGradient>,
t: f64,
) -> Option<SweepGradient>
pub fn lerp( a: Option<&SweepGradient>, b: Option<&SweepGradient>, t: f64, ) -> Option<SweepGradient>
Linearly interpolate between two SweepGradients.
If either gradient is None, then the non-null gradient is returned with
its color scaled in the same way as the scale function.
If neither gradient is None, they must have the same number of colors.
Sourcepub fn with_opacity(&self, opacity: f64) -> SweepGradient
pub fn with_opacity(&self, opacity: f64) -> SweepGradient
Returns a new SweepGradient with each color set to the given opacity.
Trait Implementations§
Source§impl Clone for SweepGradient
impl Clone for SweepGradient
Source§fn clone(&self) -> SweepGradient
fn clone(&self) -> SweepGradient
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 SweepGradient
impl Debug for SweepGradient
Source§impl Gradient for SweepGradient
impl Gradient for SweepGradient
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.