canvas

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: BSD-3-Clause Imports: 24 Imported by: 6 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package canvas contains all of the primitive CanvasObjects that make up a Bellui GUI.

The types implemented in this package are used as building blocks in order to build higher order functionality. These types are designed to be non-interactive, by design. If additional functionality is required, it's usually a sign that this type should be used as part of a custom widget.

Scene3D represents a 3D scene that can be rendered as a Bellui canvas object. It contains meshes, a camera, and lights, and renders them into a 2D image using software rasterization with perspective projection and z-buffering.

Since: 1.0

Index

Constants

View Source
const (
	// DurationStandard is the time a standard interface animation will run.
	//
	// Since: 1.0
	DurationStandard = time.Millisecond * 300
	// DurationShort is the time a subtle or small transition should use.
	//
	// Since: 1.0
	DurationShort = time.Millisecond * 150

	// MD3 duration tokens.
	DurationShort1  = time.Millisecond * 50
	DurationShort2  = time.Millisecond * 100
	DurationShort3  = DurationShort // 150ms
	DurationShort4  = time.Millisecond * 200
	DurationMedium1 = time.Millisecond * 250
	DurationMedium2 = DurationStandard // 300ms
	DurationMedium3 = time.Millisecond * 350
	DurationMedium4 = time.Millisecond * 400
	DurationLong1   = time.Millisecond * 450
	DurationLong2   = time.Millisecond * 500
)
View Source
const (
	// Texture targets
	GL_TEXTURE_2D = 0x0DE1
	GL_TEXTURE0   = 0x84C0

	// Pixel formats
	GL_RGBA          = 0x1908
	GL_RGB           = 0x1907
	GL_UNSIGNED_BYTE = 0x1401

	// Texture parameters
	GL_TEXTURE_MIN_FILTER = 0x2801
	GL_TEXTURE_MAG_FILTER = 0x2800
	GL_TEXTURE_WRAP_S     = 0x2802
	GL_TEXTURE_WRAP_T     = 0x2803
	GL_LINEAR             = 0x2601
	GL_NEAREST            = 0x2600
	GL_CLAMP_TO_EDGE      = 0x812F
	GL_REPEAT             = 0x2901

	// Buffer targets
	GL_ARRAY_BUFFER         = 0x8892
	GL_ELEMENT_ARRAY_BUFFER = 0x8893

	// Buffer usage
	GL_STATIC_DRAW  = 0x88E4
	GL_DYNAMIC_DRAW = 0x88E8

	// Data types
	GL_FLOAT          = 0x1406
	GL_UNSIGNED_SHORT = 0x1403

	// Shader types
	GL_VERTEX_SHADER   = 0x8B31
	GL_FRAGMENT_SHADER = 0x8B30
	GL_COMPILE_STATUS  = 0x8B81
	GL_LINK_STATUS     = 0x8B82

	// Draw modes
	GL_POINTS         = 0x0000
	GL_LINES          = 0x0001
	GL_LINE_STRIP     = 0x0003
	GL_TRIANGLES      = 0x0004
	GL_TRIANGLE_STRIP = 0x0005
	GL_TRIANGLE_FAN   = 0x0006

	// Blend factors
	GL_ZERO                = 0
	GL_ONE                 = 1
	GL_SRC_ALPHA           = 0x0302
	GL_ONE_MINUS_SRC_ALPHA = 0x0303

	// Clear bits
	GL_COLOR_BUFFER_BIT   = 0x00004000
	GL_DEPTH_BUFFER_BIT   = 0x00000100
	GL_STENCIL_BUFFER_BIT = 0x00000400

	// Capabilities
	GL_BLEND        = 0x0BE2
	GL_DEPTH_TEST   = 0x0B71
	GL_SCISSOR_TEST = 0x0C11
	GL_STENCIL_TEST = 0x0B90

	// Depth
	GL_DEPTH_ATTACHMENT = 0x8D00
	GL_DEPTH_COMPONENT  = 0x1902

	// Framebuffer
	GL_FRAMEBUFFER          = 0x8D40
	GL_COLOR_ATTACHMENT0    = 0x8CE0
	GL_FRAMEBUFFER_COMPLETE = 0x8CD5

	// Stencil ops
	GL_KEEP    = 0x1E00
	GL_REPLACE = 0x1E01
	GL_ALWAYS  = 0x0207
	GL_EQUAL   = 0x0202

	// Boolean
	GL_TRUE  = 1
	GL_FALSE = 0
)

Standard OpenGL constants. These match the OpenGL/ES specification values and can be passed directly to GLContext methods.

View Source
const (
	// RadiusMaximum can be applied to a canvas corner radius to achieve fully rounded corners.
	// This constant represents the maximum possible corner radius, resulting in a circular appearance.
	// Since: 1.0
	RadiusMaximum float32 = math.MaxFloat32
)

Variables

View Source
var (
	// SpringGentle is a soft, slow spring with moderate oscillation.
	SpringGentle = SpringConfig{Stiffness: 120, Damping: 14, Mass: 1, MaxDuration: 2 * time.Second}

	// SpringBouncy is a lively spring with visible oscillation before settling.
	SpringBouncy = SpringConfig{Stiffness: 300, Damping: 10, Mass: 1, MaxDuration: 2 * time.Second}

	// SpringStiff is a fast, snappy spring with minimal oscillation.
	SpringStiff = SpringConfig{Stiffness: 400, Damping: 28, Mass: 1, MaxDuration: time.Second}
)

Preset spring configurations.

Functions

func NewColorRGBAAnimation

func NewColorRGBAAnimation(start, stop color.Color, d time.Duration, fn func(color.Color)) *bellui.Animation

NewColorRGBAAnimation sets up a new animation that will transition from the start to stop Color over the specified Duration. The colour transition will move linearly through the RGB colour space. The content of fn should apply the color values to an object and refresh it. You should call Start() on the returned animation to start it.

Since: 1.0

func NewFloat32Animation

func NewFloat32Animation(start, stop float32, d time.Duration, fn func(float32)) *bellui.Animation

NewFloat32Animation sets up a new animation that will transition from start to stop over the specified Duration. This is the general-purpose scalar interpolation, suitable for animating opacity, rotation angles, scale factors, or any single float32 property. The content of fn should apply the value to an object and refresh it. You should call Start() on the returned animation to start it.

func NewKeyframeAnimation

func NewKeyframeAnimation(keyframes []Keyframe, d time.Duration, fn func(float32)) *bellui.Animation

NewKeyframeAnimation creates an animation that transitions through the given keyframes over the specified duration. Each keyframe specifies a value at a progress point, with optional per-segment easing curves.

Requirements:

  • At least 2 keyframes
  • First keyframe must have Progress == 0.0 (within a small epsilon)
  • Last keyframe must have Progress == 1.0 (within a small epsilon)
  • Keyframes must be sorted by Progress (ascending)

Panics if requirements are not met. The first/last Progress checks use an epsilon tolerance so a caller computing progress as a float (e.g. 0.9999998) does not panic. The returned animation uses AnimationLinear because per-segment curves handle easing. You should call Start() on the returned animation.

func NewParallelAnimation

func NewParallelAnimation(children ...*bellui.Animation) *bellui.Animation

NewParallelAnimation creates an animation that runs all children simultaneously. The duration is the maximum of the children's durations. Children with shorter durations reach their final value and hold it until the overall animation completes.

Each child's own Curve is applied; the returned animation uses AnimationLinear so children control their own easing. Children's RepeatCount and AutoReverse fields are ignored — set those on the returned animation if needed.

func NewPathAnimation

func NewPathAnimation(points []geo.Position, d time.Duration, fn func(geo.Position)) *bellui.Animation

NewPathAnimation sets up a new animation that will move through the given waypoints over the specified Duration. The points are traversed in order with equal time per segment. At least 2 points are required. The content of fn should apply the position to an object and refresh it. You should call Start() on the returned animation to start it.

func NewPositionAnimation

func NewPositionAnimation(start, stop geo.Position, d time.Duration, fn func(geo.Position)) *bellui.Animation

NewPositionAnimation sets up a new animation that will transition from the start to stop Position over the specified Duration. The content of fn should apply the position value to an object for the change to be visible. You should call Start() on the returned animation to start it.

Since: 1.0

func NewPositionKeyframeAnimation

func NewPositionKeyframeAnimation(keyframes []PositionKeyframe, d time.Duration, fn func(geo.Position)) *bellui.Animation

NewPositionKeyframeAnimation creates an animation that transitions through position keyframes over the specified duration. See NewKeyframeAnimation for requirements.

func NewSequenceAnimation

func NewSequenceAnimation(children ...*bellui.Animation) *bellui.Animation

NewSequenceAnimation creates an animation that runs children one after another in the order given. The total duration is the sum of all children's durations.

Each child's own Curve is applied; the returned animation uses AnimationLinear. Children's RepeatCount and AutoReverse fields are ignored.

func NewSizeAnimation

func NewSizeAnimation(start, stop geo.Size, d time.Duration, fn func(geo.Size)) *bellui.Animation

NewSizeAnimation sets up a new animation that will transition from the start to stop Size over the specified Duration. The content of fn should apply the size value to an object for the change to be visible. You should call Start() on the returned animation to start it.

Since: 1.0

func NewSpringAnimation

func NewSpringAnimation(config SpringConfig, fn func(float32)) *bellui.Animation

NewSpringAnimation creates a physics-based spring animation. The callback fn receives values from 0.0 (start) to 1.0 (settled), following spring dynamics that may overshoot and oscillate depending on the configuration.

