graphics

package
v0.1.122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package graphics provides UI graphics primitives.

Index

Constants

View Source
const (
	// DefaultStrokeWidth is the default stroke width (hairline).
	DefaultStrokeWidth float32 = 0.0

	// DefaultStrokeMiter is the default miter limit.
	DefaultStrokeMiter float32 = 4.0
)

Default stroke constants

Variables

View Source
var DefaultBlendMode = BlendModeSrcOver

DefaultBlendMode is the default blend mode used for drawing operations.

View Source
var DefaultDensity = unit.NewDensity(1.0, 1.0)

DefaultDensity is a stub density value used as a placeholder within CanvasDrawScope. The actual density is provided as a parameter during draw calls.

View Source
var DefaultStrokeCap = StrokeCapButt

DefaultStrokeCap is the default stroke cap.

View Source
var DefaultStrokeJoin = StrokeJoinMiter

DefaultStrokeJoin is the default stroke join.

View Source
var DrawStyleFill = Fill

DrawStyleFill is an alias for Fill for backwards compatibility.

Hairline represents a hairline stroke (the thinnest line that can be drawn).

View Source
var IntOffsetZero = IntOffset{X: 0, Y: 0}

IntOffsetZero is an IntOffset with zero values.

View Source
var IntSizeZero = IntSize{Width: 0, Height: 0}

IntSizeZero is an IntSize with zero dimensions.

View Source
var MatrixIdentity = Matrix{
	1, 0, 0, 0,
	0, 1, 0, 0,
	0, 0, 1, 0,
	0, 0, 0, 1,
}

MatrixIdentity is the identity matrix.

View Source
var (
	// ShadowNone represents no shadow. Use this constant instead of allocating a new zero Shadow.
	ShadowNone = NewShadow(ColorBlack, ZeroOffset, 0)
)

Zero constants (define these once)

View Source
var ShadowUnspecified = &Shadow{
	Color:      ColorUnspecified,
	Offset:     geometry.OffsetUnspecified,
	BlurRadius: floatutils.Float32Unspecified,
}

ShadowUnspecified is the singleton sentinel for unspecified/empty Shadow. It is allocated in the data segment (global) and used as a pointer to avoid allocations.

View Source
var ZeroOffset = geometry.OffsetZero

Functions

func ColorToNRGBA

func ColorToNRGBA(c Color) color.NRGBA

func Degrees

func Degrees(radians float32) float32

Degrees converts radians to degrees.

func EqualBrush

func EqualBrush(a, b Brush) bool

func EqualDrawStyle

func EqualDrawStyle(a, b DrawStyle) bool

func EqualLinearGradient

func EqualLinearGradient(a, b *LinearGradient) bool

func EqualRadialGradient

func EqualRadialGradient(a, b *RadialGradient) bool

func EqualShadow

func EqualShadow(a, b *Shadow) bool

func EqualSolidColor

func EqualSolidColor(a, b *SolidColor) bool

func EqualSweepGradient

func EqualSweepGradient(a, b *SweepGradient) bool

func InsetAll

func InsetAll(t DrawTransform, inset float32)

InsetAll is a convenience method that insets all sides by the same amount.

func InsetSymmetric

func InsetSymmetric(t DrawTransform, horizontal, vertical float32)

InsetSymmetric is a convenience method that insets both left/right by horizontal and top/bottom by vertical.

func IsShaderBrush

func IsShaderBrush(b Brush) bool

func IsSolidColor

func IsSolidColor(b Brush) bool

func IsSpecifiedBrush

func IsSpecifiedBrush(s Brush) bool

Short for IsSpecifiedShadow

func IsSpecifiedShadow

func IsSpecifiedShadow(s *Shadow) bool

Short for IsSpecifiedShadow

func Radians

func Radians(degrees float32) float32

Radians converts degrees to radians.

func RotateRad

func RotateRad(t DrawTransform, radians float32, pivot geometry.Offset)

RotateRad is a convenience method that rotates by radians instead of degrees.

func SameBrush

func SameBrush(a, b Brush) bool

Identity (2 ns)

func SameShadow

func SameShadow(a, b *Shadow) bool

Identity (2 ns)

func ScaleUniform

func ScaleUniform(t DrawTransform, scale float32, pivot geometry.Offset)

ScaleUniform is a convenience method that scales uniformly in both directions.

func SemanticEqualBrush

func SemanticEqualBrush(a, b Brush) bool

Semantic equality (field-by-field, 20 ns)

func SemanticEqualLinearGradient

func SemanticEqualLinearGradient(a, b *LinearGradient) bool

func SemanticEqualRadialGradient

func SemanticEqualRadialGradient(a, b *RadialGradient) bool

func SemanticEqualShadow

func SemanticEqualShadow(a, b *Shadow) bool

Semantic equality (field-by-field, 20 ns)

func SemanticEqualSolidColor

func SemanticEqualSolidColor(a, b *SolidColor) bool

func SemanticEqualSweepGradient

func SemanticEqualSweepGradient(a, b *SweepGradient) bool

func StringShadow

func StringShadow(s *Shadow) string

func WithClipPath

func WithClipPath(scope DrawScope, path Path, clipOp ClipOp, block func(DrawScope))

WithClipPath reduces the clip region to the given path.

func WithClipRect

func WithClipRect(scope DrawScope, left, top, right, bottom float32, clipOp ClipOp, block func(DrawScope))

WithClipRect reduces the clip region to the given rectangle.

func WithClipRectBounds

func WithClipRectBounds(scope DrawScope, clipOp ClipOp, block func(DrawScope))

WithClipRectBounds clips to the current drawing bounds.

func WithInset

func WithInset(scope DrawScope, left, top, right, bottom float32, block func(DrawScope))

WithInset translates the coordinate space and modifies the drawing bounds. The width becomes width - (left + right), height becomes height - (top + bottom).

func WithInsetAll

func WithInsetAll(scope DrawScope, inset float32, block func(DrawScope))

WithInsetAll is a convenience function that insets all sides equally.

func WithInsetSymmetric

func WithInsetSymmetric(scope DrawScope, horizontal, vertical float32, block func(DrawScope))

WithInsetSymmetric is a convenience function for symmetric horizontal and vertical insets.

func WithRotate

func WithRotate(scope DrawScope, degrees float32, pivot geometry.Offset, block func(DrawScope))

WithRotate rotates the coordinate space around the given pivot point.

func WithRotateCenter

func WithRotateCenter(scope DrawScope, degrees float32, block func(DrawScope))

WithRotateCenter rotates the coordinate space around the center.

func WithRotateRad

func WithRotateRad(scope DrawScope, radians float32, pivot geometry.Offset, block func(DrawScope))

WithRotateRad rotates the coordinate space by radians around the given pivot point.

func WithSave

func WithSave(canvas Canvas, block func())

WithSave executes the given block with a save/restore pair.

func WithSaveLayer

func WithSaveLayer(canvas Canvas, bounds geometry.Rect, paint *Paint, block func())

