Documentation
¶
Overview ¶
Package backend defines the internal native MVP boundary. It neither loads native libraries nor selects a platform implementation when imported.
Index ¶
- Variables
- type Bounds
- type Callbacks
- type CleanupFailure
- type CleanupStep
- type Config
- type ControlState
- type Driver
- type Event
- type EventKind
- type FileChooser
- type FileDialogOptions
- type InputState
- type Kind
- type NodeID
- type Panic
- type Peer
- type Queue
- type TreeBinding
- type TreeChange
- type TreeFailure
- type TreeNode
- type TreeResult
- type TreeTransaction
- type UnsupportedTree
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotRunning = errors.New("backend queue is not running") ErrNilTask = errors.New("backend queue task is nil") )
var ErrTreeUnsupported = errors.New("backend dynamic tree operations are not implemented")
Functions ¶
This section is empty.
Types ¶
type Bounds ¶
type Bounds struct{ X, Y, Width, Height int }
Bounds are logical client coordinates; conversion is backend-owned.
type Callbacks ¶
Callbacks are retained from Init until Close. Failure is an internal, non-panicking hook that immediately stops queue admission and application delivery and records the panic. It must never invoke user code. Adapters latch failure before invoking it, suppress further events, and also return the first captured panic from Run.
type CleanupFailure ¶
CleanupFailure preserves an individual cleanup error or panic with its stack.
func (CleanupFailure) Error ¶
func (e CleanupFailure) Error() string
func (CleanupFailure) Unwrap ¶
func (e CleanupFailure) Unwrap() error
type CleanupStep ¶
CleanupStep is an independent safe release attempt. Unsafe releases (e.g. active native callback roots) must stay owned by the adapter for a safe turn.
type Config ¶
type Config struct {
// Input optionally supplies the logical Edit snapshot for Text. Creation
// preserves text but need not restore its positions and must not steal focus.
Input *InputState
Kind Kind
Parent Peer
Text string
Bounds Bounds
Control ControlState
}
type ControlState ¶
ControlState carries non-text properties through both creation paths. SelectedIndex is zero-based, or -1 when no item is selected.
type Driver ¶
type Driver interface {
// PrepareTree starts a delivery fence and owns hidden attempt resources.
// A non-nil transaction MUST be returned with any error needing rollback
// or cleanup. nil+error certifies no state change and no caller-owned work.
// Call ApplyTree to complete every returned transaction on the UI thread.
PrepareTree(TreeChange) (TreeTransaction, error)
// SnapshotInput reads effective native Edit state without changing it.
// PrepareTree must snapshot all affected input itself before mutation;
// this hook also lets core retain detached state without native types.
SnapshotInput(Peer) (InputState, error)
Init(Callbacks) error
Create(Config) (Peer, error)
Destroy(Peer) error
SetText(Peer, string) error
Text(Peer) (string, error)
Show(Peer) error
// Run services native events and calls dispatch at safe loop turns, never
// inside an event sink or a native operation reentered by an application callback.
// Captured callback panic must be returned as data alongside a native error.
Run(dispatch func() *Panic) (*Panic, error)
// Quit requests exit without destroying resources or invoking application code.
Quit()
// Wake schedules a future loop turn. Safe across goroutines, nonblocking,
// never inline dispatch. Valid after Init succeeds until queue Stop returns.
Wake() error
// Close releases infrastructure after all peers have been attempted; no
// callbacks may reference the Go event sink once Close has returned.
Close() error
}
Driver is implemented separately by gtk4 and win32. Except Wake, every method must run on the pinned UI thread. Methods return native failures as errors. Init may partially allocate: Close must work even after Init fails. The event sink is synchronous and may cause nested native signals; adapters guard every FFI entry using Capture and defer cleanup until Run has returned. See docs/archive/dynamic-tree/backend-contract.md for ownership, readiness, and teardown rules.
type Event ¶
type Event struct {
Kind EventKind
Peer Peer
Text string
Checked bool
SelectedIndex int
// Generation is a routing epoch for dynamic peers; zero is the legacy
// static path. Native signals retain the epoch captured at their origin.
Generation uint64
}
Event contains Go-owned data. Change.Text is a snapshot copied before returning from the native callback. CloseRequest asks the core to begin ordinary stop.
type FileChooser ¶
type FileChooser interface {
ChooseFile(parent Peer, save bool, options FileDialogOptions, done func(string, error)) error
}
FileChooser is an optional Driver capability. A successful request delivers its result asynchronously on the UI thread. The empty path with no error denotes cancellation. Quit abandons any pending result.
type FileDialogOptions ¶
FileDialogOptions are passed to drivers supporting native file selection.
type InputState ¶
InputState uses Unicode scalar offsets, never UTF-8 bytes or UTF-16 units. Anchor and Caret describe the selection's endpoints in the effective Text. Positions must survive retained-peer moves and rollback to the original peer. Recreated peers report actual positions; restoring old positions is deferred. Focused is observed state, not a request to steal focus on attachment.
type NodeID ¶
type NodeID uint64
NodeID identifies a logical component for one tree request, independently of native peer identity. Zero is reserved for the root's external parent.
type Panic ¶
Panic preserves the original value and stack without choosing a public error representation. Native adapters retain this data until their loop returns.
func Capture ¶
func Capture(fn func()) (failure *Panic)
Capture is the outer guard of every Go callback entered through FFI. The adapter must keep ABI return conversion and failure storage non-panicking. No user callback, including a failure handler, may run after Capture returns a failure. Fatal runtime faults and os.Exit cannot be recovered here.
type Peer ¶
type Peer uint64
Peer is a backend-issued identity, not an HWND, GTK pointer, or Go pointer. Zero is invalid (and denotes no parent). IDs must not be reused within a run.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue owns all posted Go work. The native backend only wakes the UI loop. Post and Stop are safe across goroutines. Dispatch runs only on the UI thread, outside an application callback; nested Dispatch calls are ignored. A Queue must not be copied. Its zero value is not ready for use.
func NewQueue ¶
NewQueue requires a nonblocking, thread-safe wake that never dispatches Go work inline and never calls back into this Queue. It must remain valid until Stop returns. A failed wake must not imply that a task has been accepted.
func (*Queue) Dispatch ¶
Dispatch executes queued tasks sequentially. Dequeuing under the same lock as Stop is the start boundary: a selected task is already started even if Stop runs before its first instruction. Panic closes admission and is returned as data, never unwound through a native callback. The caller retains failure and requests loop exit before performing cleanup outside native callbacks.
func (*Queue) Open ¶
func (q *Queue) Open()
Open is called once native preparation is complete; Stop is irreversible.
type TreeBinding ¶
type TreeBinding struct {
ID NodeID
Peer Peer
Generation uint64
Input *InputState
}
TreeBinding is the complete post-operation binding. Detached nodes have no Peer or Generation but retain their effective input state. Every attached binding has a nonzero generation, including when the old peer is reused.
type TreeChange ¶
TreeChange is validated by the core before any native operation. Target is the external parent peer when ToAttached is true, otherwise zero. Nodes contains the whole visual subtree, not the independent ownership graph.
type TreeFailure ¶
type TreeFailure struct {
Cause error
Restore error
Cleanup []CleanupFailure
}
TreeFailure is internal diagnostics, not a promised public error type. Cleanup failure alone does not make an otherwise restored operation fatal.
func ApplyTree ¶
func ApplyTree(d interface {
PrepareTree(TreeChange) (TreeTransaction, error)
}, change TreeChange, publish func(TreeResult), fatal func(*TreeFailure)) *TreeFailure
ApplyTree coordinates the internal boundary only; it neither changes the logical graph nor implements event coalescing. publish must atomically install the prevalidated core graph/bindings/event state and must not panic, fail or call user code. fatal must synchronously close Post/delivery before cleanup, retain the diagnostic pointer (cleanup is appended later), and never panic. No fallible step follows publish: successful retirements stay adapter-owned until safe teardown, whose errors belong to that teardown's diagnostics.
func (*TreeFailure) Error ¶
func (e *TreeFailure) Error() string
func (*TreeFailure) Fatal ¶
func (e *TreeFailure) Fatal() bool
func (*TreeFailure) Unwrap ¶
func (e *TreeFailure) Unwrap() []error
type TreeNode ¶
type TreeNode struct {
ID, Parent NodeID
Peer Peer
Kind Kind
Text string
Bounds Bounds
Input *InputState
Control ControlState
}
TreeNode describes one node in parent-before-child order. Peer is the old peer, or zero for an unmaterialized node. Input is only meaningful for Edit. Parent is zero on the subtree root and otherwise refers to an earlier NodeID.
type TreeResult ¶
type TreeResult struct{ Bindings []TreeBinding }
type TreeTransaction ¶
type TreeTransaction interface {
Commit() (TreeResult, error)
Rollback() error
Cleanup() []CleanupStep
Finish()
}
TreeTransaction owns all attempted resources until Finish. Prepare fences application delivery before any native work. Commit returns only after the entire subtree and guaranteed input state are ready (without paint wait). Text survives recreation; positions are guaranteed only for retained peers. Any Commit failure requires Rollback, even if no mutation appeared to occur. Rollback returning nil certifies the entire old working state is restored; resource-release failures belong to Cleanup, not Rollback. Cleanup returns independent safe release steps for an aborted attempt only. Finish never calls user code or performs fallible physical release: it ends the fence after core publication/rollback and retains unsafe retirements for safe-loop teardown. Failed Rollback latches an irreversible delivery stop; Finish MUST NOT reopen that stop. It is called exactly once, including after failed Prepare. All methods are UI-thread-only. Transactions are single-use, not nestable.
type UnsupportedTree ¶
type UnsupportedTree struct{}
UnsupportedTree is temporary compatibility scaffolding for static adapters. It must be removed when implementing native transactions, never treated as a fallback which provides dynamic behavior.
func (UnsupportedTree) PrepareTree ¶
func (UnsupportedTree) PrepareTree(TreeChange) (TreeTransaction, error)
func (UnsupportedTree) SnapshotInput ¶
func (UnsupportedTree) SnapshotInput(Peer) (InputState, error)