UXGradientStop
UXGradientStop is a colour pinned to a position on a
UXGradient’s axis.
#use <UXKit> // or #import "UXGradient.xc"Overview
Section titled “Overview”class UXGradientStop : Object { i32 pos; // 0..255 along the gradient UXColor* color;}addStop makes stops and keeps
them in position order. You read them back through
stopAt, for example to serialise
a theme or draw the handles of a gradient editor.
Position is a byte, not a fraction
Section titled “Position is a byte, not a fraction”i32 pos // 0..255The range is 0–255 rather than 0.0–1.0 because the whole gradient
uses integer arithmetic. The same stops sample to the same colours on every
backend, with no float to round differently.
256 positions is finer than the eye resolves in a ramp, and finer than most displays can show without banding. If you need more steps than the axis has, add stops. The resolution that matters is the number of distinct colours, not the number of positions between them.
addStop clamps out-of-range positions to the ends instead of rejecting
them, so a stop at -50 becomes a stop at 0.
Two stops at one position make a hard edge
Section titled “Two stops at one position make a hard edge”A new stop is inserted after any existing stop at the same position.
Two stops sharing a position have zero span between them, so
colorAt jumps instead of
ramping:
g.addStop(128, red);g.addStop(128, blue); // colour switches at 128, with no blendUse this for a stepped ramp or a two-tone fill. It follows from the ordering rule, so no flag is needed.
The colour is shared, not copied
Section titled “The colour is shared, not copied”UXColor* colorThe stop keeps the pointer you passed to addStop. The toolkit treats a
UXColor as immutable, and every operation
returns a new one, so sharing a colour between stops, gradients and
controls is normal and safe.
Changing a UXColor’s fields in place would change every stop that holds
it. lightened, darkened and blend all return new colours, so you never
need to.
init leaves color null, but a stop in a gradient always has a
colour, because addStop is the only way to add one.
Fields
Section titled “Fields”i32 pos // 0..255UXColor* colorConforms to
Section titled “Conforms to”- Inherits
Object
See also
Section titled “See also”UXGradient: the ramp these defineUXColor: the colour, andblendUXColorList: named colours, when position is not what you want