The animation runs for at most config.MaxDuration. The spring typically settles well before that. The returned animation uses AnimationLinear because the spring equation provides its own easing.

You should call Start() on the returned animation to start it.

func NewSpringFloat32Animation

func NewSpringFloat32Animation(start, stop float32, config SpringConfig, fn func(float32)) *bellui.Animation

NewSpringFloat32Animation creates a spring animation that transitions from start to stop with spring dynamics. This is a convenience wrapper around NewSpringAnimation.

You should call Start() on the returned animation to start it.

func NewStaggeredAnimation

func NewStaggeredAnimation(entries []StaggeredEntry) *bellui.Animation

NewStaggeredAnimation creates an animation that runs children with staggered start offsets. Each entry specifies an animation and its delay from the start of the overall animation. The total duration is max(entry.Delay + entry.Animation.Duration) across all entries.

Each child's own Curve is applied; the returned animation uses AnimationLinear. Children's RepeatCount and AutoReverse fields are ignored.

func RecolorSVG

func RecolorSVG(svgContent []byte, color color.Color) ([]byte, error)

RecolorSVG takes a []byte containing SVG content, and returns new SVG content, re-colorized to be monochrome with the given color. The content can be assigned to a new bellui.StaticResource with an appropriate name to be used in a widget.Button, canvas.Image, etc.

If an error occurs, the returned content will be the original un-modified content, and a non-nil error is returned.

Since: 1.0

func Refresh

func Refresh(obj core.CanvasObject)

Refresh instructs the containing canvas to refresh the specified obj.

Types

type AnimatedFloat32

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

AnimatedFloat32 tracks a float32 value that can be smoothly animated to new targets. When AnimateTo is called while an animation is running, the current (interrupted) value is captured as the start of the new animation, enabling seamless transitions.

AnimatedFloat32 must only be used from the main thread (the same goroutine that processes UI events and animation ticks).

func NewAnimatedFloat32

func NewAnimatedFloat32(initial float32) *AnimatedFloat32

NewAnimatedFloat32 creates an AnimatedFloat32 with the given initial value.

func (*AnimatedFloat32) AnimateTo

func (a *AnimatedFloat32) AnimateTo(target float32, d time.Duration, curve bellui.AnimationCurve, fn func(float32))

AnimateTo starts a new animation from the current value to target. If an animation is already running, it is stopped and the new animation starts from the interrupted value. The fn callback is called each frame with the current value; it should apply the value to a canvas object and refresh it.

func (*AnimatedFloat32) Stop

func (a *AnimatedFloat32) Stop()

Stop stops the current animation if one is running. The value remains at its current (interrupted) position.

func (*AnimatedFloat32) Value

func (a *AnimatedFloat32) Value() float32

Value returns the current animated value.

type AnimatedPosition

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

AnimatedPosition tracks a position that can be smoothly animated to new targets. When AnimateTo is called while an animation is running, the current (interrupted) position is captured as the start of the new animation.

AnimatedPosition must only be used from the main thread.

func NewAnimatedPosition

func NewAnimatedPosition(initial geo.Position) *AnimatedPosition

NewAnimatedPosition creates an AnimatedPosition with the given initial position.

func (*AnimatedPosition) AnimateTo

func (a *AnimatedPosition) AnimateTo(target geo.Position, d time.Duration, curve bellui.AnimationCurve, fn func(geo.Position))

AnimateTo starts a new animation from the current position to target. If an animation is already running, it is stopped and the new animation starts from the interrupted position.

func (*AnimatedPosition) Stop

func (a *AnimatedPosition) Stop()

Stop stops the current animation if one is running. The position remains at its current (interrupted) value.

func (*AnimatedPosition) Value

func (a *AnimatedPosition) Value() geo.Position

Value returns the current animated position.

type Arc

type Arc struct {
	FillColor    color.Color // The arc fill colour
	StartAngle   float32     // Start angle in degrees
	EndAngle     float32     // End angle in degrees
	CornerRadius float32     // Radius used to round the corners
	StrokeColor  color.Color // The arc stroke color
	StrokeWidth  float32     // The stroke width of the arc
	CutoutRatio  float32     // Controls what portion of the inner should be cut out. A value of 0.0 results in a pie slice, while 1.0 results in a stroke.
	// contains filtered or unexported fields
}

Arc represents a filled arc or annular sector primitive that can be drawn on a Bellui canvas. It allows for the creation of circular, ring-shaped or pie-shaped segment, with configurable cutout ratio as well as customizable start and end angles to define the arc's length as the absolute difference between the two angles. The arc is always centered on its position. The arc is drawn from StartAngle to EndAngle (in degrees, positive is clockwise, negative is counter-clockwise). 0°/360 is top, 90° is right, 180° is bottom, 270° is left 0°/-360 is top, -90° is left, -180° is bottom, -270° is right

Since: 1.0

func NewArc

func NewArc(startAngle, endAngle, cutoutRatio float32, color color.Color) *Arc

NewArc returns a new Arc instance with the specified start and end angles (in degrees), fill color and cutout ratio.

func NewDoughnutArc

func NewDoughnutArc(startAngle, endAngle float32, color color.Color) *Arc

NewDoughnutArc returns a new doughnut-shaped Arc instance with the specified start and end angles (in degrees), fill color and cutout ratio set to 0.5.

func NewPieArc

func NewPieArc(startAngle, endAngle float32, color color.Color) *Arc

NewPieArc returns a new pie-shaped Arc instance with the specified start and end angles (in degrees), fill color and cutout ratio set to 0.

func (*Arc) Hide

func (a *Arc) Hide()

Hide will set this arc to not be visible.

func (*Arc) MinSize

func (o *Arc) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Arc) Move

func (a *Arc) Move(pos geo.Position)

Move the arc to a new position, relative to its parent / canvas. The position specifies the **center** of the arc.

func (*Arc) Position

func (o *Arc) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Arc) Refresh

func (a *Arc) Refresh()

Refresh causes this arc to be redrawn with its configured state.

func (*Arc) Resize

func (a *Arc) Resize(s geo.Size)

Resize updates the logical size of the arc. The arc is always drawn centered on its Position().

func (*Arc) SetMinSize

func (o *Arc) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Arc) SetTransform

func (o *Arc) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Arc) Show

func (o *Arc) Show()

Show will set this object to be visible.

func (*Arc) Size

func (o *Arc) Size() geo.Size

Size returns the current size of this canvas object.

func (*Arc) Transform

func (o *Arc) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Arc) Visible

func (o *Arc) Visible() bool

Visible returns true if this object is visible, false otherwise.

type AxisConfig3D

type AxisConfig3D struct {
	Label    string
	Min, Max float32
	Ticks    int // number of tick marks (default 5)
	Color    color.Color
}

AxisConfig3D configures one axis of a 3D chart.

type BackdropBlur

type BackdropBlur struct {

	// BlurRadius is the blur radius in logical pixels, as for BoxShadow: the
	// content behind is blurred by a Gaussian of sigma BlurRadius/2.
	BlurRadius float32
	// contains filtered or unexported fields
}

BackdropBlur is a canvas object that captures the content behind it, applies a Gaussian blur, and renders the blurred result as a background.

WARNING: This uses GPU readback (ReadPixels) which is expensive. Use sparingly — one or two BackdropBlur objects per window is fine, but many will impact frame rate.

The blurred content is cached and only re-captured when Refresh() is called.

func NewBackdropBlur

func NewBackdropBlur(radius float32) *BackdropBlur

NewBackdropBlur creates a backdrop blur canvas object.

func (*BackdropBlur) Hide

func (b *BackdropBlur) Hide()

Hide will set this backdrop blur to not be visible.

func (*BackdropBlur) MinSize

func (b *BackdropBlur) MinSize() geo.Size

MinSize returns the minimum size — backdrop blur has no inherent size.

func (*BackdropBlur) Move

func (b *BackdropBlur) Move(pos geo.Position)

Move the backdrop blur to a new position, relative to its parent.

func (*BackdropBlur) Position

func (o *BackdropBlur) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*BackdropBlur) Refresh

func (b *BackdropBlur) Refresh()

Refresh marks this backdrop blur for re-capture on the next frame.

func (*BackdropBlur) Resize

func (b *BackdropBlur) Resize(s geo.Size)

Resize sets a new size for the backdrop blur.

func (*BackdropBlur) SetMinSize

func (o *BackdropBlur) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*BackdropBlur) SetTransform

func (o *BackdropBlur) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*BackdropBlur) Show

func (o *BackdropBlur) Show()

Show will set this object to be visible.

func (*BackdropBlur) Size

func (o *BackdropBlur) Size() geo.Size

Size returns the current size of this canvas object.

func (*BackdropBlur) Transform

func (o *BackdropBlur) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*BackdropBlur) Visible

func (o *BackdropBlur) Visible() bool

Visible returns true if this object is visible, false otherwise.

type BoxShadow

type BoxShadow struct {

	// Color is the shadow base color (typically black with some alpha).
	Color color.Color

	// BlurRadius is the blur radius in logical pixels, as in CSS box-shadow:
	// the shadow is blurred by a Gaussian of sigma BlurRadius/2, so its edge
	// fades over about BlurRadius either side. Larger values produce softer,
	// more spread-out shadows.
	BlurRadius float32

	// OffsetX and OffsetY shift the shadow relative to the widget.
	OffsetX, OffsetY float32

	// CornerRadius matches the parent widget's corner rounding.
	CornerRadius float32
	// contains filtered or unexported fields
}

