pub struct RadialGradient {
pub center: AlignmentGeometry,
pub radius: f64,
pub colors: Vec<Color>,
pub stops: Option<Vec<f64>>,
pub tile_mode: TileMode,
pub focal: Option<AlignmentGeometry>,
pub focal_radius: f64,
pub transform: Option<Rc<dyn GradientTransform>>,
}Expand description
A 2D radial gradient.
This class is used by BoxDecoration to represent radial gradients. This
abstracts out the arguments to the dart:ui Gradient.radial constructor.
A normal radial gradient has a center and a radius. The
center point corresponds to 0.0, and the ring at radius
from the center corresponds to 1.0. These lengths 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.radial, whose arguments are expressed in logical
pixels.)
It is also possible to create a two-point (or focal pointed) radial gradient
(which is sometimes referred to as a two point conic gradient, but is not the
same as a CSS conic gradient which corresponds to a SweepGradient). A
focal point and focal_radius can be specified
similarly to center and radius, which will make the
rendered gradient appear to be pointed or directed in the direction of the
focal point. This is only important if focal and
center are not equal or focal_radius > 0.0 (as this
case is visually identical to a normal radial gradient). One important case to avoid is
having focal and center both resolve to
Offset::ZERO when focal_radius > 0.0. In such a case, a valid
shader cannot be created by the framework.
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 radius between 0.0 and 1.0,
giving concentric rings for each color stop. If it is null, a uniform
distribution is assumed.
The region of the canvas beyond radius from the center
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 radial 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.
radius: f64The radius of the gradient, as a fraction of the shortest side of the paint box.
For example, if a radial gradient is painted on a box that is
100.0 pixels wide and 200.0 pixels tall, then a radius of 1.0
will place the 1.0 stop at 100.0 pixels from the center.
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§focal: Option<AlignmentGeometry>The focal point of the gradient. If specified, the gradient will appear
to be focused along the vector from center to focal.
See center for a description of how the coordinates are mapped.
If this value is specified and focal_radius > 0.0, care should
be taken to ensure that either this value or center will not both
resolve to Offset::ZERO, which would fail to create a valid gradient.
focal_radius: f64The radius of the focal point of gradient, as a fraction of the shortest side of the paint box.
For example, if a radial gradient is painted on a box that is
100.0 pixels wide and 200.0 pixels tall, then a radius of 1.0
will place the 1.0 stop at 100.0 pixels from the focal point.
If this value is specified and is greater than 0.0, either focal or
center must not resolve to Offset::ZERO, which would fail to
create a valid gradient.
transform: Option<Rc<dyn GradientTransform>>The transform, if any, to apply to the gradient.
Implementations§
Source§impl RadialGradient
impl RadialGradient
Sourcepub fn new(colors: Vec<Color>) -> RadialGradient
pub fn new(colors: Vec<Color>) -> RadialGradient
Sourcepub fn center(self, center: impl Into<AlignmentGeometry>) -> RadialGradient
pub fn center(self, center: impl Into<AlignmentGeometry>) -> RadialGradient
Dart RadialGradient(center:).
Sourcepub fn radius(self, radius: f64) -> RadialGradient
pub fn radius(self, radius: f64) -> RadialGradient
Dart RadialGradient(radius:).
Sourcepub fn stops(self, stops: Vec<f64>) -> RadialGradient
pub fn stops(self, stops: Vec<f64>) -> RadialGradient
Dart RadialGradient(stops:).
Sourcepub fn tile_mode(self, tile_mode: TileMode) -> RadialGradient
pub fn tile_mode(self, tile_mode: TileMode) -> RadialGradient
Dart RadialGradient(tileMode:).
Sourcepub fn focal(self, focal: impl Into<AlignmentGeometry>) -> RadialGradient
pub fn focal(self, focal: impl Into<AlignmentGeometry>) -> RadialGradient
Dart RadialGradient(focal:).
Sourcepub fn focal_radius(self, focal_radius: f64) -> RadialGradient
pub fn focal_radius(self, focal_radius: f64) -> RadialGradient
Dart RadialGradient(focalRadius:).
Sourcepub fn transform(
self,
transform: impl Into<Rc<dyn GradientTransform>>,
) -> RadialGradient
pub fn transform( self, transform: impl Into<Rc<dyn GradientTransform>>, ) -> RadialGradient
Dart RadialGradient(transform:).
Sourcepub fn scale(&self, factor: f64) -> RadialGradient
pub fn scale(&self, factor: f64) -> RadialGradient
Returns a new RadialGradient 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) -> RadialGradient
pub fn from_color(&self, color: Color) -> RadialGradient
Dart’s RadialGradient.fromColor: the geometry kept, every color replaced by color.
Sourcepub fn lerp(
a: Option<&RadialGradient>,
b: Option<&RadialGradient>,
t: f64,
) -> Option<RadialGradient>
pub fn lerp( a: Option<&RadialGradient>, b: Option<&RadialGradient>, t: f64, ) -> Option<RadialGradient>
Linearly interpolate between two RadialGradients.
If either gradient is None, this function linearly interpolates from
a gradient that matches the other gradient in center,
radius, 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) -> RadialGradient
pub fn with_opacity(&self, opacity: f64) -> RadialGradient
Returns a new RadialGradient with each color set to the given opacity.
Trait Implementations§
Source§impl Clone for RadialGradient
impl Clone for RadialGradient
Source§fn clone(&self) -> RadialGradient
fn clone(&self) -> RadialGradient
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 RadialGradient
impl Debug for RadialGradient
Source§impl Gradient for RadialGradient
impl Gradient for RadialGradient
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.