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 ¶
const DefaultCommitInterval = 180 * time.Millisecond
DefaultCommitInterval is the default spacing between accepted source snapshots when SessionOptions.CommitInterval is zero.
Variables ¶
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") // ErrInvalidProgress reports non-finite or out-of-range sampling input. ErrInvalidProgress = errors.New("stream: invalid progress") )
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.
func (*Frame) Diagnostics ¶
func (f *Frame) Diagnostics() []untie.Diagnostic
Diagnostics returns the current frame's immutable diagnostic snapshot.
func (*Frame) Previous ¶ added in v0.5.0
Previous returns the immediately preceding box, or nil for the first frame.
func (*Frame) Result ¶
func (f *Frame) Result() *untie.RenderResult
Result exposes the diagnostics and alternative text for this frame.
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) NextCommitIn ¶
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) 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 commit interval 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
// CommitInterval bounds how often changing source is laid out. Zero uses
// DefaultCommitInterval. Negative values are invalid.
CommitInterval time.Duration
}
SessionOptions configure one formula's streaming renderer.
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) (*Transition, error)
NewTransition compares previous and current and prepares a reusable display transition. A nil previous makes every current command enter.
func (*Transition) Walk ¶
func (t *Transition) Walk( progress, appearanceStartScale float32, visit func(Command) error, ) error
Walk samples commands at normalized progress. appearanceStartScale controls the scale of entering and leaving commands. A progress of one walks exactly the visible commands of the current box in their original order.