TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::Gradient Struct Reference

Up to kMaxStops color stops plus an angle and interpolation color space. More...

#include <gui_core/style/gui_style_gradient.h>

Public Member Functions

float GetValue () const
 value as a fraction of a full turn (see EncodeAngle).
Gradient & WithColorSpace (ColorSpace cs)
 Sets the space the stops are interpolated in; returns *this.
ColorSpace GetColorSpace () const
 Space the stops are interpolated in.
bool AddStop (const color4f &color, float offset)
 Adds a stop at offset (0..1); false when all kMaxStops are in use.
bool AddStop (const color4b &color, float offset)
 Adds a stop at offset (0..1); false when all kMaxStops are in use.
void ClearStops ()
 Removes all stops.
uint8_t StopCount () const
 The stops in use: stopCount, but never past the stop array (a gradient built in code can set stopCount to anything).
bool IsEmpty () const
 No stops, or type None: nothing to draw.
void WriteTo (std::span< color4b > out) const
 Samples the gradient evenly across out, sRGB encoded.
bool operator== (const Gradient &other) const noexcept

Static Public Member Functions

static Gradient Solid (const color4f &color)
 One color: two equal stops at 0 and 1.
static Gradient Solid (const color4b &color)
 One color: two equal stops at 0 and 1.
static Gradient Linear (const color4f &c0, const color4f &c1)
 Two stops at 0 and 1.
static Gradient Linear (const color4b &c0, const color4b &c1)
 Two stops at 0 and 1.
static Gradient Linear (const color4f &c0, const color4f &c1, const color4f &c2)
 Three stops at 0, 0.5 and 1.
static Gradient Linear (const color4b &c0, const color4b &c1, const color4b &c2)
 Three stops at 0, 0.5 and 1.
static Gradient Linear (const color4f &c0, const color4f &c1, const color4f &c2, const color4f &c3)
 Four stops at 0, 0.25, 0.5 and 1.
static Gradient Linear (const color4b &c0, const color4b &c1, const color4b &c2, const color4b &c3)
 Four stops at 0, 0.25, 0.5 and 1.
static uint16_t EncodeAngle (float angleDegrees)
 Angle as a fraction of a full turn in [0, 1), wrapping negative angles (-90deg == 270deg).
static Gradient Linear (float angleDegrees=0.0f)
 An empty linear gradient at an angle in degrees; add stops with AddStop.
static Gradient Radial (float angleDegrees=1.0f)
 An empty radial gradient; add stops with AddStop.

Public Attributes

std::array< ColorStop, kMaxStops > stops {}
 the first stopCount are in use
uint16_t value = 0
 the angle, encoded by EncodeAngle
uint8_t stopCount = 0
 stops in use
GradientType type = GradientType::None
ColorSpace colorSpace = ColorSpace::sRGB
 space the stops are interpolated in

Static Public Attributes

static constexpr int kMaxStops = 8
 capacity of stops

Detailed Description

Up to kMaxStops color stops plus an angle and interpolation color space.

Registering a color style bakes it into the gradient atlas.

Member Function Documentation

◆ GetValue()

float tachyon::Gradient::GetValue ( ) const
inline

value as a fraction of a full turn (see EncodeAngle).

◆ Solid() [1/2]

Gradient tachyon::Gradient::Solid ( const color4f & color)
inlinestatic

One color: two equal stops at 0 and 1.

◆ Solid() [2/2]

Gradient tachyon::Gradient::Solid ( const color4b & color)
inlinestatic

One color: two equal stops at 0 and 1.

◆ Linear() [1/7]

Gradient tachyon::Gradient::Linear ( const color4f & c0,
const color4f & c1 )
inlinestatic

Two stops at 0 and 1.

◆ Linear() [2/7]

Gradient tachyon::Gradient::Linear ( const color4b & c0,
const color4b & c1 )
inlinestatic

Two stops at 0 and 1.

◆ Linear() [3/7]

Gradient tachyon::Gradient::Linear ( const color4f & c0,
const color4f & c1,
const color4f & c2 )
inlinestatic

Three stops at 0, 0.5 and 1.

◆ Linear() [4/7]

Gradient tachyon::Gradient::Linear ( const color4b & c0,
const color4b & c1,
const color4b & c2 )
inlinestatic

Three stops at 0, 0.5 and 1.

◆ Linear() [5/7]

Gradient tachyon::Gradient::Linear ( const color4f & c0,
const color4f & c1,
const color4f & c2,
const color4f & c3 )
inlinestatic

Four stops at 0, 0.25, 0.5 and 1.

◆ Linear() [6/7]

Gradient tachyon::Gradient::Linear ( const color4b & c0,
const color4b & c1,
const color4b & c2,
const color4b & c3 )
inlinestatic

Four stops at 0, 0.25, 0.5 and 1.

◆ EncodeAngle()

uint16_t tachyon::Gradient::EncodeAngle ( float angleDegrees)
inlinestatic

Angle as a fraction of a full turn in [0, 1), wrapping negative angles (-90deg == 270deg).

Scaled by an even number so that 90 degrees is exactly 0.25, 180 is 0.5, etc.; the visual style turns this into a 2x2 transform.

◆ Linear() [7/7]

Gradient tachyon::Gradient::Linear ( float angleDegrees = 0.0f)
inlinestatic

An empty linear gradient at an angle in degrees; add stops with AddStop.

◆ Radial()

Gradient tachyon::Gradient::Radial ( float angleDegrees = 1.0f)
inlinestatic

An empty radial gradient; add stops with AddStop.

The angle (degrees) is encoded like Linear's and rotates the color style.

◆ WithColorSpace()

Gradient & tachyon::Gradient::WithColorSpace ( ColorSpace cs)
inline

Sets the space the stops are interpolated in; returns *this.

◆ GetColorSpace()

ColorSpace tachyon::Gradient::GetColorSpace ( ) const
inline

Space the stops are interpolated in.

◆ AddStop() [1/2]

bool tachyon::Gradient::AddStop ( const color4f & color,
float offset )
inline

Adds a stop at offset (0..1); false when all kMaxStops are in use.

◆ AddStop() [2/2]

bool tachyon::Gradient::AddStop ( const color4b & color,
float offset )
inline

Adds a stop at offset (0..1); false when all kMaxStops are in use.

◆ ClearStops()

void tachyon::Gradient::ClearStops ( )
inline

Removes all stops.

◆ StopCount()

uint8_t tachyon::Gradient::StopCount ( ) const
inline

The stops in use: stopCount, but never past the stop array (a gradient built in code can set stopCount to anything).

◆ IsEmpty()

bool tachyon::Gradient::IsEmpty ( ) const
inline

No stops, or type None: nothing to draw.

◆ WriteTo()

void tachyon::Gradient::WriteTo ( std::span< color4b > out) const

Samples the gradient evenly across out, sRGB encoded.

◆ operator==()

bool tachyon::Gradient::operator== ( const Gradient & other) const
inlinenoexcept

Member Data Documentation

◆ kMaxStops

int tachyon::Gradient::kMaxStops = 8
staticconstexpr

capacity of stops

◆ stops

std::array<ColorStop, kMaxStops> tachyon::Gradient::stops {}

the first stopCount are in use

◆ value

uint16_t tachyon::Gradient::value = 0

the angle, encoded by EncodeAngle

◆ stopCount

uint8_t tachyon::Gradient::stopCount = 0

stops in use

◆ type

GradientType tachyon::Gradient::type = GradientType::None

◆ colorSpace

ColorSpace tachyon::Gradient::colorSpace = ColorSpace::sRGB

space the stops are interpolated in


The documentation for this struct was generated from the following file: