stream

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: ? 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 stream renders append-only formula updates as stable display transitions.

A Session coalesces rapidly changing source before rendering, retains the latest immutable boxes, and exposes a Transition that moves, resizes, fades, and scales visible commands without rebuilding its path geometry for every animation frame. The package has no UI-framework dependency; hosts walk the sampled commands through their own painter.

Index

Constants

View Source
const (
	// DefaultDuration is the default time newly committed display geometry
	// takes to reach its final layout.
	DefaultDuration = 180 * time.Millisecond
	// DefaultAppearanceStartScale is the default scale of entering commands.
	DefaultAppearanceStartScale float32 = 0.72
)

Variables

View Source
var (
	// ErrInvalidOptions reports unusable stream configuration.
	ErrInvalidOptions = errors.New("stream: invalid options")
	// ErrInvalidTransition reports a nil or malformed display box.
	ErrInvalidTransition = errors.New("stream: invalid transition")
	// ErrInvalidVisitor reports a nil command visitor.
	ErrInvalidVisitor = errors.New("stream: invalid visitor")
)

Functions

This section is empty.

Types

type Command

type Command struct {
	Kind    Kind
	Paint   display.Paint
	Opacity float32
	Bound   geometry.Rect

	Path display.PathTemplate
	At   geometry.Point
	Em   float32

	Rect geometry.Rect
	Snap display.SnapAxis
}

Command is one streamed drawing command in box coordinates.

Path aliases immutable storage in the current Box. Callers must not mutate it or retain it after the Walk callback returns. Opacity ranges from zero to one and multiplies the host-resolved paint color.

type Frame

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

Frame is one immutable committed layout and its transition.

func (*Frame) Animating

func (f *Frame) Animating(at time.Time) bool

Animating reports whether command interpolation is still in progress.

func (*Frame) Box

func (f *Frame) Box() *untie.Box

Box returns the current immutable display box.

func (*Frame) Diagnostics

func (f *Frame) Diagnostics() []untie.Diagnostic

Diagnostics returns the current frame's immutable diagnostic snapshot.

func (*Frame) Result

func (f *Frame) Result() *untie.RenderResult

Result exposes the diagnostics and alternative text for this frame.

func (*Frame) Source

func (f *Frame) Source() string

Source returns the partial formula source rendered by this frame.

func (*Frame) Stage

func (f *Frame) Stage() *untie.Box

Stage returns the stable completed layout, or Box when no target was given.

func (*Frame) Walk

func (f *Frame) Walk(at time.Time, visit func(Command) error) error

Walk samples drawing commands at time at.

type Kind

type Kind uint8

Kind identifies one sampled drawing command.

const (
	// Path fills a shared path template placed by At and Em.
	Path Kind = iota
	// Rule fills Rect.
	Rule
)

type Renderer

type Renderer interface {
	Render(
		context.Context,
		string,
		untie.RenderRequest,
	) (*untie.RenderResult, error)
}

Renderer is the subset of Untie's renderer used by a Session.

type Session

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

Session coalesces source updates into immutable render frames.

Session is caller-owned and must not be used concurrently. The renderer it refers to may be shared concurrently by other sessions.

func NewSession

func NewSession(
	ctx context.Context,
	renderer Renderer,
	options SessionOptions,
) (*Session, error)

NewSession prepares a streaming renderer and an optional completed target stage. The target is rendered once before the first update.

func (*Session) Animating

func (s *Session) Animating(now time.Time) bool

Animating reports whether pending work or command interpolation needs another host frame.

func (*Session) Frame

func (s *Session) Frame() *Frame

Frame returns the latest committed frame.

func (*Session) NextCommitIn

func (s *Session) NextCommitIn(now time.Time) (time.Duration, bool)

NextCommitIn reports how long a host should wait before calling Update again to commit the pending source. The returned duration is zero when a commit is already due. ok is false when no source is pending.

Non-UI hosts can use this with their timer scheduler. MyGo hosts can pass the duration directly to Context.After, which requests a full view rebuild rather than the paint-only frames used for interpolation.

func (*Session) Pending

func (s *Session) Pending() bool

Pending reports whether a newer source is waiting for the next commit.

func (*Session) Update

func (s *Session) Update(
	ctx context.Context,
	source string,
	now time.Time,
) (*Frame, bool, error)

Update offers the latest source and renders it when the previous transition window has elapsed. Repetitive calls during that window coalesce to one layout. changed reports whether a new immutable frame was committed.

type SessionOptions

type SessionOptions struct {
	// Request selects dialect, mode, style, and parse options.
	Request untie.RenderRequest
	// TargetSource, when non-empty, is rendered once and exposed as the
	// session's stable layout stage. Hosts use it to reserve final geometry.
	TargetSource string
	// Transition controls interpolation and partial-source error visibility.
	Transition TransitionOptions
}

SessionOptions configure one formula's streaming renderer.

type Timing

type Timing uint8

Timing selects the interpolation curve for a transition.

const (
	// TimingEaseOutCubic starts quickly and settles gently. It is the default.
	TimingEaseOutCubic Timing = iota
	// TimingEaseInOutCubic accelerates from rest and settles gently.
	TimingEaseInOutCubic
)

type Transition

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

Transition samples the change from one immutable formula layout to another.

func NewTransition

func NewTransition(
	previous, current *untie.Box,
	started time.Time,
	options TransitionOptions,
) (*Transition, error)

NewTransition compares previous and current and prepares a reusable display transition. A nil previous makes every current command enter.

func (*Transition) Animating

func (t *Transition) Animating(at time.Time) bool

Animating reports whether at falls before the transition's final frame.

func (*Transition) Duration

func (t *Transition) Duration() time.Duration

Duration returns the effective transition duration.

func (*Transition) Walk

func (t *Transition) Walk(at time.Time, visit func(Command) error) error

Walk samples commands at time at. Once complete, it walks exactly the visible commands of the current box in their original order.

type TransitionOptions

type TransitionOptions struct {
	// Duration zero uses DefaultDuration. Negative values are invalid.
	Duration time.Duration
	// Timing defaults to TimingEaseOutCubic.
	Timing Timing
	// HideErrors omits error and placeholder paint while source is partial.
	HideErrors bool
	// AppearanceStartScale zero uses DefaultAppearanceStartScale. One keeps
	// entering commands at their final scale while retaining the fade.
	AppearanceStartScale float32
}

TransitionOptions configure display interpolation.

Jump to

Keyboard shortcuts

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