BoxShadow is a canvas object that renders a blurred shadow behind a widget. When the GL painter supports FBO blur, this produces a soft Gaussian-blurred shadow. On software painters or when FBO is unavailable, it falls back to a solid colored rectangle with reduced opacity.

func NewBoxShadow

func NewBoxShadow(c color.Color, blurRadius float32) *BoxShadow

NewBoxShadow creates a new box shadow with the given color and blur radius.

func (*BoxShadow) Hide

func (s *BoxShadow) Hide()

Hide will set this shadow to not be visible.

func (*BoxShadow) MinSize

func (o *BoxShadow) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*BoxShadow) Move

func (s *BoxShadow) Move(pos geo.Position)

Move the shadow to a new position, relative to its parent.

func (*BoxShadow) Position

func (o *BoxShadow) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*BoxShadow) Refresh

func (s *BoxShadow) Refresh()

Refresh causes this shadow to be redrawn.

func (*BoxShadow) Resize

func (s *BoxShadow) Resize(size geo.Size)

Resize sets a new size for the shadow.

func (*BoxShadow) SetMinSize

func (o *BoxShadow) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*BoxShadow) SetTransform

func (o *BoxShadow) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*BoxShadow) Show

func (o *BoxShadow) Show()

Show will set this object to be visible.

func (*BoxShadow) Size

func (o *BoxShadow) Size() geo.Size

Size returns the current size of this canvas object.

func (*BoxShadow) Transform

func (o *BoxShadow) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*BoxShadow) Visible

func (o *BoxShadow) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Camera3D

type Camera3D struct {
	Position Vec3    // camera position in world space
	Target   Vec3    // point the camera looks at
	Up       Vec3    // up direction (usually {0, 1, 0})
	FOV      float32 // field of view in degrees (default 45)
	Near     float32 // near clipping plane (default 0.1)
	Far      float32 // far clipping plane (default 1000)
}

Camera3D defines the viewpoint for a 3D scene.

func DefaultCamera

func DefaultCamera() Camera3D

DefaultCamera returns a camera with sensible defaults.

type Circle

type Circle struct {
	Position1 geo.Position // The current top-left position of the Circle
	Position2 geo.Position // The current bottomright position of the Circle
	Hidden    bool         // Is this circle currently hidden

	FillColor   color.Color // The circle fill color
	StrokeColor color.Color // The circle stroke color
	StrokeWidth float32     // The stroke width of the circle
	// contains filtered or unexported fields
}

Circle describes a colored circle primitive in a Bellui canvas

func NewCircle

func NewCircle(color color.Color) *Circle

NewCircle returns a new Circle instance

func (*Circle) Hide

func (c *Circle) Hide()

Hide will set this circle to not be visible

func (*Circle) MinSize

func (c *Circle) MinSize() geo.Size

MinSize for a Circle simply returns Size{1, 1} as there is no explicit content

func (*Circle) Move

func (c *Circle) Move(pos geo.Position)

Move the circle object to a new position, relative to its parent / canvas

func (*Circle) Position

func (c *Circle) Position() geo.Position

Position gets the current top-left position of this circle object, relative to its parent / canvas

func (*Circle) Refresh

func (c *Circle) Refresh()

Refresh causes this object to be redrawn with its configured state.

func (*Circle) Resize

func (c *Circle) Resize(size geo.Size)

Resize sets a new bottom-right position for the circle object If it has a stroke width this will cause it to Refresh.

func (*Circle) SetTransform

func (c *Circle) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this circle. Use geo.Identity to clear the transform.

func (*Circle) Show

func (c *Circle) Show()

Show will set this circle to be visible

func (*Circle) Size

func (c *Circle) Size() geo.Size

Size returns the current size of bounding box for this circle object

func (*Circle) Transform

func (c *Circle) Transform() geo.Matrix

Transform returns the local affine transform of this circle. If no transform has been set, it returns the identity matrix.

func (*Circle) Visible

func (c *Circle) Visible() bool

Visible returns true if this circle is visible, false otherwise

type Face

type Face struct {
	A, B, C int // indices into Mesh3D.Vertices
}

Face defines a triangle by three vertex indices.

type FillRule

type FillRule uint8

FillRule defines how the interior of a path is determined.

const (
	// FillRuleWinding uses the non-zero winding rule (default).
	FillRuleWinding FillRule = iota
	// FillRuleEvenOdd uses the even-odd rule.
	FillRuleEvenOdd
)

type GLAttribute

type GLAttribute int32

GL handle types — thin wrappers over the underlying integer types used by OpenGL.

Experimental: these, GLContext, GLView and the GL_* constants below are not covered by the compatibility promise and may change or be removed. See GLView for why.

type GLBuffer

type GLBuffer uint32

GL handle types — thin wrappers over the underlying integer types used by OpenGL.

Experimental: these, GLContext, GLView and the GL_* constants below are not covered by the compatibility promise and may change or be removed. See GLView for why.

type GLContext

type GLContext interface {
	// Texture operations
	CreateTexture() GLTexture
	DeleteTexture(texture GLTexture)
	ActiveTexture(textureUnit uint32)
	BindTexture(target uint32, texture GLTexture)
	TexImage2D(target uint32, level, width, height int, colorFormat, typ uint32, data []uint8)
	TexSubImage2D(target uint32, level, x, y, width, height int, colorFormat, typ uint32, data []uint8)
	TexParameteri(target, param uint32, value int32)

	// Buffer operations
	CreateBuffer() GLBuffer
	DeleteBuffer(buffer GLBuffer)
	BindBuffer(target uint32, buf GLBuffer)
	BufferData(target uint32, points []float32, usage uint32)
	BufferSubData(target uint32, points []float32)

	// Shader operations
	CreateShader(typ uint32) GLShader
	CompileShader(shader GLShader)
	ShaderSource(shader GLShader, source string)
	GetShaderi(shader GLShader, param uint32) int
	GetShaderInfoLog(shader GLShader) string

	// Program operations
	CreateProgram() GLProgram
	AttachShader(program GLProgram, shader GLShader)
	LinkProgram(program GLProgram)
	GetProgrami(program GLProgram, param uint32) int
	GetProgramInfoLog(program GLProgram) string
	UseProgram(program GLProgram)

	// Vertex attributes
	GetAttribLocation(program GLProgram, name string) GLAttribute
	EnableVertexAttribArray(attribute GLAttribute)
	VertexAttribPointerWithOffset(attribute GLAttribute, size int, typ uint32, normalized bool, stride, offset int)

	// Uniforms
	GetUniformLocation(program GLProgram, name string) GLUniform
	Uniform1f(uniform GLUniform, v float32)
	Uniform2f(uniform GLUniform, v0, v1 float32)
	Uniform3f(uniform GLUniform, v0, v1, v2 float32)
	Uniform4f(uniform GLUniform, v0, v1, v2, v3 float32)
	UniformMatrix3fv(uniform GLUniform, value [9]float32)
	UniformMatrix4fv(uniform GLUniform, value [16]float32)

	// Drawing
	DrawArrays(mode uint32, first, count int)
	Viewport(x, y, width, height int)
	Clear(mask uint32)
	ClearColor(r, g, b, a float32)

	// Blending
	BlendFunc(srcFactor, destFactor uint32)
	BlendColor(r, g, b, a float32)

	// Clipping
	Scissor(x, y, w, h int32)
	Enable(capability uint32)
	Disable(capability uint32)

	// Framebuffer objects
	CreateFramebuffer() GLFramebuffer
	DeleteFramebuffer(fb GLFramebuffer)
	BindFramebuffer(target uint32, fb GLFramebuffer)
	FramebufferTexture2D(target, attachment uint32, texture GLTexture, level int32)
	CheckFramebufferStatus(target uint32) uint32

	// Stencil
	ClearStencil(s int32)
	StencilFunc(fn uint32, ref int32, mask uint32)
	StencilOp(sfail, dpfail, dppass uint32)
	StencilMask(mask uint32)
	ColorMask(r, g, b, a bool)

	// Pixel readback
	ReadBuffer(src uint32)
	ReadPixels(x, y, width, height int, colorFormat, typ uint32, pixels []uint8)

	// Error
	GetError() uint32
}

GLContext provides access to OpenGL operations during a GLView render callback. It is only valid for the duration of the callback — do not store references.

Experimental: not covered by the compatibility promise and may change or be removed. This interface is the largest part of that promise — sixty-odd methods mirroring the OpenGL API — and it can only ever be implemented by a painter that has an OpenGL context. See GLView.

type GLFramebuffer

type GLFramebuffer uint32

GL handle types — thin wrappers over the underlying integer types used by OpenGL.

Experimental: these, GLContext, GLView and the GL_* constants below are not covered by the compatibility promise and may change or be removed. See GLView for why.

type GLProgram

type GLProgram uint32

GL handle types — thin wrappers over the underlying integer types used by OpenGL.

Experimental: these, GLContext, GLView and the GL_* constants below are not covered by the compatibility promise and may change or be removed. See GLView for why.

type GLShader

type GLShader uint32

GL handle types — thin wrappers over the underlying integer types used by OpenGL.

Experimental: these, GLContext, GLView and the GL_* constants below are not covered by the compatibility promise and may change or be removed. See GLView for why.

type GLTexture

type GLTexture uint32

GL handle types — thin wrappers over the underlying integer types used by OpenGL.

Experimental: these, GLContext, GLView and the GL_* constants below are not covered by the compatibility promise and may change or be removed. See GLView for why.

type GLUniform

type GLUniform int32

GL handle types — thin wrappers over the underlying integer types used by OpenGL.

Experimental: these, GLContext, GLView and the GL_* constants below are not covered by the compatibility promise and may change or be removed. See GLView for why.

type GLView

type GLView struct {

	// Render is called on the GL thread during each paint. The viewport
	// is pre-configured to this view's screen area. The context is only
	// valid for the duration of the callback.
	Render func(ctx GLContext, width, height int, pixelScale float32)
	// contains filtered or unexported fields
}

GLView is a canvas object that renders custom OpenGL content. The Render callback is invoked on the GL thread during the paint phase with the viewport set to the view's pixel bounds. The callback receives a GLContext for issuing GL commands, the pixel dimensions, and the display scale factor.

GLView requires the GL painter

It hands the application a live OpenGL context and lets it draw into the window's GL framebuffer, so it only works under the GL painter — built with -tags gl, and the default on targets that have no WebGPU backend. The WebGPU painter, which is the default on desktop, has no OpenGL context to hand out: a GLView placed there draws nothing and reports why, once, to the error log (#213).

For GPU-drawn content that works under every painter, use Scene3D: it describes meshes, a camera and lights declaratively rather than issuing GL calls, and every painter can draw it.

Experimental

GLView, GLContext, the GL handle types and the GL_* constants are **not covered by the compatibility promise** and may change or be removed.

The reason is above: this is an escape hatch bound to one painter, and the painter it is bound to is not the default. Promising its shape would freeze GLContext's sixty-odd methods for the life of the major version, in exchange for an API that a default-configured app cannot use. A portable custom-draw surface is the intended replacement if a consumer needs one; until then Scene3D, a streaming Raster and the built-in GPU effects cover the ground between them.

func NewGLView

func NewGLView(render func(ctx GLContext, width, height int, pixelScale float32)) *GLView

NewGLView creates a new GLView with the given render callback.

Experimental: see GLView.

func (*GLView) Hide

func (v *GLView) Hide()

Hide will set this view to not be visible.

func (*GLView) MinSize

func (o *GLView) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*GLView) Move

func (v *GLView) Move(pos geo.Position)

Move the view to a new position, relative to its parent / canvas.

func (*GLView) Position

func (o *GLView) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*GLView) Refresh

func (v *GLView) Refresh()

Refresh causes this view to be redrawn.

func (*GLView) Resize

func (v *GLView) Resize(s geo.Size)

Resize sets the view's size and triggers a refresh.

func (*GLView) SetMinSize

func (o *GLView) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*GLView) SetTransform

func (o *GLView) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*GLView) Show

func (o *GLView) Show()

Show will set this object to be visible.

func (*GLView) Size

func (o *GLView) Size() geo.Size

Size returns the current size of this canvas object.

func (*GLView) Transform

func (o *GLView) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*GLView) Visible

func (o *GLView) Visible() bool

Visible returns true if this object is visible, false otherwise.

type GradientStop

type GradientStop struct {
	Color    color.Color
	Position float64 // 0.0–1.0
}

GradientStop defines a color at a specific position in a multi-stop gradient.

type Image

type Image struct {

	// one of the following sources will provide our image data
	File     string          // Load the image from a file
	Resource bellui.Resource // Load the image from an in-memory resource
	Image    image.Image     // Specify a loaded image to use in this canvas object

	Translucency float64    // Set a translucency value > 0.0 to fade the image
	FillMode     ImageFill  // Specify how the image should expand to fill or fit the available space
	ScaleMode    ImageScale // Specify the type of scaling interpolation applied to the image

	// CornerRadius specifies a radius to apply to round corners of the image.
	//
	// Since: 1.0
	CornerRadius float32
	// contains filtered or unexported fields
}

Image describes a drawable image area that can render in a Bellui canvas The image may be a vector or a bitmap representation, it will fill the area. The fill mode can be changed by setting FillMode to a different ImageFill.

func NewImageFromFile

func NewImageFromFile(file string) *Image

NewImageFromFile creates a new image from a local file. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

func NewImageFromImage

func NewImageFromImage(img image.Image) *Image

NewImageFromImage returns a new Image instance that is rendered from the Go image.Image passed in. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

func NewImageFromReader

func NewImageFromReader(read io.Reader, name string) *Image

NewImageFromReader creates a new image from a data stream. The name parameter is required to uniquely identify this image (for caching etc.). If the image in this io.Reader is an SVG, the name should end ".svg". Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

Since: 1.0

func NewImageFromResource

func NewImageFromResource(res bellui.Resource) *Image

NewImageFromResource creates a new image by loading the specified resource. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

func NewImageFromURI

func NewImageFromURI(uri bellui.URI) *Image

NewImageFromURI creates a new image from named resource. File URIs will read the file path and other schemes will download the data into a resource. HTTP and HTTPs URIs will use the GET method by default to request the resource. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

Since: 1.0

func (*Image) Alpha

func (i *Image) Alpha() float64

Alpha is a convenience function that returns the alpha value for an image based on its Translucency value. The result is 1.0 - Translucency.

func (*Image) Aspect

func (i *Image) Aspect() float32

Aspect will return the original content aspect after it was last refreshed. Aspect is safe for concurrent use.

Since: 1.0

func (*Image) Hide

func (i *Image) Hide()

Hide will set this image to not be visible

func (*Image) MinSize

func (i *Image) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Image) Move

func (i *Image) Move(pos geo.Position)

Move the image object to a new position, relative to its parent top, left corner.

func (*Image) Position

func (o *Image) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Image) Refresh

func (i *Image) Refresh()

Refresh causes this image to be redrawn with its configured state.

func (*Image) Resize

func (i *Image) Resize(s geo.Size)

Resize on an image will scale the content or reposition it according to FillMode. It will normally cause a Refresh to ensure the pixels are recalculated.

func (*Image) SetMinSize

func (o *Image) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Image) SetTransform

func (o *Image) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Image) Show

func (o *Image) Show()

Show will set this object to be visible.

func (*Image) Size

func (o *Image) Size() geo.Size

Size returns the current size of this canvas object.

func (*Image) Transform

func (o *Image) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Image) Visible

func (o *Image) Visible() bool

Visible returns true if this object is visible, false otherwise.

type ImageFill

type ImageFill int

ImageFill defines the different type of ways an image can stretch to fill its space.

const (
	// ImageFillStretch will scale the image to match the Size() values.
	// This is the default and does not maintain aspect ratio.
	ImageFillStretch ImageFill = iota
	// ImageFillContain makes the image fit within the object Size(),
	// centrally and maintaining aspect ratio.
	// There may be transparent sections top and bottom or left and right.
	ImageFillContain // (Fit)
	// ImageFillOriginal ensures that the container grows to the pixel dimensions
	// required to fit the original image. The aspect of the image will be maintained so,
	// as with ImageFillContain there may be transparent areas around the image.
	// Note that the minSize may be smaller than the image dimensions if scale > 1.
	ImageFillOriginal

	// ImageFillCover maintains the image aspect ratio whilst filling the space.
	// The image content will be centered on the available space meaning that an equal amount of top and bottom
	// or left and right will be clipped if the output aspect ratio does not match the source image.
	// Since: 1.0
	ImageFillCover
)

type ImageScale

type ImageScale int32

ImageScale defines the different scaling filters used to scaling images

const (
	// ImageScaleSmooth will scale the image using ApproxBiLinear filter (or GL equivalent)
	ImageScaleSmooth ImageScale = iota
	// ImageScalePixels will scale the image using NearestNeighbor filter (or GL equivalent)
	ImageScalePixels
	// ImageScaleFastest will scale the image using hardware GPU if available
	//
	// Since: 1.0
	ImageScaleFastest
)

type Keyframe

type Keyframe struct {
	Progress float32               // 0.0 to 1.0
	Value    float32               // value at this keyframe
	Curve    bellui.AnimationCurve // easing from previous keyframe to this one; nil = linear
}

Keyframe defines a value at a specific point in an animation's progress. The Curve field specifies the easing from the previous keyframe to this one; nil means linear interpolation for that segment.

type Light3D

type Light3D struct {
	Direction Vec3        // light direction (normalized)
	Color     color.Color // light color
	Ambient   float32     // ambient factor [0, 1]
}

Light3D defines a directional light source.

func DefaultLight

func DefaultLight() Light3D

DefaultLight returns a light with sensible defaults.

type Line

type Line struct {
	Position1 geo.Position // The current top-left position of the Line
	Position2 geo.Position // The current bottom-right position of the Line
	Hidden    bool         // Is this Line currently hidden

	StrokeColor color.Color // The line stroke color
	StrokeWidth float32     // The stroke width of the line
	// contains filtered or unexported fields
}

Line describes a colored line primitive in a Bellui canvas. Lines are special as they can have a negative width or height to indicate an inverse slope (i.e. slope up vs down).

func NewLine

func NewLine(color color.Color) *Line

NewLine returns a new Line instance

func (*Line) Hide

func (l *Line) Hide()

Hide will set this line to not be visible

func (*Line) MinSize

func (l *Line) MinSize() geo.Size

MinSize for a Line simply returns Size{1, 1} as there is no explicit content

func (*Line) Move

func (l *Line) Move(pos geo.Position)

Move the line object to a new position, relative to its parent / canvas

func (*Line) Position

func (l *Line) Position() geo.Position

Position gets the current top-left position of this line object, relative to its parent / canvas

func (*Line) Refresh

func (l *Line) Refresh()

Refresh causes this line to be redrawn with its configured state.

func (*Line) Resize

func (l *Line) Resize(size geo.Size)

Resize sets a new bottom-right position for the line object, then it will then be refreshed.

func (*Line) SetTransform

func (l *Line) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this line. Use geo.Identity to clear the transform.

func (*Line) Show

func (l *Line) Show()

Show will set this line to be visible

func (*Line) Size

func (l *Line) Size() geo.Size

Size returns the current size of bounding box for this line object

func (*Line) Transform

func (l *Line) Transform() geo.Matrix

Transform returns the local affine transform of this line. If no transform has been set, it returns the identity matrix.

func (*Line) Visible

func (l *Line) Visible() bool

Visible returns true if this line is visible, false otherwise

type LineCap

type LineCap uint8

LineCap defines the shape at the endpoints of an open path stroke.

const (
	// LineCapButt ends the stroke flush at the endpoint (default).
	LineCapButt LineCap = iota
	// LineCapRound ends the stroke with a semicircle at the endpoint.
	LineCapRound
	// LineCapSquare ends the stroke with a half-square at the endpoint.
	LineCapSquare
)

type LineJoin

type LineJoin uint8

LineJoin defines the shape at the junction of two path segments.

const (
	// LineJoinMiter joins segments with a sharp point (default).
	LineJoinMiter LineJoin = iota
	// LineJoinRound joins segments with a circular arc.
	LineJoinRound
	// LineJoinBevel joins segments with a flat cut.
	LineJoinBevel
)

type LinearGradient

type LinearGradient struct {
	StartColor color.Color // The beginning color of the gradient
	EndColor   color.Color // The end color of the gradient
	Angle      float64     // The angle of the gradient (0/180 for vertical; 90/270 for horizontal)
	// Stops defines a multi-stop gradient. When non-empty, StartColor and EndColor are ignored.
	// Stops must be sorted by Position (0.0 to 1.0).
	Stops []GradientStop
	// contains filtered or unexported fields
}

LinearGradient defines a Gradient travelling straight at a given angle. The only supported values for the angle are `0.0` (vertical) and `90.0` (horizontal), currently.

func NewHorizontalGradient

func NewHorizontalGradient(start, end color.Color) *LinearGradient

NewHorizontalGradient creates a new horizontally travelling linear gradient. The start color will be at the left of the gradient and the end color will be at the right.

func NewLinearGradient

func NewLinearGradient(start, end color.Color, angle float64) *LinearGradient

NewLinearGradient creates a linear gradient at the specified angle. The angle parameter is the degree angle along which the gradient is calculated. A NewHorizontalGradient uses 270 degrees and NewVerticalGradient is 0 degrees.

func NewVerticalGradient

func NewVerticalGradient(start color.Color, end color.Color) *LinearGradient

NewVerticalGradient creates a new vertically travelling linear gradient. The start color will be at the top of the gradient and the end color will be at the bottom.

func (*LinearGradient) Generate

func (g *LinearGradient) Generate(iw, ih int) image.Image

Generate calculates an image of the gradient with the specified width and height.

func (*LinearGradient) Hide

func (g *LinearGradient) Hide()

Hide will set this gradient to not be visible

func (*LinearGradient) MinSize

func (o *LinearGradient) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*LinearGradient) Move

func (g *LinearGradient) Move(pos geo.Position)

Move the gradient to a new position, relative to its parent / canvas

func (*LinearGradient) Position

func (o *LinearGradient) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*LinearGradient) Refresh

func (g *LinearGradient) Refresh()

Refresh causes this gradient to be redrawn with its configured state.

func (*LinearGradient) Resize

func (g *LinearGradient) Resize(size geo.Size)

Resize resizes the gradient to a new size.

func (*LinearGradient) SetMinSize

func (o *LinearGradient) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*LinearGradient) SetTransform

func (o *LinearGradient) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*LinearGradient) Show

func (o *LinearGradient) Show()

Show will set this object to be visible.

func (*LinearGradient) Size

func (o *LinearGradient) Size() geo.Size

Size returns the current size of this canvas object.

func (*LinearGradient) Transform

func (o *LinearGradient) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*LinearGradient) Visible

func (o *LinearGradient) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Mat4

type Mat4 [16]float32

Mat4 is a 4x4 matrix in column-major order.

func LookAtMatrix

func LookAtMatrix(eye, center, up Vec3) Mat4

LookAtMatrix builds a view matrix from eye position, center/target, and up vector.

func PerspectiveMatrix

func PerspectiveMatrix(fovDeg, aspect, near, far float32) Mat4

PerspectiveMatrix builds a perspective projection matrix. fovDeg is the vertical field of view in degrees, aspect is width/height.

func (Mat4) Mul

func (m Mat4) Mul(b Mat4) Mat4

Mul multiplies two 4x4 matrices.

func (Mat4) MulVec3

func (m Mat4) MulVec3(v Vec3) Vec3

MulVec3 transforms a Vec3 by this matrix (assumes w=1, performs perspective divide).

type Mesh3D

type Mesh3D struct {
	Vertices  []Vec3
	Faces     []Face
	FillColor color.Color

	// FaceColors overrides FillColor per-face (if len matches Faces).
	FaceColors []color.Color
}

Mesh3D defines a 3D mesh with vertices, faces, and colors.

type OrbitCamera

type OrbitCamera struct {
	Target   Vec3    // point to orbit around
	Distance float32 // distance from target
	Theta    float32 // horizontal angle in radians (azimuth)
	Phi      float32 // vertical angle in radians (elevation), clamped to avoid poles
	Up       Vec3

	// MinDistance and MaxDistance bound [OrbitCamera.Zoom]. Either left at or
	// below zero falls back to its default — 0.5 and 100 respectively — so a
	// zero-value OrbitCamera zooms exactly as it always has. Set them for a
	// scene authored at a different scale, where the defaults would snap the
	// camera to a limit on the first zoom.
	MinDistance float32
	MaxDistance float32
}

OrbitCamera provides orbit controls for a Camera3D: rotate around a target and zoom in/out by changing the distance.

func NewOrbitCamera

func NewOrbitCamera(cam Camera3D) *OrbitCamera

NewOrbitCamera creates an OrbitCamera from a Camera3D position and target.

A camera positioned outside the default zoom range gets limits scaled to its own distance, so orbiting a large or a miniature scene does not yank the camera to a limit the moment the user zooms.

func (*OrbitCamera) Camera

func (o *OrbitCamera) Camera(fov, near, far float32) Camera3D

Camera returns the Camera3D corresponding to the current orbit state.

Non-positive fov, near and far resolve to defaults; the near default scales with the orbit distance in both directions, while the far default only grows with it. Callers that feed a resolved Near or Far back into the next call freeze that default at its first value — keep passing zero (or an explicit choice) to let it track the zoom.

func (*OrbitCamera) Rotate

func (o *OrbitCamera) Rotate(dTheta, dPhi float32)

Rotate adjusts the orbit angles by the given deltas (in radians).

func (*OrbitCamera) Zoom

func (o *OrbitCamera) Zoom(factor float32)

Zoom changes the distance from the target by a factor, bounded by OrbitCamera.MinDistance and OrbitCamera.MaxDistance. factor > 1 zooms out, factor < 1 zooms in.

type Path

type Path struct {
	FillColor   color.Color // The path fill color
	FillRule    FillRule    // The fill rule (even-odd or winding)
	StrokeColor color.Color // The path stroke color
	StrokeWidth float32     // The stroke width
	LineCap     LineCap     // The stroke cap style
	LineJoin    LineJoin    // The stroke join style
	MiterLimit  float32     // The miter limit for miter joins (0 uses default of 4)
	DashPattern []float32   // The stroke dash pattern (alternating dash/gap lengths)
	DashOffset  float32     // The starting offset into the dash pattern
	// contains filtered or unexported fields
}

Path describes an arbitrary 2D vector path in a Bellui canvas. It supports fill, stroke with configurable width/caps/joins/dashes, and is rendered through the GPU pipeline.

func NewPath

func NewPath(build func(*Path)) *Path

NewPath creates a new Path and calls the build function to construct it.

func (*Path) Bounds

func (p *Path) Bounds() (minX, minY, maxX, maxY float32)

Bounds returns the axis-aligned bounding box of the path's control points as (minX, minY, maxX, maxY) in path-local coordinates.

func (*Path) Close

func (p *Path) Close()

Close closes the current subpath by drawing a straight line back to the starting point of the subpath.

func (*Path) CubicTo

func (p *Path) CubicTo(cx1, cy1, cx2, cy2, x, y float32)

CubicTo adds a cubic Bezier curve from the current point, with control points (cx1, cy1), (cx2, cy2) and endpoint (x, y).

func (*Path) Elements

func (p *Path) Elements() []PathElement

Elements returns the path elements. The returned slice must not be modified.

func (*Path) Hide

func (p *Path) Hide()

Hide will set this path to not be visible.

func (*Path) LineTo

func (p *Path) LineTo(x, y float32)

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

func (*Path) MinSize

func (o *Path) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Path) Move

func (p *Path) Move(pos geo.Position)

Move the path to a new position, relative to its parent / canvas.

func (*Path) MoveTo

func (p *Path) MoveTo(x, y float32)

MoveTo begins a new subpath at the given point.

func (*Path) Position

func (o *Path) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Path) QuadTo

func (p *Path) QuadTo(cx, cy, x, y float32)

QuadTo adds a quadratic Bezier curve from the current point, with control point (cx, cy) and endpoint (x, y).

func (*Path) Refresh

func (p *Path) Refresh()

Refresh causes this path to be redrawn with its configured state.

func (*Path) Reset

func (p *Path) Reset()

Reset clears all path commands, restoring the path to an empty state.

func (*Path) Resize

func (p *Path) Resize(s geo.Size)

Resize on a path updates the size of this object.

func (*Path) SetMinSize

func (o *Path) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Path) SetTransform

func (o *Path) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Path) Show

func (o *Path) Show()

Show will set this object to be visible.

func (*Path) Size

func (o *Path) Size() geo.Size

Size returns the current size of this canvas object.

func (*Path) Transform

func (o *Path) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Path) Visible

func (o *Path) Visible() bool

Visible returns true if this object is visible, false otherwise.

type PathCommand

type PathCommand uint8

PathCommand identifies a path drawing command.

const (
	// PathMoveTo begins a new subpath at the given point.
	PathMoveTo PathCommand = iota
	// PathLineTo adds a straight line from the current point.
	PathLineTo
	// PathQuadTo adds a quadratic Bezier curve from the current point.
	PathQuadTo
	// PathCubicTo adds a cubic Bezier curve from the current point.
	PathCubicTo
	// PathClose closes the current subpath with a straight line back to the start.
	PathClose
)

type PathElement

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

PathElement stores a single path command with its control points.

func (PathElement) Cmd

func (e PathElement) Cmd() PathCommand

Cmd returns the path command.

func (PathElement) Point

func (e PathElement) Point(i int) geo.Position

Point returns the i-th control point (0, 1, or 2).

type Polygon

type Polygon struct {
	FillColor    color.Color // The polygon fill color
	StrokeColor  color.Color // The polygon stroke color
	StrokeWidth  float32     // The stroke width of the polygon
	CornerRadius float32     // The radius of the polygon corners
	Angle        float32     // Angle of polygon, in degrees (positive means clockwise, negative means counter-clockwise direction).
	Sides        uint        //	Amount of sides of polygon.
	// contains filtered or unexported fields
}

Polygon describes a colored regular polygon primitive in a Bellui canvas. The rendered portion will be in the center of the available space.

Since: 1.0

func NewPolygon

func NewPolygon(sides uint, color color.Color) *Polygon

NewPolygon returns a new Polygon instance

func (*Polygon) Hide

func (r *Polygon) Hide()

Hide will set this polygon to not be visible

func (*Polygon) MinSize

func (o *Polygon) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Polygon) Move

func (r *Polygon) Move(pos geo.Position)

Move the polygon to a new position, relative to its parent / canvas

func (*Polygon) Position

func (o *Polygon) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Polygon) Refresh

func (r *Polygon) Refresh()

Refresh causes this polygon to be redrawn with its configured state.

func (*Polygon) Resize

func (r *Polygon) Resize(s geo.Size)

Resize on a polygon updates the new size of this object. If it has a stroke width this will cause it to Refresh.

func (*Polygon) SetMinSize

func (o *Polygon) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Polygon) SetTransform

func (o *Polygon) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Polygon) Show

func (o *Polygon) Show()

Show will set this object to be visible.

func (*Polygon) Size

func (o *Polygon) Size() geo.Size

Size returns the current size of this canvas object.

func (*Polygon) Transform

func (o *Polygon) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Polygon) Visible

func (o *Polygon) Visible() bool

Visible returns true if this object is visible, false otherwise.

type PositionKeyframe

type PositionKeyframe struct {
	Progress float32
	Value    geo.Position
	Curve    bellui.AnimationCurve // easing from previous keyframe to this one; nil = linear
}

PositionKeyframe defines a position at a specific point in an animation's progress.

type RadialGradient

type RadialGradient struct {
	StartColor color.Color // The beginning color of the gradient
	EndColor   color.Color // The end color of the gradient
	// The offset of the center for generation of the gradient.
	// This is not a DP measure but relates to the width/height.
	// A value of 0.5 would move the center by the half width/height.
	CenterOffsetX, CenterOffsetY float64
	// Stops defines a multi-stop gradient. When non-empty, StartColor and EndColor are ignored.
	Stops []GradientStop
	// contains filtered or unexported fields
}

RadialGradient defines a Gradient travelling radially from a center point outward.

func NewRadialGradient

func NewRadialGradient(start, end color.Color) *RadialGradient

NewRadialGradient creates a new radial gradient.

func (*RadialGradient) Generate

func (g *RadialGradient) Generate(iw, ih int) image.Image

Generate calculates an image of the gradient with the specified width and height.

func (*RadialGradient) Hide

func (g *RadialGradient) Hide()

Hide will set this gradient to not be visible

func (*RadialGradient) MinSize

func (o *RadialGradient) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*RadialGradient) Move

func (g *RadialGradient) Move(pos geo.Position)

Move the gradient to a new position, relative to its parent / canvas

func (*RadialGradient) Position

func (o *RadialGradient) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*RadialGradient) Refresh

func (g *RadialGradient) Refresh()

Refresh causes this gradient to be redrawn with its configured state.

func (*RadialGradient) Resize

func (g *RadialGradient) Resize(size geo.Size)

Resize resizes the gradient to a new size.

func (*RadialGradient) SetMinSize

func (o *RadialGradient) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*RadialGradient) SetTransform

func (o *RadialGradient) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*RadialGradient) Show

func (o *RadialGradient) Show()

Show will set this object to be visible.

func (*RadialGradient) Size

func (o *RadialGradient) Size() geo.Size

Size returns the current size of this canvas object.

func (*RadialGradient) Transform

func (o *RadialGradient) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*RadialGradient) Visible

func (o *RadialGradient) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Raster

type Raster struct {

	// Render the raster image from code
	Generator func(w, h int) image.Image

	// Set a translucency value > 0.0 to fade the raster
	Translucency float64
	// Specify the type of scaling interpolation applied to the raster if it is not full-size
	// Since: 1.0
	ScaleMode ImageScale

	// Streaming enables in-place texture updates.
	// When true, Refresh() reuses the existing GPU texture — uploading only the
	// new pixels — instead of deleting and recreating it on every frame. Ideal
	// for video playback. Honoured by the GL and WebGPU painters; the software
	// painter re-draws the current pixels each paint, so Streaming is a no-op
	// there rather than a behaviour change.
	Streaming bool

	// StreamMu protects the streaming pixel fields (StreamPix, StreamPixW,
	// StreamPixH, StreamTexW, StreamTexH) from concurrent access between
	// SetPixels (user goroutine) and the GL painter thread.
	StreamMu sync.Mutex

	// StreamPix holds raw premultiplied-RGBA pixel data set via SetPixels.
	// Read by the painter; do not set directly — use SetPixels.
	StreamPix []byte
	// StreamPixW and StreamPixH are the dimensions of StreamPix data.
	StreamPixW, StreamPixH int

	// StreamTexW and StreamTexH track the allocated GL texture dimensions.
	// Managed by the painter to detect size changes.
	StreamTexW, StreamTexH int
	// contains filtered or unexported fields
}

Raster describes a raster image area that can render in a Bellui canvas

func NewRaster

func NewRaster(generate func(w, h int) image.Image) *Raster

NewRaster returns a new Image instance that is rendered dynamically using the specified generate function. Images returned from this method should draw dynamically to fill the width and height parameters passed to pixelColor.

func NewRasterFromImage

func NewRasterFromImage(img image.Image) *Raster

NewRasterFromImage returns a new Raster instance that is rendered from the Go image.Image passed in. Rasters returned from this method will map pixel for pixel to the screen starting img.Bounds().Min pixels from the top left of the canvas object. Truncates rather than scales the image. If smaller than the target space, the image will be padded with zero-pixels to the target size.

func NewRasterWithPixels

func NewRasterWithPixels(pixelColor func(x, y, w, h int) color.Color) *Raster

NewRasterWithPixels returns a new Image instance that is rendered dynamically by iterating over the specified pixelColor function for each x, y pixel. Images returned from this method should draw dynamically to fill the width and height parameters passed to pixelColor.

func (*Raster) Alpha

func (r *Raster) Alpha() float64

Alpha is a convenience function that returns the alpha value for a raster based on its Translucency value. The result is 1.0 - Translucency.

func (*Raster) Hide

func (r *Raster) Hide()

Hide will set this raster to not be visible

func (*Raster) MinSize

func (o *Raster) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Raster) Move

func (r *Raster) Move(pos geo.Position)

Move the raster to a new position, relative to its parent / canvas

func (*Raster) PixelImage

func (r *Raster) PixelImage(w, h int) image.Image

PixelImage returns the raster's current content at the requested size: the data supplied by Raster.SetPixels when there is any, otherwise the output of Generator. It returns nil when the raster has neither, so painters can skip an empty raster instead of dereferencing a nil Generator.

The pixel data is copied, so the caller may keep the result after the next SetPixels call. Painters with an in-place upload path should read StreamPix under StreamMu directly rather than pay for that copy every frame.

Since: 1.0

func (*Raster) Position

func (o *Raster) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Raster) Refresh

func (r *Raster) Refresh()

Refresh causes this raster to be redrawn with its configured state.

func (*Raster) Resize

func (r *Raster) Resize(s geo.Size)

Resize on a raster image causes the new size to be set and then calls Refresh. This causes the underlying data to be recalculated and a new output to be drawn.

func (*Raster) SetMinSize

func (o *Raster) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Raster) SetPixels

func (r *Raster) SetPixels(pix []byte, width, height int)

SetPixels updates the raster's pixel data directly with raw RGBA bytes. The provided data must be premultiplied RGBA with 4 bytes per pixel, and width*height*4 must equal len(pix). This is the fastest path for video frame updates when Streaming is true. It automatically calls Refresh to trigger a repaint.

A raster driven purely by SetPixels needs no Generator: every painter reads the supplied pixels in preference to it. Until the first SetPixels call such a raster simply has no content and draws nothing.

func (*Raster) SetTransform

func (o *Raster) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Raster) Show

func (o *Raster) Show()

Show will set this object to be visible.

func (*Raster) Size

func (o *Raster) Size() geo.Size

Size returns the current size of this canvas object.

func (*Raster) Transform

func (o *Raster) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Raster) Visible

func (o *Raster) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Rectangle

type Rectangle struct {
	FillColor   color.Color // The rectangle fill color
	StrokeColor color.Color // The rectangle stroke color
	StrokeWidth float32     // The stroke width of the rectangle
	// The radius of the rectangle corners
	//
	// Since: 1.0
	CornerRadius float32

	// Enforce an aspect ratio for the rectangle, the content will be made shorter or narrower
	// to meet the requested aspect, if set.
	//
	// Since: 1.0
	Aspect float32

	// The radius of the rectangle top-right corner only.
	//
	// Since: 1.0
	TopRightCornerRadius float32

	// The radius of the rectangle top-left corner only.
	//
	// Since: 1.0
	TopLeftCornerRadius float32

	// The radius of the rectangle bottom-right corner only.
	//
	// Since: 1.0
	BottomRightCornerRadius float32

	// The radius of the rectangle bottom-left corner only.
	//
	// Since: 1.0
	BottomLeftCornerRadius float32
	// contains filtered or unexported fields
}

Rectangle describes a colored rectangle primitive in a Bellui canvas

func NewRectangle

func NewRectangle(color color.Color) *Rectangle

NewRectangle returns a new Rectangle instance

func NewSquare

func NewSquare(color color.Color) *Rectangle

NewSquare returns a new Rectangle instance that has a square aspect ratio.

Since: 1.0

func (*Rectangle) Hide

func (r *Rectangle) Hide()

Hide will set this rectangle to not be visible

func (*Rectangle) MinSize

func (o *Rectangle) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Rectangle) Move

func (r *Rectangle) Move(pos geo.Position)

Move the rectangle to a new position, relative to its parent / canvas

func (*Rectangle) Position

func (o *Rectangle) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Rectangle) Refresh

func (r *Rectangle) Refresh()

Refresh causes this rectangle to be redrawn with its configured state.

func (*Rectangle) Resize

func (r *Rectangle) Resize(s geo.Size)

Resize on a rectangle updates the new size of this object. If it has a stroke width this will cause it to Refresh. If Aspect is non-zero it may cause the rectangle to be smaller than the requested size.

func (*Rectangle) SetMinSize

func (o *Rectangle) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Rectangle) SetTransform

func (o *Rectangle) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Rectangle) Show

func (o *Rectangle) Show()

Show will set this object to be visible.

func (*Rectangle) Size

func (o *Rectangle) Size() geo.Size

Size returns the current size of this canvas object.

func (*Rectangle) Transform

func (o *Rectangle) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Rectangle) Visible

func (o *Rectangle) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Ripple

type Ripple struct {

	// Center is the ripple origin relative to the widget's top-left.
	Center geo.Position

	// Radius is the current ripple radius in logical pixels (animated).
	Radius float32

	// Color is the ripple overlay color (typically the widget's content color).
	Color color.Color

	// Opacity is the current ripple opacity (0.0–1.0, animated).
	Opacity float32

	// CornerRadius is the corner radius for SDF clipping to the parent shape.
	CornerRadius float32
	// contains filtered or unexported fields
}

Ripple is a canvas object that renders a radial ripple effect from a center point, clipped to a rounded rectangle shape. It is used for MD3-style touch feedback on interactive widgets.

func NewRipple

func NewRipple(c color.Color) *Ripple

NewRipple creates a new ripple canvas object.

func (*Ripple) Hide

func (r *Ripple) Hide()

Hide will set this ripple to not be visible.

func (*Ripple) MinSize

func (o *Ripple) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Ripple) Move

func (r *Ripple) Move(pos geo.Position)

Move the ripple to a new position, relative to its parent.

func (*Ripple) Position

func (o *Ripple) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Ripple) Refresh

func (r *Ripple) Refresh()

Refresh causes this ripple to be redrawn.

func (*Ripple) Resize

func (r *Ripple) Resize(s geo.Size)

Resize sets a new size for the ripple.

func (*Ripple) SetMinSize

func (o *Ripple) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Ripple) SetTransform

func (o *Ripple) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Ripple) Show

func (o *Ripple) Show()

Show will set this object to be visible.

func (*Ripple) Size

func (o *Ripple) Size() geo.Size

Size returns the current size of this canvas object.

func (*Ripple) Transform

func (o *Ripple) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Ripple) Visible

func (o *Ripple) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Scene3D

type Scene3D struct {
	Camera Camera3D
	Meshes []Mesh3D
	Lights []Light3D

	// Background color for the scene (default transparent).
	Background color.Color

	// BackfaceCulling, when true, skips triangles whose normals face away from
	// the camera. When false (default), both sides of every triangle are rendered
	// with correct lighting (normals are flipped toward the viewer).
	BackfaceCulling bool
	// contains filtered or unexported fields
}

Scene3D is a canvas object that renders a 3D scene using software rasterization. It contains meshes, a camera, and lights, and produces a 2D image via perspective projection and z-buffering. It integrates with the Bellui rendering pipeline as a standard CanvasObject.

Since: 1.0

func NewScene3D

func NewScene3D() *Scene3D

NewScene3D creates a Scene3D with a default camera and light.

Since: 1.0

func (*Scene3D) AddAxes

func (s *Scene3D) AddAxes(xCfg, yCfg, zCfg AxisConfig3D)

AddAxes adds X, Y, Z axis lines with tick marks and ground grid to the scene.

func (*Scene3D) AddMesh

func (s *Scene3D) AddMesh(m Mesh3D)

AddMesh adds a mesh to the scene.

func (*Scene3D) Hide

func (s *Scene3D) Hide()

Hide will set this scene to not be visible.

func (*Scene3D) MinSize

func (o *Scene3D) MinSize() geo.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Scene3D) Move

func (s *Scene3D) Move(pos geo.Position)

Move the scene to a new position, relative to its parent / canvas.

func (*Scene3D) Position

func (o *Scene3D) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Scene3D) Refresh

func (s *Scene3D) Refresh()

Refresh causes this scene to be redrawn.

func (*Scene3D) Render

func (s *Scene3D) Render(width, height int) *image.NRGBA

Render produces an NRGBA image of the scene at the given pixel dimensions.

func (*Scene3D) Resize

func (s *Scene3D) Resize(size geo.Size)

Resize updates the size of the scene.

func (*Scene3D) SetMinSize

func (o *Scene3D) SetMinSize(size geo.Size)

SetMinSize specifies the smallest size this object should be.

func (*Scene3D) SetTransform

func (o *Scene3D) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*Scene3D) Show

func (o *Scene3D) Show()

Show will set this object to be visible.

func (*Scene3D) Size

func (o *Scene3D) Size() geo.Size

Size returns the current size of this canvas object.

func (*Scene3D) Transform

func (o *Scene3D) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*Scene3D) Visible

func (o *Scene3D) Visible() bool

Visible returns true if this object is visible, false otherwise.

type SpringConfig

type SpringConfig struct {
	Stiffness   float32       // spring constant (default 170)
	Damping     float32       // damping coefficient (default 26)
	Mass        float32       // mass (default 1)
	MaxDuration time.Duration // safety duration cap (default 2s)
}

SpringConfig configures the physics of a spring animation. Default values are applied for zero fields: Stiffness=170, Damping=26, Mass=1, MaxDuration=2s.

type StaggeredEntry

type StaggeredEntry struct {
	Animation *bellui.Animation
	Delay     time.Duration
}

StaggeredEntry pairs an animation with a start delay for use with NewStaggeredAnimation.

type StyledText

type StyledText struct {
	Alignment bellui.TextAlign // The alignment of the text content

	Color    color.Color // The default text draw color (used when a run's Color is nil)
	TextSize float32     // The default font size (used when a run's TextSize is 0)

	Runs []TextRun // The styled text runs
	// contains filtered or unexported fields
}

StyledText describes multi-styled inline text in a Bellui canvas. Each run can have independent color, size, style, and font. This is a single-line primitive; use widget.RichText for wrapping.

Since: 1.0

func NewStyledText

func NewStyledText(runs []TextRun, defaultColor color.Color) *StyledText

NewStyledText returns a new StyledText with the given runs and default color.

Since: 1.0

func (*StyledText) Hide

func (st *StyledText) Hide()

Hide will set this text to not be visible.

func (*StyledText) MinSize

func (st *StyledText) MinSize() geo.Size

MinSize returns the minimum size of this styled text based on font sizes and content.

func (*StyledText) Move

func (st *StyledText) Move(pos geo.Position)

Move the styled text to a new position, relative to its parent / canvas.

func (*StyledText) Position

func (o *StyledText) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*StyledText) Refresh

func (st *StyledText) Refresh()

Refresh causes this styled text to be redrawn with its configured state.

func (*StyledText) Resize

func (st *StyledText) Resize(s geo.Size)

Resize updates the size of this object.

func (*StyledText) SetMinSize

func (st *StyledText) SetMinSize(geo.Size)

