Package icyllis.modernui.graphics

# Class LinearGradient.Builder

java.lang.Object
icyllis.modernui.graphics.GradientShader.Builder
icyllis.modernui.graphics.LinearGradient.Builder

Enclosing class:
  `LinearGradient`

public static class LinearGradient.Builder extends GradientShader.Builder
Builder pattern of `LinearGradient`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Builder(float startX, float startY, float endX, float endY, Shader.TileMode tileMode)`
  `Builder(float startX, float startY, float endX, float endY, Shader.TileMode tileMode, ColorSpace colorSpace)`
  `Builder(float startX, float startY, float endX, float endY, Shader.TileMode tileMode, ColorSpace colorSpace, int colorCount)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `LinearGradient.Builder`
  `addColor(float r, float g, float b, float a)`
  Add a color representing the color of the i-th stop.
  `LinearGradient.Builder`
  `addColor(int color)`
  Add a color representing the color of the i-th stop.
  `LinearGradient.Builder`
  `addColorStop(float offset, int color)`
  Helper version of `addColor(int)` and `addPosition(float)`.
  `LinearGradient.Builder`
  `addPosition(float position)`
  Add a number between 0 and 1, inclusive, representing the position of the i-th color stop.
  `LinearGradient`
  `build()`
  Create the linear gradient, this builder cannot be reused anymore.
  `int`
  `getColorCount()`
  Returns the initial number of color stops.
  `LinearGradient.Builder`
  `setHueInterpolationMethod(GradientShader.HueInterpolationMethod hueInterpolationMethod)`
  For color functions with a hue angle (LCH, HSL, HWB etc.), this specifies a way to interpolate hue values.
  `LinearGradient.Builder`
  `setInterpolationColorSpace(GradientShader.InterpolationColorSpace interpolationColorSpace)`
  Set the color space for interpolation.
  `LinearGradient.Builder`
  `setInterpolationInPremul(boolean interpolationInPremul)`
  If false, gradients will interpolate their colors in unpremul space and then premultiply each of the results.
  `LinearGradient.Builder`
  `setLocalMatrix(Matrix localMatrix)`
  This specifies an additional local matrix for the gradient, it transforms gradient's local coordinates to geometry's local coordinates, null means identity.

  ### Methods inherited from class icyllis.modernui.graphics.GradientShader.Builder

  `getHueInterpolationMethod, getInterpolationColorSpace, isInterpolationInPremul`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Builder

    public Builder(float startX, float startY, float endX, float endY, @NonNull Shader.TileMode tileMode)

  - ### Builder

    public Builder(float startX, float startY, float endX, float endY, @NonNull Shader.TileMode tileMode, @Nullable ColorSpace colorSpace)

  - ### Builder

    public Builder(float startX, float startY, float endX, float endY, @NonNull Shader.TileMode tileMode, @Nullable ColorSpace colorSpace, int colorCount)

- ## Method Details

  - ### addColor

    @NonNull public LinearGradient.Builder addColor(@ColorInt int color)
    Add a color representing the color of the i-th stop.

  - ### addColor

    @NonNull public LinearGradient.Builder addColor(float r, float g, float b, float a)
    Add a color representing the color of the i-th stop.

  - ### addPosition

    @NonNull public LinearGradient.Builder addPosition(float position)
    Add a number between 0 and 1, inclusive, representing the position of the i-th color stop. 0 represents the start of the gradient and 1 represents the end.

    A gradient can be created with implicit positions (by assuming they are uniformly distributed). Once you call this method, the number of colors must be equal to the number of positions.

  - ### addColorStop

    @NonNull public LinearGradient.Builder addColorStop(float offset, @ColorInt int color)
    Helper version of `addColor(int)` and `addPosition(float)`.

  - ### getColorCount

    public int getColorCount()
    Returns the initial number of color stops.

  - ### setInterpolationInPremul

    public LinearGradient.Builder setInterpolationInPremul(boolean interpolationInPremul)
    If false, gradients will interpolate their colors in unpremul space and then premultiply each of the results. If true, gradients will premultiply their colors first, and then interpolate between them.

    Interpolating colors using the premultiplied representations tends to produce more attractive transitions than the non-premultiplied representations, particularly when transitioning from a fully opaque color to fully transparent.

    The default is true to match CSS requirements.

    Overrides:
      `setInterpolationInPremul` in class `GradientShader.Builder`
    Parameters:
      `interpolationInPremul` - whether interpolate colors in premul space

  - ### setInterpolationColorSpace

    public LinearGradient.Builder setInterpolationColorSpace(@NonNull GradientShader.InterpolationColorSpace interpolationColorSpace)
    Set the color space for interpolation.

    The default is `GradientShader.InterpolationColorSpace.DESTINATION`.

    Overrides:
      `setInterpolationColorSpace` in class `GradientShader.Builder`

  - ### setHueInterpolationMethod

    public LinearGradient.Builder setHueInterpolationMethod(@NonNull GradientShader.HueInterpolationMethod hueInterpolationMethod)
    For color functions with a hue angle (LCH, HSL, HWB etc.), this specifies a way to interpolate hue values.

    The default is `GradientShader.HueInterpolationMethod.SHORTER`.

    Overrides:
      `setHueInterpolationMethod` in class `GradientShader.Builder`

  - ### setLocalMatrix

    @NonNull public LinearGradient.Builder setLocalMatrix(@Nullable Matrix localMatrix)
    This specifies an additional local matrix for the gradient, it transforms gradient's local coordinates to geometry's local coordinates, null means identity.
    Parameters:
      `localMatrix` - the local matrix to set

  - ### build

    @NonNull public LinearGradient build()
    Create the linear gradient, this builder cannot be reused anymore.
    Specified by:
      `build` in class `GradientShader.Builder`
    Throws:
      `IllegalArgumentException` - no color, NaN, infinity, non-invertible matrix, etc.