WithSaveLayer executes the given block with a saveLayer/restore pair.

func WithScale

func WithScale(scope DrawScope, scaleX, scaleY float32, pivot geometry.Offset, block func(DrawScope))

WithScale scales the coordinate space around the given pivot point.

func WithScaleCenter

func WithScaleCenter(scope DrawScope, scale float32, block func(DrawScope))

WithScaleCenter scales uniformly around the center.

func WithTransform

func WithTransform(scope DrawScope, transformBlock func(DrawTransform), drawBlock func(DrawScope))

WithTransform performs transformations and executes drawing commands within the transformed space. After the block completes, the transformation is restored.

func WithTranslate

func WithTranslate(scope DrawScope, left, top float32, block func(DrawScope))

WithTranslate translates the coordinate space.

Types

type BlendMode

type BlendMode int

BlendMode defines algorithms to use when painting on the canvas. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/BlendMode.kt

const (
	BlendModeClear      BlendMode = 0
	BlendModeSrc        BlendMode = 1
	BlendModeDst        BlendMode = 2
	BlendModeSrcOver    BlendMode = 3
	BlendModeDstOver    BlendMode = 4
	BlendModeSrcIn      BlendMode = 5
	BlendModeDstIn      BlendMode = 6
	BlendModeSrcOut     BlendMode = 7
	BlendModeDstOut     BlendMode = 8
	BlendModeSrcAtop    BlendMode = 9
	BlendModeDstAtop    BlendMode = 10
	BlendModeXor        BlendMode = 11
	BlendModePlus       BlendMode = 12
	BlendModeModulate   BlendMode = 13
	BlendModeScreen     BlendMode = 14
	BlendModeOverlay    BlendMode = 15
	BlendModeDarken     BlendMode = 16
	BlendModeLighten    BlendMode = 17
	BlendModeColorDodge BlendMode = 18
	BlendModeColorBurn  BlendMode = 19
	BlendModeHardlight  BlendMode = 20
	BlendModeSoftlight  BlendMode = 21
	BlendModeDifference BlendMode = 22
	BlendModeExclusion  BlendMode = 23
	BlendModeMultiply   BlendMode = 24
	BlendModeHue        BlendMode = 25
	BlendModeSaturation BlendMode = 26
	BlendModeColor      BlendMode = 27
	BlendModeLuminosity BlendMode = 28
)

func (BlendMode) IsSupported

func (b BlendMode) IsSupported() bool

IsSupported returns whether the BlendMode is supported. SrcOver is guaranteed to be supported.

func (BlendMode) String

func (b BlendMode) String() string

type Brush

type Brush interface {
	ApplyTo(size geometry.Size, p *Paint, alpha float32)
	IntrinsicSize() geometry.Size
	// contains filtered or unexported methods
}

Brush is the interface for all brush types used for drawing. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/Brush.kt

var BrushUnspecified Brush = &SolidColor{Value: ColorUnspecified}

func CoalesceBrush

func CoalesceBrush(ptr, def Brush) Brush

func LerpBrush

func LerpBrush(start, stop Brush, fraction float32) Brush

LerpBrush linearly interpolates between two brushes.

func TakeOrElseBrush

func TakeOrElseBrush(s, def Brush) Brush

type Canvas

type Canvas interface {
	// Save saves a copy of the current transform and clip on the save stack.
	Save()

	// Restore pops the current save stack, restoring the previous transform and clip.
	Restore()

	// SaveLayer saves the current state and creates a new group for subsequent operations.
	// When restored, the layer is composited into the previous layer using the paint's blend mode.
	SaveLayer(bounds geometry.Rect, paint *Paint)

	// Translate shifts the coordinate space by the given delta.
	Translate(dx, dy float32)

	// Scale scales the coordinate space by the given factors.
	Scale(sx, sy float32)

	// Rotate rotates the coordinate space by the given degrees clockwise.
	Rotate(degrees float32)

	// Skew applies an axis-aligned skew transformation.
	Skew(sx, sy float32)

	// Concat multiplies the current transform by the specified matrix.
	Concat(matrix Matrix)

	// ClipRect reduces the clip region to the intersection of the current clip and the given rectangle.
	ClipRect(left, top, right, bottom float32, clipOp ClipOp)

	// ClipPath reduces the clip region to the intersection of the current clip and the given path.
	ClipPath(path Path, clipOp ClipOp)

	// DrawLine draws a line between the given points.
	DrawLine(p1, p2 geometry.Offset, paint *Paint)

	// DrawRect draws a rectangle.
	DrawRect(left, top, right, bottom float32, paint *Paint)

	// DrawRoundRect draws a rounded rectangle.
	DrawRoundRect(left, top, right, bottom, radiusX, radiusY float32, paint *Paint)

	// DrawOval draws an axis-aligned oval that fills the given rectangle.
	DrawOval(left, top, right, bottom float32, paint *Paint)

	// DrawCircle draws a circle at the given center with the given radius.
	DrawCircle(center geometry.Offset, radius float32, paint *Paint)

	// DrawArc draws an arc scaled to fit inside the given rectangle.
	DrawArc(left, top, right, bottom, startAngle, sweepAngle float32, useCenter bool, paint *Paint)

	// DrawPath draws the given path.
	DrawPath(path Path, paint *Paint)

	// DrawImage draws an image at the given offset.
	DrawImage(image ImageBitmap, topLeftOffset geometry.Offset, paint *Paint)

	// DrawImageRect draws a portion of an image into a destination rectangle.
	DrawImageRect(image ImageBitmap, srcOffset IntOffset, srcSize IntSize, dstOffset IntOffset, dstSize IntSize, paint *Paint)

	// DrawPoints draws a sequence of points according to the given PointMode.
	DrawPoints(pointMode PointMode, points []geometry.Offset, paint *Paint)

	// EnableZ enables Z-ordering for 3D-like effects (Android-specific, may be no-op on other platforms).
	EnableZ()

	// DisableZ disables Z-ordering.
	DisableZ()
}

Canvas provides a low-level interface for drawing operations. This is an interface that will be implemented by platform-specific backends (e.g., Skia). https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/Canvas.kt

type CanvasDrawScope

type CanvasDrawScope struct {
	// contains filtered or unexported fields
}

CanvasDrawScope is the implementation of DrawScope that issues drawing commands into the specified canvas and bounds. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/CanvasDrawScope.kt

func NewCanvasDrawScope

func NewCanvasDrawScope() *CanvasDrawScope

NewCanvasDrawScope creates a new CanvasDrawScope.

func (*CanvasDrawScope) Center

func (c *CanvasDrawScope) Center() geometry.Offset

func (*CanvasDrawScope) Density

func (c *CanvasDrawScope) Density() float32

Density interface implementation

func (*CanvasDrawScope) DpRectToRect

func (c *CanvasDrawScope) DpRectToRect(rect unit.DpRect) geometry.Rect

func (*CanvasDrawScope) DpRoundToPx

func (c *CanvasDrawScope) DpRoundToPx(dp unit.Dp) int

func (*CanvasDrawScope) DpSizeToSize

func (c *CanvasDrawScope) DpSizeToSize(size unit.DpSize) geometry.Size

func (*CanvasDrawScope) DpToPx

func (c *CanvasDrawScope) DpToPx(dp unit.Dp) float32

func (*CanvasDrawScope) DpToTextUnit added in v0.1.120

func (c *CanvasDrawScope) DpToTextUnit(dp unit.Dp) unit.TextUnit

func (*CanvasDrawScope) Draw

func (c *CanvasDrawScope) Draw(
	density unit.Density,
	layoutDirection unit.LayoutDirection,
	canvas Canvas,
	size geometry.Size,
	block func(DrawScope),
)

Draw executes the drawing commands within the provided canvas and bounds.

func (*CanvasDrawScope) DrawArc

func (c *CanvasDrawScope) DrawArc(color Color, startAngle, sweepAngle float32, useCenter bool, opts ...DrawArcOption)

func (*CanvasDrawScope) DrawArcWithBrush

func (c *CanvasDrawScope) DrawArcWithBrush(brush Brush, startAngle, sweepAngle float32, useCenter bool, opts ...DrawArcOption)

func (*CanvasDrawScope) DrawCircle

func (c *CanvasDrawScope) DrawCircle(color Color, opts ...DrawCircleOption)

func (*CanvasDrawScope) DrawCircleWithBrush

func (c *CanvasDrawScope) DrawCircleWithBrush(brush Brush, opts ...DrawCircleOption)

func (*CanvasDrawScope) DrawContext

func (c *CanvasDrawScope) DrawContext() DrawContext

DrawScope interface implementation

func (*CanvasDrawScope) DrawImage

func (c *CanvasDrawScope) DrawImage(image ImageBitmap, opts ...DrawImageOption)

func (*CanvasDrawScope) DrawIntoCanvas

func (c *CanvasDrawScope) DrawIntoCanvas(block func(Canvas))

func (*CanvasDrawScope) DrawLine

func (c *CanvasDrawScope) DrawLine(color Color, start, end geometry.Offset, opts ...DrawLineOption)

Drawing methods

func (*CanvasDrawScope) DrawLineWithBrush

func (c *CanvasDrawScope) DrawLineWithBrush(brush Brush, start, end geometry.Offset, opts ...DrawLineOption)

func (*CanvasDrawScope) DrawOval

func (c *CanvasDrawScope) DrawOval(color Color, opts ...DrawOvalOption)

func (*CanvasDrawScope) DrawOvalWithBrush

func (c *CanvasDrawScope) DrawOvalWithBrush(brush Brush, opts ...DrawOvalOption)

func (*CanvasDrawScope) DrawPath

func (c *CanvasDrawScope) DrawPath(path Path, color Color, opts ...DrawPathOption)

func (*CanvasDrawScope) DrawPathWithBrush

func (c *CanvasDrawScope) DrawPathWithBrush(path Path, brush Brush, opts ...DrawPathOption)

func (*CanvasDrawScope) DrawPoints

func (c *CanvasDrawScope) DrawPoints(points []geometry.Offset, pointMode PointMode, color Color, opts ...DrawPointsOption)

func (*CanvasDrawScope) DrawPointsWithBrush

func (c *CanvasDrawScope) DrawPointsWithBrush(points []geometry.Offset, pointMode PointMode, brush Brush, opts ...DrawPointsOption)

func (*CanvasDrawScope) DrawRect

func (c *CanvasDrawScope) DrawRect(color Color, opts ...DrawRectOption)

func (*CanvasDrawScope) DrawRectWithBrush

func (c *CanvasDrawScope) DrawRectWithBrush(brush Brush, opts ...DrawRectOption)

func (*CanvasDrawScope) DrawRoundRect

func (c *CanvasDrawScope) DrawRoundRect(color Color, opts ...DrawRoundRectOption)

func (*CanvasDrawScope) DrawRoundRectWithBrush

func (c *CanvasDrawScope) DrawRoundRectWithBrush(brush Brush, opts ...DrawRoundRectOption)

func (*CanvasDrawScope) DrawWithGraphicsLayer

func (c *CanvasDrawScope) DrawWithGraphicsLayer(
	density unit.Density,
	layoutDirection unit.LayoutDirection,
	canvas Canvas,
	size geometry.Size,
	graphicsLayer interface{},
	block func(DrawScope),
)

DrawWithGraphicsLayer executes drawing with an optional graphics layer.

func (*CanvasDrawScope) FloatToDp

func (c *CanvasDrawScope) FloatToDp(px float32) unit.Dp

func (*CanvasDrawScope) FloatToSp

func (c *CanvasDrawScope) FloatToSp(px float32) unit.TextUnit

func (*CanvasDrawScope) FontScale

func (c *CanvasDrawScope) FontScale() float32

func (*CanvasDrawScope) IntToDp

func (c *CanvasDrawScope) IntToDp(px int) unit.Dp

func (*CanvasDrawScope) IntToSp

func (c *CanvasDrawScope) IntToSp(px int) unit.TextUnit

func (*CanvasDrawScope) LayoutDirection

func (c *CanvasDrawScope) LayoutDirection() unit.LayoutDirection

func (*CanvasDrawScope) Size

func (c *CanvasDrawScope) Size() geometry.Size

func (*CanvasDrawScope) SizeToDpSize

func (c *CanvasDrawScope) SizeToDpSize(size geometry.Size) unit.DpSize

func (*CanvasDrawScope) TextUnitRoundToPx

func (c *CanvasDrawScope) TextUnitRoundToPx(tu unit.TextUnit) int

func (*CanvasDrawScope) TextUnitToDp added in v0.1.120

func (c *CanvasDrawScope) TextUnitToDp(tu unit.TextUnit) unit.Dp

func (*CanvasDrawScope) TextUnitToPx

func (c *CanvasDrawScope) TextUnitToPx(tu unit.TextUnit) float32

type ClipOp

type ClipOp int

ClipOp defines the algorithm used for clipping. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/ClipOp.kt

const (
	// ClipOpIntersect clips to the intersection of the current clip and the given path/rect.
	// This is the default behavior.
	ClipOpIntersect ClipOp = iota

	// ClipOpDifference clips to the difference of the current clip and the given path/rect.
	// This subtracts the given region from the current clip.
	ClipOpDifference
)

func (ClipOp) String

func (c ClipOp) String() string

String returns the string representation of the ClipOp.

type Color

type Color uint64