SetMinSize has no effect as the smallest size is based on font sizes and content.

func (*StyledText) SetTransform

func (o *StyledText) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*StyledText) Show

func (o *StyledText) Show()

Show will set this object to be visible.

func (*StyledText) Size

func (o *StyledText) Size() geo.Size

Size returns the current size of this canvas object.

func (*StyledText) Transform

func (o *StyledText) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*StyledText) Visible

func (o *StyledText) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Text

type Text struct {
	Alignment bellui.TextAlign // The alignment of the text content

	Color     color.Color      // The main text draw color
	Text      string           // The string content of this Text
	TextSize  float32          // Size of the text - if the Canvas scale is 1.0 this will be equivalent to point size
	TextStyle bellui.TextStyle // The style of the text content

	// SubPixel disables pixel-grid rounding of the text texture size during
	// GL rendering. Enable this for precise positioning in data-visualization
	// layouts where labels must sit at exact fractional coordinates.
	SubPixel bool

	// FontSource defines a resource that can be used instead of the theme for looking up the font.
	// When a font source is set the `TextStyle` may not be effective, as it will be limited to the styles
	// present in the data provided.
	//
	// Since: 1.0
	FontSource bellui.Resource
	// contains filtered or unexported fields
}

Text describes a text primitive in a Bellui canvas. A text object can have a style set which will apply to the whole string. No formatting or text parsing will be performed

func NewText

func NewText(text string, color color.Color) *Text

NewText returns a new Text implementation

func (*Text) Hide

func (t *Text) Hide()

Hide will set this text to not be visible

func (*Text) MinSize

func (t *Text) MinSize() geo.Size

MinSize returns the minimum size of this text object based on its font size and content. This is normally determined by the render implementation.

The measurement is memoised per object: while Text, TextSize, TextStyle and FontSource are unchanged (and the theme/font caches have not reset) the last result is returned without consulting the driver, so measure-heavy layouts do not re-hash unchanged strings through the global metrics cache (pre-rebrand tracker #923).

func (*Text) MinSizeWithBaseline

func (t *Text) MinSizeWithBaseline() (geo.Size, float32)

MinSizeWithBaseline returns Text.MinSize together with the distance from the top of the text to its baseline, both served from the same per-object measurement memo.

Note that TextStyle is compared as a value: its pointer fields (Weight, LineHeightScale, LetterSpacing) are compared by pointer, so a caller mutating a pointee in place must assign a fresh pointer (or style) for the change to be measured.

Since: 1.0

func (*Text) Move

func (t *Text) Move(pos geo.Position)

Move the text to a new position, relative to its parent / canvas

func (*Text) Position

func (o *Text) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Text) Refresh

func (t *Text) Refresh()

Refresh causes this text to be redrawn with its configured state.

func (*Text) Resize

func (t *Text) Resize(s geo.Size)

Resize on a text updates the new size of this object, which may not result in a visual change, depending on alignment.

func (*Text) Rotation

func (t *Text) Rotation() float32

Rotation returns the rotation angle in degrees set by [SetRotation]. If the transform was set directly via [SetTransform], this returns 0.

func (*Text) SetMinSize

func (t *Text) SetMinSize(geo.Size)

SetMinSize has no effect as the smallest size this canvas object can be is based on its font size and content.

func (*Text) SetRotation

func (t *Text) SetRotation(degrees float32)

SetRotation sets the rotation angle in degrees. The text is rotated around its visual center (half of the un-rotated MinSize). The rotation is recomputed automatically when the text content or size changes.

SetRotation and [SetTransform] are mutually exclusive — calling one clears the effect of the other.

func (*Text) SetTransform

func (t *Text) SetTransform(m geo.Matrix)

SetTransform sets an arbitrary affine transform and clears any rotation previously set via [SetRotation].

func (*Text) Show

func (o *Text) Show()

Show will set this object to be visible.

func (*Text) Size

func (o *Text) Size() geo.Size

Size returns the current size of this canvas object.

func (*Text) Transform

func (t *Text) Transform() geo.Matrix

Transform returns the local affine transform. When a rotation has been set via [SetRotation], the transform is computed lazily from the current text size so the rotation center stays correct as text content changes.

func (*Text) Visible

func (o *Text) Visible() bool

Visible returns true if this object is visible, false otherwise.

type TextOnPath

type TextOnPath struct {
	Color      color.Color      // The text draw color
	Text       string           // The string content
	TextSize   float32          // Font size
	TextStyle  bellui.TextStyle // Style for the text
	FontSource bellui.Resource  // Custom font resource; nil means use theme font

	// Offset is the starting distance along the path where text begins.
	// Default 0 means text starts at the path's first point.
	Offset float32

	// BaselineShift moves glyphs perpendicular to the path direction.
	// Positive values shift upward (away from the path's convex side).
	// Default 0 places the text baseline on the path.
	BaselineShift float32
	// contains filtered or unexported fields
}

TextOnPath describes text that follows a path, with each glyph positioned and rotated along the path's arc length.

Since: 1.0

func NewTextOnPath

func NewTextOnPath(text string, color color.Color, buildPath func(*TextOnPath)) *TextOnPath

NewTextOnPath creates a new TextOnPath and calls the build function to construct the path.

Since: 1.0

func (*TextOnPath) Close

func (t *TextOnPath) Close()

Close closes the current subpath by drawing a straight line back to the starting point of the subpath.

func (*TextOnPath) CubicTo

func (t *TextOnPath) CubicTo(cx1, cy1, cx2, cy2, x, y float32)

CubicTo adds a cubic Bezier curve from the current point, with control points (cx1, cy1), (cx2, cy2) and endpoint (x, y).

func (*TextOnPath) Elements

func (t *TextOnPath) Elements() []PathElement

Elements returns the path elements. The returned slice must not be modified.

func (*TextOnPath) Hide

func (t *TextOnPath) Hide()

Hide will set this text to not be visible.

func (*TextOnPath) LineTo

func (t *TextOnPath) LineTo(x, y float32)

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

func (*TextOnPath) MinSize

func (t *TextOnPath) MinSize() geo.Size

MinSize returns the minimum size based on the path bounds expanded by the text height (glyphs can extend beyond the path due to rotation).

func (*TextOnPath) Move

func (t *TextOnPath) Move(pos geo.Position)

Move the text on path to a new position, relative to its parent / canvas.

func (*TextOnPath) MoveTo

func (t *TextOnPath) MoveTo(x, y float32)

MoveTo begins a new subpath at the given point.

func (*TextOnPath) Position

func (o *TextOnPath) Position() geo.Position

Position gets the current position of this canvas object, relative to its parent.

func (*TextOnPath) QuadTo

func (t *TextOnPath) QuadTo(cx, cy, x, y float32)

QuadTo adds a quadratic Bezier curve from the current point, with control point (cx, cy) and endpoint (x, y).

func (*TextOnPath) Refresh

func (t *TextOnPath) Refresh()

Refresh causes this text on path to be redrawn with its configured state.

func (*TextOnPath) Reset

func (t *TextOnPath) Reset()

Reset clears all path commands.

func (*TextOnPath) Resize

func (t *TextOnPath) Resize(s geo.Size)

Resize updates the size of this object.

func (*TextOnPath) SetMinSize

func (t *TextOnPath) SetMinSize(geo.Size)

SetMinSize has no effect as the smallest size is based on the path and text content.

func (*TextOnPath) SetTransform

func (o *TextOnPath) SetTransform(m geo.Matrix)

SetTransform sets the local affine transform for this object. Use geo.Identity to clear the transform. SetTransform is safe for concurrent use.

func (*TextOnPath) Show

func (o *TextOnPath) Show()

Show will set this object to be visible.

func (*TextOnPath) Size

func (o *TextOnPath) Size() geo.Size

Size returns the current size of this canvas object.

func (*TextOnPath) Transform

func (o *TextOnPath) Transform() geo.Matrix

Transform returns the local affine transform of this object. If no transform has been set, it returns the identity matrix. Transform is safe for concurrent use.

func (*TextOnPath) Visible

func (o *TextOnPath) Visible() bool

Visible returns true if this object is visible, false otherwise.

type TextRun

type TextRun struct {
	Text       string           // The string content of this run
	Color      color.Color      // Color for this run; nil means use StyledText.Color
	TextSize   float32          // Font size for this run; 0 means use StyledText.TextSize
	TextStyle  bellui.TextStyle // Style for this run
	FontSource bellui.Resource  // Custom font resource; nil means use theme font
}

TextRun defines a run of text with its own styling properties. Fields left at their zero value inherit from the parent StyledText.

Since: 1.0

type Vec3

type Vec3 struct {
	X, Y, Z float32
}

Vec3 represents a 3D vector or point.

func (Vec3) Add

func (v Vec3) Add(other Vec3) Vec3

Add returns v + other.

func (Vec3) Cross

func (v Vec3) Cross(other Vec3) Vec3

Cross returns the cross product of v and other.

func (Vec3) Dot

func (v Vec3) Dot(other Vec3) float32

Dot returns the dot product of v and other.

func (Vec3) Length

func (v Vec3) Length() float32

Length returns the magnitude of v.

func (Vec3) Normalize

func (v Vec3) Normalize() Vec3

Normalize returns a unit vector in the direction of v.

func (Vec3) Scale

func (v Vec3) Scale(s float32) Vec3

Scale returns v * s.

func (Vec3) Sub

func (v Vec3) Sub(other Vec3) Vec3

Sub returns v - other.

Jump to

Keyboard shortcuts

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