@Js
@Serializable {
simple=true
collection=false
}
Fills a shape with a linear or radial color gradient.
NOTE: SWT only supports linear two stop gradients with no angle using the Graphics.fillRect method.
Slots
-
const static private GradientStop[] defStops := ...
white 0% to black 100%
- equalsSource
-
override Bool equals(Obj? obj)
Overrides sys::Obj.equals
Equality is based on fields.
- fromStrSource
-
static Gradient? fromStr(Str str, Bool checked := true)
Parse a gradient from string (see toStr). If invalid and checked is true then throw ParseErr otherwise return null:
<gradient> := <linear> | <radial> | <impliedLinear> <linear> := "linear(" <args> ")" <radial> := "radial(" <args> ")" <impliedLinear> := <args> <args> := <start> "," <end> ("," <stop>)* <start> := <pos> <pos> <end> := <pos> <pos> <pos> := <int> <unit> // no space allowed between <stop> := <color> [<float>] // 0f..1f <color> := #AARRGGBB, #RRGGBB, #RGB <unit> := "px" | "%"
The general format is a start and end position followed by a comma list of gradient stops. The start and end positions are x, y coordinates (% or pixel). The stops are a color followed by a position in the range (0..1). If the position is omitted it is calcaulated as percentage:
#000, #fff => #000 0.0, #fff 1.0 #000, #abc, #fff => #000 0.0, #000 0.5, #fff 1.0
Examples:
Gradient("linear(0% 0%, 100% 100%, #f00, #00f)") => linear(0% 0%, 100% 100%, #ff0000 0.0, #0000ff 1.0) Gradient("5px 3px, 25px 30px, #f00, #00f") => linear(5px 3px, 25px 30px, #ff0000 0.0, #0000ff 1.0) Gradient("0% 50%, 100% 50%, #f00 0.1, #00f 0.9") => linear(0% 50%, 100% 50%, #ff0000 0.1, #0000ff 0.9)
- hashSource
-
override Int hash()
Overrides sys::Obj.hash
Hash the fields.
-
static private Unit loadUnit(Str name, Str symbol)
Just in case unit database is not available, create unit as fallback
- makeSource
-
new make(|This|? f := null)
Construct for it-block. Throw ArgErr if any units are invalid or less than 2 stops.
-
new makeStr(Str str)
- modeSource
-
const GradientMode mode := GradientMode.linear
Mode is linear or radial
- percentSource
-
const static Unit percent
Percent unit constant
- pixelSource
-
const static Unit pixel
Pixel unit constant
- stopsSource
-
const GradientStop[] stops := defStops
List of gradient stops, default is "white 0.0" to "black 1.0".
- toStrSource
-
override Str toStr()
Overrides sys::Obj.toStr
Return
"[point1:color1; point2:color2]"
. This string format is subject to change. - x1Source
-
const Int x1 := 0
Starting point x coordinate with unit defined by x1Unit
- x1UnitSource
-
const Unit x1Unit := pixel
- x2Source
-
const Int x2 := 100
Ending point x coordinate with unit defined by x2Unit
- x2UnitSource
-
const Unit x2Unit := pixel
- y1Source
-
const Int y1 := 0
Starting point y coordinate with unit defined by y1Unit
- y1UnitSource
-
const Unit y1Unit := pixel
- y2Source
-
const Int y2 := 100
Ending point y coordinate with unit defined by y2Unit
- y2UnitSource
-
const Unit y2Unit := pixel