Color is a 64-bit value representing a color. The value is packed as follows: - For sRGB colors:

  • Bits 0-31: Unused (or Alpha/Red/Green/Blue for 32-bit int representation, but here it's 64-bit)
  • Actually, Kotlin docs say: "For sRGB colors, the value is packed as:
  • Bits 32-63: ARGB (8 bits per component)" "For other color spaces:
  • Bits 0-15: Red (Float16)
  • Bits 16-31: Green (Float16)
  • Bits 32-47: Blue (Float16)
  • Bits 48-57: Alpha (10 bits)
  • Bits 58-63: ColorSpace ID (6 bits)"
const (
	ColorBlack Color = 0xFF00000000000000 // sRGB Black? No, wait.
	// Kotlin: Color(0xFF000000) for Black.
	// In Kotlin, Color(int) creates an sRGB color.
	// sRGB packing in Kotlin: (value.toULong() and 0xFFFFFFFFUL) shl 32
	// So 0xFF000000 -> 0xFF00000000000000.
	// Wait, 0xFF000000 is ARGB. Alpha=255.
	// 0xFF000000 << 32 = 0xFF00000000000000?
	// 0xFF (Alpha) << 24 | 0x00 (R) << 16 ...
	// Yes.
	ColorDarkGray    Color = 0xFF44444400000000
	ColorGray        Color = 0xFF88888800000000
	ColorLightGray   Color = 0xFFCCCCCC00000000
	ColorWhite       Color = 0xFFFFFFFF00000000
	ColorRed         Color = 0xFFFF000000000000
	ColorGreen       Color = 0xFF00FF0000000000
	ColorBlue        Color = 0xFF0000FF00000000
	ColorYellow      Color = 0xFFFFFF0000000000
	ColorCyan        Color = 0xFF00FFFF00000000
	ColorMagenta     Color = 0xFFFF00FF00000000
	ColorTransparent Color = 0x0000000000000000
)

Standard Colors

const (
	// ColorUnspecified represents an uninitialized or unspecified color.
	ColorUnspecified Color = 0x10
)

func FromNRGBA

func FromNRGBA(c color.NRGBA) Color

func Hsl

func Hsl(hue, saturation, lightness, alpha float32, colorSpace *colorspace.Rgb) Color

Hsl creates a color from HSL (Hue, Saturation, Lightness) representation. hue: 0..360, saturation: 0..1, lightness: 0..1, alpha: 0..1

func Hsv

func Hsv(hue, saturation, value, alpha float32, colorSpace *colorspace.Rgb) Color

Hsv creates a color from HSV (Hue, Saturation, Value) representation. hue: 0..360, saturation: 0..1, value: 0..1, alpha: 0..1

func Lerp

func Lerp(start, stop Color, fraction float32) Color

Lerp linearly interpolates between two colors. Interpolation is done in Oklab color space for perceptually uniform results. The result is converted to the stop color's color space.

func LerpColor

func LerpColor(start, stop Color, fraction float32) Color

LerpColor interpolates between two colors.

func LerpColors

func LerpColors(a, b []Color, t float32) []Color

func NewColor

func NewColor(r, g, b, a float32, space colorspace.ColorSpace) Color

NewColor creates a new Color from float components and a ColorSpace.

func NewColorLong

func NewColorLong(argb int64) Color

NewColorLong creates a new sRGB Color from a 32-bit ARGB long. Useful for specifying colors with alpha > 0x80 without sign issues.

func NewColorSrgb

func NewColorSrgb(r, g, b, a int) Color

NewColorSrgb creates a new sRGB Color from 8-bit components.

func SetOpacity

func SetOpacity(c Color, opacity float32) Color

func UncheckedColor

func UncheckedColor(r, g, b, a float32, space colorspace.ColorSpace) Color

UncheckedColor creates a color without validation. Used for performance-critical code like lerp where values are known to be valid.

func (Color) Alpha

func (c Color) Alpha() float32

Implement basic getters

func (Color) Blue

func (c Color) Blue() float32

func (Color) ColorSpace

func (c Color) ColorSpace() colorspace.ColorSpace

ColorSpace returns the ColorSpace object for this color.

func (Color) ColorSpaceId

func (c Color) ColorSpaceId() int

func (Color) Component1

func (c Color) Component1() float32

Component accessors for destructuring

func (Color) Component2

func (c Color) Component2() float32

func (Color) Component3

func (c Color) Component3() float32

func (Color) Component4

func (c Color) Component4() float32

func (Color) Component5

func (c Color) Component5() colorspace.ColorSpace

func (Color) CompositeOver

func (c Color) CompositeOver(background Color) Color

CompositeOver composites this color over the background color. The result is in the background's color space.

func (Color) Convert

func (c Color) Convert(destColorSpace colorspace.ColorSpace) Color

Convert transforms this color to another color space.

func (Color) Copy

func (c Color) Copy(opts ...ColorCopyOption) Color

Copy creates a new color with modified components.

func (Color) GetComponents

func (c Color) GetComponents() [4]float32

GetComponents returns the color components as [red, green, blue, alpha].

func (Color) Green

func (c Color) Green() float32

func (Color) IsSpecified

func (c Color) IsSpecified() bool

func (Color) IsUnspecified

func (c Color) IsUnspecified() bool

func (Color) Luminance

func (c Color) Luminance() float32

Luminance returns the relative luminance of the color. Based on WCAG 2.0 formula.

func (Color) Red

func (c Color) Red() float32

func (Color) SetOpacity

func (c Color) SetOpacity(opacity float32) Color

func (Color) String

func (c Color) String() string

func (Color) TakeOrElse

func (c Color) TakeOrElse(block Color) Color

TakeOrElse returns this color if specified, otherwise returns the block result. Direct value version for Go zero-allocation.

func (Color) ToArgb

func (c Color) ToArgb() uint32

ToArgb converts to 32-bit ARGB. For non-sRGB colors, converts to sRGB first.

func (Color) ToNRGBA

func (c Color) ToNRGBA() color.NRGBA

type ColorCopyOption

type ColorCopyOption func(*ColorCopyOptions) ColorCopyOptions

func CopyWithAlpha

func CopyWithAlpha(alpha float32) ColorCopyOption

func CopyWithBlue

func CopyWithBlue(blue float32) ColorCopyOption

func CopyWithGreen

func CopyWithGreen(green float32) ColorCopyOption

func CopyWithRed

func CopyWithRed(red float32) ColorCopyOption

type ColorCopyOptions

type ColorCopyOptions struct {
	Alpha, Red, Green, Blue float32
}

type ColorProducer

type ColorProducer func() Color

ColorProducer is a functional interface that produces a Color. Useful for avoiding boxing in performance-critical code.

type CompositeShader

type CompositeShader struct {
	Dst       Shader
	Src       Shader
	BlendMode BlendMode
}

type ContentDrawScope

type ContentDrawScope interface {
	DrawScope

	// DrawContent causes child drawing operations to run.
	// If not called, the contents of the layout will not be drawn.
	DrawContent()
}

ContentDrawScope is a DrawScope that can draw content between other drawing operations. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/ContentDrawScope.kt

type DrawArcOption

type DrawArcOption func(*drawArcConfig)

DrawArcOption configures optional parameters for DrawArc.

func WithArcAlpha

func WithArcAlpha(alpha float32) DrawArcOption

WithArcAlpha sets the alpha.

func WithArcBlendMode

func WithArcBlendMode(mode BlendMode) DrawArcOption

WithArcBlendMode sets the blend mode.

func WithArcSize

func WithArcSize(size geometry.Size) DrawArcOption

WithArcSize sets the size.

func WithArcStyle

func WithArcStyle(style DrawStyle) DrawArcOption

WithArcStyle sets the draw style.

func WithArcTopLeft

func WithArcTopLeft(offset geometry.Offset) DrawArcOption

WithArcTopLeft sets the top-left offset.

type DrawCircleOption

type DrawCircleOption func(*drawCircleConfig)

DrawCircleOption configures optional parameters for DrawCircle.

func WithCircleAlpha

func WithCircleAlpha(alpha float32) DrawCircleOption

WithCircleAlpha sets the alpha.

func WithCircleBlendMode

func WithCircleBlendMode(mode BlendMode) DrawCircleOption

WithCircleBlendMode sets the blend mode.

func WithCircleCenter

func WithCircleCenter(center geometry.Offset) DrawCircleOption

WithCircleCenter sets the center.

func WithCircleRadius

func WithCircleRadius(radius float32) DrawCircleOption

WithCircleRadius sets the radius.

func WithCircleStyle

func WithCircleStyle(style DrawStyle) DrawCircleOption

WithCircleStyle sets the draw style.

type DrawContext

type DrawContext interface {
	// Size returns the current size of the drawing environment.
	Size() geometry.Size

	// SetSize sets the size of the drawing environment.
	SetSize(size geometry.Size)

	// Canvas returns the target canvas to issue drawing commands.
	Canvas() Canvas

	// SetCanvas sets the target canvas.
	SetCanvas(canvas Canvas)

	// Transform returns the controller for issuing transformations.
	Transform() DrawTransform

	// LayoutDirection returns the layout direction of the layout being drawn.
	LayoutDirection() unit.LayoutDirection

	// SetLayoutDirection sets the layout direction.
	SetLayoutDirection(ld unit.LayoutDirection)

	// Density returns the density used for dp/sp conversions.
	Density() unit.Density

	// SetDensity sets the density.
	SetDensity(d unit.Density)

	// GraphicsLayer returns the current graphics layer, if any.
	// May return nil if not drawing into a graphics layer.
	GraphicsLayer() interface{}

	// SetGraphicsLayer sets the current graphics layer.
	SetGraphicsLayer(layer interface{})
}

DrawContext provides the dependencies to support a DrawScope drawing environment. It provides drawing bounds (size), target canvas, and handles transformations. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext.kt

func NewDrawContext

func NewDrawContext() DrawContext

NewDrawContext creates a new DrawContext with the given initial values.

type DrawImageOption

type DrawImageOption func(*drawImageConfig)

DrawImageOption configures optional parameters for DrawImage.

func WithImageAlpha

func WithImageAlpha(alpha float32) DrawImageOption

WithImageAlpha sets the alpha.

func WithImageBlendMode

func WithImageBlendMode(mode BlendMode) DrawImageOption

WithImageBlendMode sets the blend mode.

func WithImageTopLeft

func WithImageTopLeft(offset geometry.Offset) DrawImageOption

WithImageTopLeft sets the top-left offset.

type DrawLineOption

type DrawLineOption func(*drawLineConfig)

DrawLineOption configures optional parameters for DrawLine.

func WithLineAlpha

func WithLineAlpha(alpha float32) DrawLineOption

WithLineAlpha sets the alpha for a line.

func WithLineBlendMode

func WithLineBlendMode(mode BlendMode) DrawLineOption

WithLineBlendMode sets the blend mode for a line.

func WithLineCap

func WithLineCap(cap StrokeCap) DrawLineOption

WithLineCap sets the stroke cap for a line.

func WithLineStrokeWidth

func WithLineStrokeWidth(width float32) DrawLineOption

WithLineStrokeWidth sets the stroke width for a line.

type DrawOvalOption

type DrawOvalOption func(*drawOvalConfig)

DrawOvalOption configures optional parameters for DrawOval.

func WithOvalAlpha

func WithOvalAlpha(alpha float32) DrawOvalOption

WithOvalAlpha sets the alpha.

func WithOvalBlendMode

func WithOvalBlendMode(mode BlendMode) DrawOvalOption

WithOvalBlendMode sets the blend mode.

func WithOvalSize

func WithOvalSize(size geometry.Size) DrawOvalOption

WithOvalSize sets the size.

func WithOvalStyle

func WithOvalStyle(style DrawStyle) DrawOvalOption

WithOvalStyle sets the draw style.

func WithOvalTopLeft

func WithOvalTopLeft(offset geometry.Offset) DrawOvalOption

WithOvalTopLeft sets the top-left offset.

type DrawPathOption

type DrawPathOption func(*drawPathConfig)

DrawPathOption configures optional parameters for DrawPath.

func WithPathAlpha

func WithPathAlpha(alpha float32) DrawPathOption

WithPathAlpha sets the alpha.

func WithPathBlendMode

func WithPathBlendMode(mode BlendMode) DrawPathOption

WithPathBlendMode sets the blend mode.

func WithPathStyle

func WithPathStyle(style DrawStyle) DrawPathOption

WithPathStyle sets the draw style.

type DrawPointsOption

type DrawPointsOption func(*drawPointsConfig)

DrawPointsOption configures optional parameters for DrawPoints.

func WithPointsAlpha

func WithPointsAlpha(alpha float32) DrawPointsOption

WithPointsAlpha sets the alpha.

func WithPointsBlendMode

func WithPointsBlendMode(mode BlendMode) DrawPointsOption

WithPointsBlendMode sets the blend mode.

func WithPointsCap

func WithPointsCap(cap StrokeCap) DrawPointsOption

WithPointsCap sets the stroke cap.

func WithPointsStrokeWidth

func WithPointsStrokeWidth(width float32) DrawPointsOption

WithPointsStrokeWidth sets the stroke width.

type DrawRectOption

type DrawRectOption func(*drawRectConfig)

DrawRectOption configures optional parameters for DrawRect.

func WithRectAlpha

func WithRectAlpha(alpha float32) DrawRectOption

WithRectAlpha sets the alpha for a rectangle.

func WithRectBlendMode

func WithRectBlendMode(mode BlendMode) DrawRectOption

WithRectBlendMode sets the blend mode for a rectangle.

func WithRectSize

func WithRectSize(size geometry.Size) DrawRectOption

WithRectSize sets the size for a rectangle.

func WithRectStyle

func WithRectStyle(style DrawStyle) DrawRectOption

WithRectStyle sets the draw style (Fill or Stroke) for a rectangle.

func WithRectTopLeft

func WithRectTopLeft(offset geometry.Offset) DrawRectOption

WithRectTopLeft sets the top-left offset for a rectangle.

type DrawRoundRectOption

type DrawRoundRectOption func(*drawRoundRectConfig)

DrawRoundRectOption configures optional parameters for DrawRoundRect.

func WithRoundRectAlpha

func WithRoundRectAlpha(alpha float32) DrawRoundRectOption

WithRoundRectAlpha sets the alpha.

func WithRoundRectBlendMode

func WithRoundRectBlendMode(mode BlendMode) DrawRoundRectOption

WithRoundRectBlendMode sets the blend mode.

func WithRoundRectCornerRadius

func WithRoundRectCornerRadius(radius geometry.CornerRadius) DrawRoundRectOption

WithRoundRectCornerRadius sets the corner radius.

func WithRoundRectSize

func WithRoundRectSize(size geometry.Size) DrawRoundRectOption

WithRoundRectSize sets the size.

func WithRoundRectStyle

func WithRoundRectStyle(style DrawStyle) DrawRoundRectOption

WithRoundRectStyle sets the draw style.

func WithRoundRectTopLeft

func WithRoundRectTopLeft(offset geometry.Offset) DrawRoundRectOption

WithRoundRectTopLeft sets the top-left offset.

type DrawScope

type DrawScope interface {
	unit.Density

	// DrawContext returns the underlying draw context.
	DrawContext() DrawContext

	// LayoutDirection returns the layout direction of the layout being drawn.
	LayoutDirection() unit.LayoutDirection

	// Size returns the current size of the drawing environment.
	Size() geometry.Size

	// Center returns the center of the current drawing environment.
	Center() geometry.Offset

	// DrawLine draws a line between the given points using a color.
	DrawLine(color Color, start, end geometry.Offset, opts ...DrawLineOption)

	// DrawLineWithBrush draws a line between the given points using a brush.
	DrawLineWithBrush(brush Brush, start, end geometry.Offset, opts ...DrawLineOption)

	// DrawRect draws a rectangle with the given color.
	DrawRect(color Color, opts ...DrawRectOption)

	// DrawRectWithBrush draws a rectangle with the given brush.
	DrawRectWithBrush(brush Brush, opts ...DrawRectOption)

	// DrawRoundRect draws a rounded rectangle with the given color.
	DrawRoundRect(color Color, opts ...DrawRoundRectOption)

	// DrawRoundRectWithBrush draws a rounded rectangle with the given brush.
	DrawRoundRectWithBrush(brush Brush, opts ...DrawRoundRectOption)

	// DrawCircle draws a circle with the given color.
	DrawCircle(color Color, opts ...DrawCircleOption)

	// DrawCircleWithBrush draws a circle with the given brush.
	DrawCircleWithBrush(brush Brush, opts ...DrawCircleOption)

	// DrawOval draws an oval with the given color.
	DrawOval(color Color, opts ...DrawOvalOption)

	// DrawOvalWithBrush draws an oval with the given brush.
	DrawOvalWithBrush(brush Brush, opts ...DrawOvalOption)

	// DrawArc draws an arc with the given color.
	DrawArc(color Color, startAngle, sweepAngle float32, useCenter bool, opts ...DrawArcOption)

	// DrawArcWithBrush draws an arc with the given brush.
	DrawArcWithBrush(brush Brush, startAngle, sweepAngle float32, useCenter bool, opts ...DrawArcOption)

	// DrawPath draws a path with the given color.
	DrawPath(path Path, color Color, opts ...DrawPathOption)

	// DrawPathWithBrush draws a path with the given brush.
	DrawPathWithBrush(path Path, brush Brush, opts ...DrawPathOption)

	// DrawPoints draws a sequence of points with the given color.
	DrawPoints(points []geometry.Offset, pointMode PointMode, color Color, opts ...DrawPointsOption)

	// DrawPointsWithBrush draws a sequence of points with the given brush.
	DrawPointsWithBrush(points []geometry.Offset, pointMode PointMode, brush Brush, opts ...DrawPointsOption)

	// DrawImage draws an image at the given offset.
	DrawImage(image ImageBitmap, opts ...DrawImageOption)

	// DrawIntoCanvas provides direct access to the underlying canvas.
	DrawIntoCanvas(block func(Canvas))
}

DrawScope provides a scoped drawing environment with a declarative, stateless API. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.kt

type DrawStyle

type DrawStyle interface {
	// contains filtered or unexported methods
}

DrawStyle defines a way to draw something. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.kt;l=939

var Fill DrawStyle = fillStyle{}

Fill is the default DrawStyle indicating shapes should be drawn completely filled.

func TakeOrElseDrawStyle

func TakeOrElseDrawStyle(a, b DrawStyle) DrawStyle

type DrawTransform

type DrawTransform interface {
	// Size returns the current size of the drawing environment.
	Size() geometry.Size

	// Center returns the center offset of the current transformation.
	Center() geometry.Offset

	// Inset simultaneously translates the coordinate space and modifies the drawing bounds.
	// The width becomes width - (left + right), height becomes height - (top + bottom).
	Inset(left, top, right, bottom float32)

	// ClipRect reduces the clip region to the intersection of the current clip
	// and the given rectangle.
	ClipRect(left, top, right, bottom float32, clipOp ClipOp)

	// ClipPath reduces the clip region to the intersection of the current clip
	// and the given path.
	ClipPath(path Path, clipOp ClipOp)

	// Translate translates the coordinate space by the given delta.
	Translate(left, top float32)

	// Rotate adds a rotation (in degrees clockwise) to the current transform
	// at the given pivot point.
	Rotate(degrees float32, pivot geometry.Offset)

	// Scale adds an axis-aligned scale to the current transform at the given pivot point.
	Scale(scaleX, scaleY float32, pivot geometry.Offset)

	// Transform applies the given transformation matrix to the drawing environment.
	Transform(matrix Matrix)
}

DrawTransform defines transformations that can be applied to a drawing environment. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/DrawTransform.kt

type ImageBitmap

type ImageBitmap interface {
	// Width returns the width of the image in pixels.
	Width() int

	// Height returns the height of the image in pixels.
	Height() int

	// Size returns the size of the image.
	Size() geometry.Size
}

ImageBitmap represents an image that can be drawn onto a canvas. This is an interface that will be implemented by platform-specific image types. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/ImageBitmap.kt

type ImageResource

type ImageResource struct {
	ImageOp paint.ImageOp
}

func NewResourceFromImageByPath

func NewResourceFromImageByPath(imagePath string) ImageResource

func NewResourceFromImageFS

func NewResourceFromImageFS(assetsFS fs.ReadFileFS, imagePath string) ImageResource

func NewResourceFromImageFile

func NewResourceFromImageFile(imageFile io.Reader) ImageResource

type LinearGradient

type LinearGradient struct {
	Colors   []Color
	Stops    []float32
	Start    geometry.Offset
	End      geometry.Offset
	TileMode TileMode
}

LinearGradient Brush implementation.

func HorizontalGradient

func HorizontalGradient(colors []Color, startX, endX float32, tileMode TileMode) *LinearGradient

func LinearGradientBrush

func LinearGradientBrush(colors []Color, start, end geometry.Offset, tileMode TileMode) *LinearGradient

func LinearGradientBrushWithStops

func LinearGradientBrushWithStops(colorStops []struct {
	Stop  float32
	Color Color
}, start, end geometry.Offset, tileMode TileMode) *LinearGradient

func VerticalGradient

func VerticalGradient(colors []Color, startY, endY float32, tileMode TileMode) *LinearGradient

func (LinearGradient) ApplyTo

func (l LinearGradient) ApplyTo(size geometry.Size, p *Paint, alpha float32)

func (LinearGradient) CreateShader

func (l LinearGradient) CreateShader(size geometry.Size) Shader

func (LinearGradient) IntrinsicSize

func (l LinearGradient) IntrinsicSize() geometry.Size

type LinearGradientShader

type LinearGradientShader struct {
	Colors     []Color
	ColorStops []float32
	From       Offset
	To         Offset
	TileMode   TileMode
}

type Offset

type Offset = geometry.Offset

type Paint

type Paint struct {
	Alpha       float32
	Color       Color
	Shader      Shader
	BlendMode   BlendMode
	StrokeWidth float32
}

Paint holds the style and color information about how to draw geometries, text and bitmaps.

func NewPaint

func NewPaint() *Paint

NewPaint creates a new Paint instance with default values.

type Path

type Path interface {
	// FillType returns the path fill type.
	FillType() PathFillType

	// SetFillType sets the path fill type.
	SetFillType(fillType PathFillType)

	// IsConvex returns true if the path is convex.
	IsConvex() bool

	// IsEmpty returns true if the path is empty (contains no lines or curves).
	IsEmpty() bool

	// MoveTo starts a new subpath at the given coordinate.
	MoveTo(x, y float32)

	// RelativeMoveTo starts a new subpath at the given offset from the current point.
	RelativeMoveTo(dx, dy float32)

	// LineTo adds a straight line segment from the current point to the given point.
	LineTo(x, y float32)

	// RelativeLineTo adds a straight line segment from the current point to the point
	// at the given offset from the current point.
	RelativeLineTo(dx, dy float32)

	// QuadraticTo adds a quadratic bezier segment that curves from the current point
	// to (x2, y2), using (x1, y1) as the control point.
	QuadraticTo(x1, y1, x2, y2 float32)

	// RelativeQuadraticTo adds a quadratic bezier segment using relative coordinates.
	RelativeQuadraticTo(dx1, dy1, dx2, dy2 float32)

	// CubicTo adds a cubic bezier segment that curves from the current point to (x3, y3),
	// using (x1, y1) and (x2, y2) as control points.
	CubicTo(x1, y1, x2, y2, x3, y3 float32)

	// RelativeCubicTo adds a cubic bezier segment using relative coordinates.
	RelativeCubicTo(dx1, dy1, dx2, dy2, dx3, dy3 float32)

	// ArcTo adds an arc segment from the current point.
	ArcTo(rect geometry.Rect, startAngleDegrees, sweepAngleDegrees float32, forceMoveTo bool)

	// AddRect adds a rectangle as a new subpath.
	AddRect(rect geometry.Rect, direction PathDirection)

	// AddOval adds an oval (ellipse) as a new subpath.
	AddOval(oval geometry.Rect, direction PathDirection)

	// AddArc adds an arc segment as a new subpath.
	AddArc(oval geometry.Rect, startAngleDegrees, sweepAngleDegrees float32)

	// AddPath adds another path to this path with an optional offset.
	AddPath(path Path, offset geometry.Offset)

	// Close closes the current subpath.
	Close()

	// Reset clears all subpaths from the path.
	Reset()

	// Rewind clears lines and curves but keeps internal data structure for faster reuse.
	Rewind()

	// Translate translates all segments by the given offset.
	Translate(offset geometry.Offset)

	// GetBounds computes the bounds of the control points of the path.
	GetBounds() geometry.Rect

	// Op performs a boolean operation on two paths.
	Op(path1, path2 Path, operation PathOperation) bool
}

Path defines an interface for 2D geometric paths.

A path contains zero or more subpaths, each of which contains zero or more straight line segments and/or bezier curve segments.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/Path.kt

type PathDirection

type PathDirection int

PathDirection specifies how closed shapes are wound when added to a path.

const (
	// PathDirectionCounterClockwise means the shape is wound in counter-clockwise order.
	PathDirectionCounterClockwise PathDirection = iota

	// PathDirectionClockwise means the shape is wound in clockwise order.
	PathDirectionClockwise
)

func (PathDirection) String

func (d PathDirection) String() string

String returns the string representation of the PathDirection.

type PathFillType

type PathFillType int

PathFillType determines how the interior of a path is calculated.

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/PathFillType.kt

const (
	// PathFillTypeNonZero specifies that the path uses the non-zero winding rule.
	PathFillTypeNonZero PathFillType = iota

	// PathFillTypeEvenOdd specifies that the path uses the even-odd winding rule.
	PathFillTypeEvenOdd
)

func (PathFillType) String

func (f PathFillType) String() string

String returns the string representation of the PathFillType.

type PathOperation

type PathOperation int

PathOperation specifies the boolean operation to perform on two paths.

const (
	// PathOperationDifference subtracts path2 from path1.
	PathOperationDifference PathOperation = iota

	// PathOperationIntersect returns the intersection of path1 and path2.
	PathOperationIntersect

	// PathOperationUnion returns the union of path1 and path2.
	PathOperationUnion

	// PathOperationXor returns the exclusive-or of path1 and path2.
	PathOperationXor

	// PathOperationReverseDifference subtracts path1 from path2.
	PathOperationReverseDifference
)

func (PathOperation) String

func (o PathOperation) String() string

String returns the string representation of the PathOperation.

type PointMode

type PointMode int

PointMode defines the manner in which a sequence of points should be drawn. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/PointMode.kt

const (
	// PointModePoints draws each point as a dot at the specified position.
	PointModePoints PointMode = iota

	// PointModeLines draws each pair of points as a line segment.
	// If there are an odd number of points, the last point is ignored.
	PointModeLines

	// PointModePolygon draws the list of points as a polygon, connecting consecutive points.
	// Unlike Lines, this connects each point to the next rather than treating pairs separately.
	PointModePolygon
)

func (PointMode) String

func (p PointMode) String() string

String returns the string representation of the PointMode.

type RadialGradient

type RadialGradient struct {
	Colors   []Color
	Stops    []float32
	Center   geometry.Offset
	Radius   float32
	TileMode TileMode
}

RadialGradient Brush implementation.

func RadialGradientBrush

func RadialGradientBrush(colors []Color, center geometry.Offset, radius float32, tileMode TileMode) *RadialGradient

func (RadialGradient) ApplyTo

func (r RadialGradient) ApplyTo(size geometry.Size, p *Paint, alpha float32)

func (RadialGradient) CreateShader

func (r RadialGradient) CreateShader(size geometry.Size) Shader

func (RadialGradient) IntrinsicSize

func (r RadialGradient) IntrinsicSize() geometry.Size

type RadialGradientShader

type RadialGradientShader struct {
	Colors     []Color
	ColorStops []float32
	Center     Offset
	Radius     float32
	TileMode   TileMode
}

type Shader

type Shader interface {
	// contains filtered or unexported methods
}

Shader corresponds to the Android/Skia Shader class. It is used to draw gradients and bitmaps.

type ShaderBrush

type ShaderBrush interface {
	Brush
	CreateShader(size geometry.Size) Shader
}

ShaderBrush is a Brush implementation that wraps a shader.

func AsShaderBrush

func AsShaderBrush(b Brush) ShaderBrush

type ShaderBrushForTest

type ShaderBrushForTest struct{}

ShaderBrushForTest is an exported ShaderBrush implementation for cross-package testing. Use NewShaderBrushForTest() to create instances in tests.

func NewShaderBrushForTest

func NewShaderBrushForTest() ShaderBrushForTest

func (ShaderBrushForTest) ApplyTo

func (s ShaderBrushForTest) ApplyTo(size geometry.Size, p *Paint, alpha float32)

func (ShaderBrushForTest) CreateShader

func (s ShaderBrushForTest) CreateShader(size geometry.Size) Shader

func (ShaderBrushForTest) Equal

func (s ShaderBrushForTest) Equal(other Brush) bool

func (ShaderBrushForTest) IntrinsicSize

func (s ShaderBrushForTest) IntrinsicSize() geometry.Size

type Shadow

type Shadow struct {
	Color      Color   // Color of the shadow (typically with alpha)
	Offset     Offset  // Offset from the element
	BlurRadius float32 // Blur radius in pixels
}

Shadow represents a single shadow with color, offset, and blur radius. All fields are immutable after creation; use Copy() to create modified versions.

func CoalesceShadow

func CoalesceShadow(ptr, def *Shadow) *Shadow

func CopyShadow

func CopyShadow(s *Shadow, options ...ShadowOption) *Shadow

Copy creates a new Shadow with optional field overrides.

func LerpShadow

func LerpShadow(start, stop *Shadow, fraction float32) *Shadow

LerpShadow interpolates between two Shadows.

func MergeShadow

func MergeShadow(a, b *Shadow) *Shadow

func NewShadow

func NewShadow(color Color, offset geometry.Offset, blurRadius float32) *Shadow

NewShadow creates a new Shadow instance.

func TakeOrElseShadow

func TakeOrElseShadow(s, def *Shadow) *Shadow

type ShadowOption

type ShadowOption func(*Shadow)

func WithBlurRadius

func WithBlurRadius(blurRadius float32) ShadowOption

func WithColor

func WithColor(color Color) ShadowOption

func WithOffset

func WithOffset(offset geometry.Offset) ShadowOption

type SolidColor

type SolidColor struct {
	Value Color
}

SolidColor is a Brush that represents a single solid color.

func AsSolidColor

func AsSolidColor(b Brush) *SolidColor

func NewSolidColor

func NewSolidColor(color Color) *SolidColor

NewSolidColor creates a new SolidColor brush from a Color.

func (SolidColor) ApplyTo

func (s SolidColor) ApplyTo(size geometry.Size, p *Paint, alpha float32)

func (SolidColor) IntrinsicSize

func (s SolidColor) IntrinsicSize() geometry.Size

type Stroke

type Stroke struct {
	// Width configures the width of the stroke in pixels.
	Width float32

	// Miter is the stroke miter value. Used to control the behavior of miter joins
	// when the joins angle is sharp. A value of 4.0 is the default.
	Miter float32

	// Cap is the treatment applied to the beginning and end of stroked lines and paths.
	Cap StrokeCap

	// Join is the treatment applied where lines and curve segments join on a stroked path.
	Join StrokeJoin

	// PathEffect is an optional effect to apply to the stroke.
	// Currently a placeholder - PathEffect interface needs separate implementation.
	PathEffect interface{}
}

Stroke is a DrawStyle that provides information for drawing content with a stroke. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.kt;l=960

func NewStroke

func NewStroke(width float32) *Stroke

NewStroke creates a new Stroke with the given width and default values.

func NewStrokeWithOptions

func NewStrokeWithOptions(width, miter float32, cap StrokeCap, join StrokeJoin, pathEffect interface{}) *Stroke

NewStrokeWithOptions creates a new Stroke with all customizable options.

func (*Stroke) Equal

func (s *Stroke) Equal(other *Stroke) bool

Equal checks if two Stroke instances are equal.

func (*Stroke) String

func (s *Stroke) String() string

String returns a string representation of the Stroke.

type StrokeCap

type StrokeCap int

StrokeCap defines the shape to be used at the ends of open subpaths when they are stroked. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/StrokeCap.kt

const (
	// StrokeCapButt ends with a flat edge and no extension.
	StrokeCapButt StrokeCap = iota

	// StrokeCapRound ends with a semicircle with diameter equal to the stroke width.
	StrokeCapRound

	// StrokeCapSquare ends with a half-square with side equal to the stroke width.
	StrokeCapSquare
)

func (StrokeCap) String

func (s StrokeCap) String() string

String returns the string representation of the StrokeCap.

type StrokeJoin

type StrokeJoin int

StrokeJoin defines the shape to be used at the corners of stroked paths. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/StrokeJoin.kt

const (
	// StrokeJoinMiter creates a sharp corner where line segments join.
	// The miter limit determines when the corner is beveled if too sharp.
	StrokeJoinMiter StrokeJoin = iota

	// StrokeJoinRound creates a rounded corner with radius equal to half the stroke width.
	StrokeJoinRound

	// StrokeJoinBevel creates a beveled corner where the outer edges meet with a straight line.
	StrokeJoinBevel
)

func (StrokeJoin) String

func (s StrokeJoin) String() string

String returns the string representation of the StrokeJoin.

type SweepGradient

type SweepGradient struct {
	Center geometry.Offset
	Colors []Color
	Stops  []float32
}

SweepGradient Brush implementation.

func SweepGradientBrush

func SweepGradientBrush(colors []Color, center geometry.Offset) *SweepGradient

func (SweepGradient) ApplyTo

func (s SweepGradient) ApplyTo(size geometry.Size, p *Paint, alpha float32)

func (SweepGradient) CreateShader

func (s SweepGradient) CreateShader(size geometry.Size) Shader

func (SweepGradient) IntrinsicSize

func (s SweepGradient) IntrinsicSize() geometry.Size

type SweepGradientShader

type SweepGradientShader struct {
	Center     Offset
	Colors     []Color
	ColorStops []float32
}

type TileMode

type TileMode int

TileMode defines what happens at the edge of the gradient. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/TileMode.kt

const (
	// Edge is clamped to the final color.
	TileModeClamp TileMode = 0
	// Edge is repeated from first color to last.
	TileModeRepeated TileMode = 1
	// Edge is mirrored from last color to first.
	TileModeMirror TileMode = 2
	// Render the shader's image pixels only within its original bounds.
	TileModeDecal TileMode = 3
)

func (TileMode) IsSupported

func (t TileMode) IsSupported() bool

IsSupported returns true if the TileMode is supported. Clamp, Repeated, and Mirror are guaranteed to be supported.

func (TileMode) String

func (t TileMode) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL