html

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 29 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 html provides retained HTML surfaces and typed components on the scene runtime. It owns DOM, CSS, layout, reconciliation, painting, animation, and form state. The parent ui package adapts these controls to native widgets.

Index

Constants

View Source
const (
	ScrollbarHorizontal uint8 = iota
	ScrollbarVertical
)
View Source
const (
	ScrollbarTrack uint8 = iota
	ScrollbarThumb
	ScrollbarArrowStart
	ScrollbarArrowEnd
)

Variables

This section is empty.

Functions

func Animating

func Animating(world *ecs.World) bool

Animating reports whether an active CSS animation needs another frame.

func ControlByID

func ControlByID(world *ecs.World, owner ecs.Entity, id string) (ecs.Entity, bool)

ControlByID returns the rendered form control for the first matching DOM id in this surface. It reuses the document and render indexes. Before a node is rendered, after replacing the source, or for a non-control match it returns false. Dirty document indexes are refreshed before resolving the id.

func ControlTextColor

func ControlTextColor(world *ecs.World, control ecs.Entity) (graphics.ColorRGBA, bool)

ControlTextColor returns the computed CSS foreground of a generated control.

func ControlTextStyle

func ControlTextStyle(world *ecs.World, control ecs.Entity) (scene.Text2D, bool)

ControlTextStyle returns the computed font and foreground for native control text.

func ControlTextTabWidth

func ControlTextTabWidth(world *ecs.World, control ecs.Entity, text *scene.Text2D) (float32, bool)

ControlTextTabWidth resolves CSS tab-size against the control's current font.

func Dispose

func Dispose(world *ecs.World)

func HasControlForm

func HasControlForm(world *ecs.World, control ecs.Entity) bool

HasControlForm reports whether a generated control has a form owner. It also handles unnamed ancestor forms, which have an empty FormID.

func HasForm

func HasForm(world *ecs.World, owner ecs.Entity, formID string) bool

HasForm reports whether a named form exists in an HTML surface.

func NeedsFrame

func NeedsFrame(world *ecs.World) bool

NeedsFrame includes changes made after HTML synchronization. An app must flush them before suspending, even if it already consumed its render request.

func Release

func Release(world *ecs.World, owner ecs.Entity)

Release removes retained children before their owner is despawned. Call outside ECS queries and removal hooks, which forbid structural changes.

func ResetControlForm

func ResetControlForm(world *ecs.World, control ecs.Entity) bool

ResetControlForm executes the reset default action for a generated control's form owner without event dispatch.

func ResetForm

func ResetForm(world *ecs.World, owner ecs.Entity, formID string) bool

ResetForm executes the named form's reset default action without event dispatch. UI callers should use ui.ResetForm for a cancelable reset event.

func Serialize

func Serialize(world *ecs.World, page ecs.Entity) (string, error)

Serialize returns the current retained HTML document for page.

The returned string is HTML markup, rather than the diagnostic tree emitted by dom.Node.String. The retained DOM is serialized after all mutations that have already been applied to the page, so callers should run Sync after changing component state when the serialized output must include that change.

func Set

func Set(world *ecs.World, entity ecs.Entity, value string) bool

Set updates the HTML source on an existing entity. The visual tree is rebuilt by SyncSystem on the next synchronization pass.

func SetBaseCSS

func SetBaseCSS(world *ecs.World, page ecs.Entity, cssText string) bool

SetBaseCSS replaces the page stylesheet while preserving mounted component styles. Unchanged values reuse the retained stylesheet without allocation.

func SetControlActive

func SetControlActive(world *ecs.World, control ecs.Entity, active bool) bool

SetControlActive updates CSS :active for the duration of a pointer activation. The active target's element ancestors match as they do in HTML.

func SetControlChecked

func SetControlChecked(world *ecs.World, control ecs.Entity, checked bool) bool

SetControlChecked updates the live checkedness of a checkbox or radio without changing its authored checked content attribute.

func SetControlFocus

func SetControlFocus(world *ecs.World, control ecs.Entity, focused bool) bool

SetControlFocus updates CSS :focus styles for a generated control in place. Focus changes are routed through the UI runtime, so the retained DOM and generated control entities remain stable while their styles update.

func SetControlFocusVisible

func SetControlFocusVisible(world *ecs.World, control ecs.Entity, focused, focusVisible bool) bool

SetControlFocusVisible updates :focus and records whether the current input modality should also match :focus-visible.

func SetControlHover

func SetControlHover(world *ecs.World, control ecs.Entity, hovered bool) bool

SetControlHover updates CSS :hover styles for a generated control in place. It intentionally avoids changing the retained DOM or render revision, so pointer movement cannot rebuild the HTML control tree.

func SetControlOptionSelected

func SetControlOptionSelected(world *ecs.World, control ecs.Entity, option int, selected bool) bool

SetControlOptionSelected updates one option's live selectedness. Unlike selectedIndex, this preserves other selected options on a multiple select.

func SetControlSelected

func SetControlSelected(world *ecs.World, control ecs.Entity, selected int) bool

SetControlSelected updates a select option without rebuilding its HTML tree. It returns false for an invalid or disabled option.

func SetControlSelectionFocus

func SetControlSelectionFocus(world *ecs.World, control ecs.Entity, anchor, focus int) bool

SetControlSelectionFocus updates the multiple-select navigation focus without changing selectedness. A negative anchor clears the range anchor.

func SetControlSelectionRange

func SetControlSelectionRange(world *ecs.World, control ecs.Entity, anchor, focus int) bool

SetControlSelectionRange replaces a multiple select's live selectedness with the inclusive range between anchor and focus. Disabled options retain their prior state, matching Chromium user input.

func SetControlValue

func SetControlValue(world *ecs.World, control ecs.Entity, value string) bool

SetControlValue updates an editable control's live value without changing its authored value attribute or textarea child text.

func SetEditableSelection

func SetEditableSelection(world *ecs.World, editable ecs.Entity, anchor, focus int) bool

SetEditableSelection updates Selection anchor/focus rune offsets without rebuilding or allocating.

func SetEditableValue

func SetEditableValue(world *ecs.World, editable ecs.Entity, value string) bool

SetEditableValue replaces an editing host's live textContent. The DOM is retained and the next HTML synchronization pass recomputes layout.

func SetFocusableFocusVisible

func SetFocusableFocusVisible(world *ecs.World, target ecs.Entity, focused, focusVisible bool) bool

SetFocusableFocusVisible updates :focus for a generated HTML focus target.

func SetNodeOffset

func SetNodeOffset(world *ecs.World, owner ecs.Entity, id string, x, y float32) bool

SetNodeOffset moves all retained visuals generated for the element with the supplied id. The offset is applied to each visual's local transform, so updating an animation does not rebuild the HTML document or its layout. For overlapping bindings, the last registered matching offset wins; updating an existing binding preserves its registration order.

func SetNodeScroll

func SetNodeScroll(world *ecs.World, owner ecs.Entity, id string, area ecs.Entity, originX, originY float32) bool

SetNodeScroll attaches the generated visuals for an HTML element to an existing UIScroll viewport. The element's children are reparented to the viewport and clipped by its ClipRect2D; the binding is reapplied whenever the HTML visual tree is rebuilt. The first registered matching scroll binding owns each top-level visual; control and CSS clip descendants inherit it.

func SetVisualActive

func SetVisualActive(world *ecs.World, visual ecs.Entity, active bool) bool

SetVisualActive updates :active for a retained non-control HTML visual.

func SetVisualHover

func SetVisualHover(world *ecs.World, visual ecs.Entity, hovered bool) bool

SetVisualHover updates :hover for a retained non-control HTML visual.

func Sync

func Sync(world *ecs.World) error

Sync runs one HTML synchronization pass immediately.

func SyncComponentsSystem

func SyncComponentsSystem(name string) ecs.SystemConfig

SyncComponentsSystem renders dirty components before the HTML layout system runs. SyncSystem calls it internally, so applications normally only need to register the existing HTML system.

func SyncScrollContent

func SyncScrollContent(world *ecs.World)

SyncScrollContent applies HTML scroll and sticky offsets after scroll input, before global transforms and hit-test bounds are synchronized.

func SyncScrollbars

func SyncScrollbars(world *ecs.World)

SyncScrollbars updates only retained thumb geometry after UIScroll input changes. The caller runs it after UIScrollSystem and before transforms sync.

func SyncSystem

func SyncSystem(name string) ecs.SystemConfig

SyncSystem synchronizes every HTML component into ordinary ECS UI children. Register it before SyncUIGlobalTransformSystem so generated children receive their global transforms in the same frame.

func UnmountComponent

func UnmountComponent(world *ecs.World, entity ecs.Entity) bool

UnmountComponent removes the component roots, bindings, and ECS entity.

func UpdateComponentProps

func UpdateComponentProps[P, S any](world *ecs.World, entity ecs.Entity, props P) bool

UpdateComponentProps replaces typed props and schedules a render.

func UpdateComponentState

func UpdateComponentState[P, S any](world *ecs.World, entity ecs.Entity, update func(*S)) bool

UpdateComponentState applies a typed state update and schedules a render.

Types

type ActionContext

type ActionContext struct {
	Event   Event
	Current ecs.Entity
}

ActionContext is delivered synchronously before an HTML default action. PreventDefault only affects cancelable events.

func (*ActionContext) PreventDefault

func (c *ActionContext) PreventDefault()

type ActionHandler

type ActionHandler struct {
	Handle func(*ActionContext)
}

ActionHandler observes cancelable HTML events before their default action. Handlers may be installed on the generated target or HTML surface.

type Behavior

type Behavior[P, S any] struct {
	Render      func(RenderContext[P, S], *View)
	Mount       func(*ComponentContext[P, S])
	Update      func(*ComponentContext[P, S])
	Unmount     func(*ComponentContext[P, S])
	HandleEvent func(*ComponentEventContext[P, S])
}

Behavior describes the render and event logic of a component.

type ClickHandler

type ClickHandler func(*PointerEvent)

ClickHandler observes click (tap) events for one HTML node.

type Component

type Component[P, S any] struct {
	Definition *Definition[P, S]
	Props      P
	State      S
	Page       ecs.Entity
	Parent     ecs.Entity
	Key        uint64
}

Component is the typed state and props of one HTML component instance. Instances must be created with MountComponent so the page runtime can attach the type-erased render record used by the HTML component system.

type ComponentContext

type ComponentContext[P, S any] struct {
	World     *ecs.World
	Props     *P
	State     *S
	Component ecs.Entity
}

ComponentContext is passed to component lifecycle callbacks.

type ComponentEventContext

type ComponentEventContext[P, S any] struct {
	World     *ecs.World
	Pointer   *PointerEvent
	Props     *P
	State     *S
	Ref       string
	Event     Event
	Component ecs.Entity
	// contains filtered or unexported fields
}

ComponentEventContext is passed to a typed component event handler.

func (*ComponentEventContext[P, S]) DefaultPrevented

func (c *ComponentEventContext[P, S]) DefaultPrevented() bool

DefaultPrevented reports whether PreventDefault was called.

func (*ComponentEventContext[P, S]) PreventDefault

func (c *ComponentEventContext[P, S]) PreventDefault()

PreventDefault cancels the component event's default action.

func (*ComponentEventContext[P, S]) StopPropagation

func (c *ComponentEventContext[P, S]) StopPropagation()

StopPropagation consumes the pointer event so it does not reach an HTML ancestor callback.

func (*ComponentEventContext[P, S]) UpdateState

func (c *ComponentEventContext[P, S]) UpdateState(update func(*S)) bool

UpdateState mutates state and schedules one component render for the current synchronization pass. Mutating State directly is also supported; this method is useful when the update should be explicit at the call site.

type ComponentVNode

type ComponentVNode struct {
	Key uint64
	// contains filtered or unexported fields
}

ComponentVNode describes one typed child component in a component VDOM. Values are snapshots; mount/update operations are shared by the definition.

type Control

type Control struct {
	Placeholder string
	ID          string
	FormID      string
	Name        string
	Tag         string
	Type        string
	Value       string
	// DefaultValue reflects the authored value attribute or textarea text.
	DefaultValue string
	// Options contains the authored options of a select in document order.
	Options []SelectOption
	// DefaultSelected is the option selected by the authored attributes.
	DefaultSelected int
	// Selected is the live option index of a select, or -1 when no option is selected.
	Selected  int
	MaxLength int
	Owner     ecs.Entity
	// SelectionFocus is the option currently navigated by keyboard or pointer.
	SelectionFocus int
	// SelectionAnchor is the fixed option used for an extended user selection.
	SelectionAnchor int
	// RenderRevision changes when authored control data or geometry is synchronized.
	RenderRevision uint64
	// SelectedCount is the number of live selected options.
	SelectedCount int
	// PaddingBox is the area inside CSS borders, in control-local coordinates.
	// Native scrollbars run along its edges independently of text padding.
	PaddingBox scene.TextRangeRect2D
	// Checked is the live state of an input checkbox.
	Checked bool
	// DirtyValue prevents authored default changes from replacing the live value.
	DirtyValue bool
	// DirtyChecked prevents checked attribute changes from replacing live checkedness.
	DirtyChecked bool
	// DefaultChecked reflects the authored checked content attribute.
	DefaultChecked bool
	// DirtySelected reports whether any option has dirty live selectedness.
	DirtySelected bool
	// Multiple reflects the select multiple content attribute.
	Multiple bool
	// Wrap reports whether the textarea's computed white-space permits soft wrapping.
	Wrap     bool
	ReadOnly bool
	Disabled bool
	// Open reports whether a select popup is currently open.
	Open bool
}

Control identifies a form control generated by an HTML surface. The generated entity remains stable while its DOM node and control type survive.

type ControlText

type ControlText struct {
	Control ecs.Entity
	// Content is the CSS content box in the control's local coordinates.
	Content scene.TextRangeRect2D
}

ControlText links a generated text visual to its form control.

type ControlTextFont

type ControlTextFont struct{ Font *onixtext.Font }

ControlTextFont selects a native control's text face independently of its surface font. Attach it to the control so HTML reconciliation uses the same face for text, line height and CSS tab-size as the native widget.

type ControlVisual

type ControlVisual struct {
	Control   ecs.Entity
	Kind      ControlVisualKind
	Selection bool
	Index     int
}

ControlVisual links a generated caret, selection, or scrollbar visual to its form control. Selection remains separate because textareas reserve several indexed selection surfaces.

type ControlVisualKind

type ControlVisualKind uint8

ControlVisualKind identifies generated form-control visuals whose geometry and style are supplied by the UI runtime.

const (
	ControlVisualCaret ControlVisualKind = iota
	ControlVisualScrollTrackHorizontal
	ControlVisualScrollTrackVertical
	ControlVisualScrollThumbHorizontal
	ControlVisualScrollThumbVertical
)

type Definition

type Definition[P, S any] struct {
	Behavior Behavior[P, S]

	Template Template
	CSS      string
	// ScopedCSS isolates this definition's selectors and template elements.
	ScopedCSS bool
	// contains filtered or unexported fields
}

Definition is a compiled, reusable component definition.

func Define

func Define[P, S any](template Template, cssText string, behavior Behavior[P, S]) (*Definition[P, S], error)

Define parses and compiles an HTML component definition.

func DefineScoped

func DefineScoped[P, S any](template Template, cssText string, behavior Behavior[P, S]) (*Definition[P, S], error)

DefineScoped creates a component whose template elements and stylesheet are isolated by a stable, definition-level scope class.

func (*Definition[P, S]) ComponentChild

func (definition *Definition[P, S]) ComponentChild(key uint64, props P, state S) ComponentVNode

ComponentChild creates a keyed child component VNode for a slot.

func (*Definition[P, S]) DefineScopedChild

func (parent *Definition[P, S]) DefineScopedChild[CP, CS any](template Template, behavior Behavior[CP, CS]) (*Definition[CP, CS], error)

DefineScopedChild compiles content in its parent's CSS scope. The parent retains the stylesheet, so replacing child templates does not republish CSS.

func (*Definition[P, S]) HydrateComponent

func (definition *Definition[P, S]) HydrateComponent(world *ecs.World, page ecs.Entity, props P, state S, key uint64) (ecs.Entity, error)

HydrateComponent adopts one matching component root sequence already retained by the page DOM. The sequence must be unique among the page's direct children; dynamic values are reconciled on the first Sync pass.

func (*Definition[P, S]) HydrateComponentInto

func (definition *Definition[P, S]) HydrateComponentInto(world *ecs.World, parent ecs.Entity, slot string, props P, state S, key uint64) (ecs.Entity, error)

HydrateComponentInto adopts one matching child root sequence already present in a component slot. It preserves the existing DOM node identity.

func (*Definition[P, S]) MountComponent

func (definition *Definition[P, S]) MountComponent(world *ecs.World, page ecs.Entity, props P, state S, key uint64) (ecs.Entity, error)

MountComponent appends a component's template roots to a page HTML document and creates the typed ECS component instance.

func (*Definition[P, S]) MountComponentInto

func (definition *Definition[P, S]) MountComponentInto(world *ecs.World, parent ecs.Entity, slot string, props P, state S, key uint64) (ecs.Entity, error)

MountComponentInto mounts a child component into a data-ref element of an existing component. The child remains an independent ECS entity while its roots participate in the parent's DOM subtree.

type Editable

type Editable struct {
	ID             string
	Value          string
	RenderRevision uint64
	Owner          ecs.Entity
	Anchor         int
	Focus          int
}

Editable is the live plaintext and Selection state of a contenteditable editing host. Anchor and Focus are rune offsets in Value.

type EditableText

type EditableText struct {
	Editable ecs.Entity
}

EditableText links the flattened live text visual of an editing host.

type EditableVisual

type EditableVisual struct {
	Editable  ecs.Entity
	Selection bool
	Index     int
}

EditableVisual links caret and selection visuals to an editing host.

type Event

type Event struct {
	Snapshot piecetree.Snapshot
	Value    string
	// InputType identifies the beforeinput/input editing operation.
	InputType string
	Data      string
	ID        string
	FormID    string
	Name      string
	Kind      EventKind
	// SelectedCount allows allocation-free multiple-select event inspection.
	SelectedCount    int
	Entity           ecs.Entity
	Selected         int
	Target           ecs.Entity
	Anchor           int
	Focus            int
	Checked          bool
	Document         bool
	Bubbles          bool
	Cancelable       bool
	DefaultPrevented bool
}

Event is emitted for generated interactive HTML elements. Entity is the HTML surface, while Target is the generated input entity when present.

func DispatchAction

func DispatchAction(world *ecs.World, event Event) Event

DispatchAction synchronously dispatches an event to its generated target and then its HTML surface. It performs no allocation after ECS warmup.

type EventKind

type EventKind string

EventKind identifies a browser-style event emitted by an HTML control.

const (
	EventClick       EventKind = "click"
	EventBeforeInput EventKind = "beforeinput"
	EventInput       EventKind = "input"
	EventChange      EventKind = "change"
	EventSubmit      EventKind = "submit"
	EventReset       EventKind = "reset"
	EventFocus       EventKind = "focus"
	EventBlur        EventKind = "blur"
)

type FallbackReason

type FallbackReason string

FallbackReason identifies why retained paint could not be updated locally.

const (
	FallbackNone        FallbackReason = ""
	FallbackInitial     FallbackReason = "initial-document"
	FallbackDocument    FallbackReason = "document-replaced"
	FallbackEnvironment FallbackReason = "render-environment"
	FallbackImages      FallbackReason = "image-provider"
	FallbackLayout      FallbackReason = "layout-requested"
	FallbackVisual      FallbackReason = "visual-requested"
	FallbackRetained    FallbackReason = "retained-paint-invalid"
	FallbackVisibility  FallbackReason = "visibility-changed"
	FallbackContract    FallbackReason = "control-or-event-contract"
	FallbackStructure   FallbackReason = "structure-ownership"
	FallbackBox         FallbackReason = "box-ownership"
	FallbackContext     FallbackReason = "context-ownership"
	FallbackStack       FallbackReason = "stacking-ownership"
)

type FocusOwner

type FocusOwner struct {
	Entity ecs.Entity
}

FocusOwner links a rendered descendant to the HTML element that should receive pointer focus without changing the descendant's event target.

type Focusable

type Focusable struct {
	ID           string
	Tag          string
	Type         string
	Owner        ecs.Entity
	TabIndex     int
	Order        uint32
	Sequential   bool
	Pointer      bool
	AutoFocus    bool
	FocusVisible bool
}

Focusable describes an HTML element's focus behavior independently from whether the element is a form control.

type ImageProvider

type ImageProvider interface {
	ResolveHTMLImage(source string, width, height float32) (*graphics.Texture, bool)
}

ImageProvider resolves an img src into an engine texture. Applications can install one as a resource when HTML pages reference project assets. Width and height are the laid-out CSS size before surface transforms and DPI.

type Images

type Images struct{ Provider ImageProvider }

Images binds an immutable image provider to one surface. Its owner resolves relative URLs without exposing a global asset namespace.

type Layout

type Layout struct {
	Width  float32
	Height float32
}

Layout is the computed size of an HTML surface.

func Bounds

func Bounds(world *ecs.World, entity ecs.Entity) (Layout, bool)

Bounds returns the current synchronized surface size.

type Node

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

Node is a mutable node owned by an HTML surface. Mutations are rendered by the next HTML synchronization pass.

func NodeByID

func NodeByID(world *ecs.World, owner ecs.Entity, id string) (Node, bool)

NodeByID finds the first element with id within an HTML surface.

func Root

func Root(world *ecs.World, owner ecs.Entity) (Node, error)

Root returns the retained document root for an HTML surface.

func (Node) Append

func (n Node) Append(child Node) bool

Append appends a detached node as the last child.

func (Node) Attribute

func (n Node) Attribute(name string) (string, bool)

Attribute returns an element's current authored attribute without serializing it.

func (Node) Bounds

func (n Node) Bounds() (Rect, bool)

Bounds returns the last synchronized layout border box. Hidden or detached nodes have no box. Native window hit testing can use this without duplicating CSS layout. Surface transforms and runtime scroll/animation offsets are not included.

func (Node) Clear

func (n Node) Clear() bool

Clear removes all child nodes.

func (Node) Clone

func (n Node) Clone() Node

Clone returns a detached deep copy owned by the same HTML surface.

func (Node) FindByID

func (n Node) FindByID(id string) (Node, bool)

FindByID finds the first descendant element with id.

func (Node) OnClick

func (n Node) OnClick(handler ClickHandler) bool

OnClick binds a native click callback to this HTML node. It runs for tap events after the pointer callback, when one is installed. Passing nil removes the click callback.

func (Node) OnPointer

func (n Node) OnPointer(handler PointerHandler) bool

OnPointer binds a native pointer callback to this HTML node. The callback receives enter/leave/press/move/release/wheel/cancel and tap events. Passing nil removes the pointer callback.

func (Node) Remove

func (n Node) Remove() bool

Remove detaches the node from its parent.

func (Node) RemoveAttribute

func (n Node) RemoveAttribute(name string) bool

RemoveAttribute removes an element attribute.

func (Node) ScrollContainer

func (n Node) ScrollContainer() (ecs.Entity, bool)

ScrollContainer returns the node's synchronized overflow scroll entity, including when its content is outside the visible paint area.

func (Node) Serialize

func (n Node) Serialize() (string, error)

Serialize serializes this retained node and all of its descendants as HTML markup. Root is the usual entry point when the whole page is needed.

func (Node) SetAttribute

func (n Node) SetAttribute(name, value string) bool

SetAttribute sets an element attribute.

func (Node) SetHidden

func (n Node) SetHidden(hidden bool) bool

SetHidden controls the standard hidden attribute.

func (Node) SetSelectedIndex

func (n Node) SetSelectedIndex(selected int) bool

SetSelectedIndex writes the live selection, preserving authored defaults. It also works before the first render or while option text is being updated.

func (Node) SetText

func (n Node) SetText(value string) bool

SetText replaces the node contents with one text node.

type Option

type Option = SelectOption

Option is kept as a concise name for callers that inspect select options.

type PointerEvent

type PointerEvent struct {
	Target  Node
	Kind    scene.InputEventKind
	X       float32
	Y       float32
	DeltaX  float32
	DeltaY  float32
	WheelX  float32
	WheelY  float32
	Handled bool
}

PointerEvent is delivered to a callback bound directly to an HTML node. Kind contains the pointer lifecycle event; a click callback receives the same event with Kind set to InputEventTap.

func (*PointerEvent) Consume

func (e *PointerEvent) Consume()

Consume prevents the input event from bubbling to an ancestor.

type PointerHandler

type PointerHandler func(*PointerEvent)

PointerHandler observes pointer lifecycle events for one HTML node.

type Rect

type Rect struct{ X, Y, Width, Height float32 }

Rect is an element's CSS border box in its HTML surface's coordinates.

type RenderContext

type RenderContext[P, S any] struct {
	World     *ecs.World
	Props     *P
	State     *S
	Component ecs.Entity
}

RenderContext is passed by value to Render. Props and State point to the component instance; copying the context does not copy its props or state.

type ScrollContent

type ScrollContent struct {
	Area ecs.Entity
	X    float32
	Y    float32
	// contains filtered or unexported fields
}

ScrollContent links a generated HTML subtree to a UIScroll viewport. X and Y preserve the subtree's unscrolled local origin while the UI runtime applies the current UIScroll offset after input handling. Sticky content can use Area == 0 when only its sticky offset is needed.

type ScrollStyle

type ScrollStyle struct {
	BarSize                 float32
	DisableHorizontalScroll bool
	Hidden                  bool
	HasTrackColor           bool
	HasThumbColor           bool
	HasThumbHoverColor      bool
	TrackColor              graphics.ColorRGBA
	ThumbColor              graphics.ColorRGBA
	ThumbHoverColor         graphics.ColorRGBA
}

ScrollStyle contains the scrollbar values computed for an HTML node. Has*Color distinguishes authored colors (including transparent) from auto. BarSize matches CSS overflow scrollbars. Hidden records scrollbar-width:none, which suppresses painting while scrolling remains available.

func ControlScrollStyle

func ControlScrollStyle(world *ecs.World, control ecs.Entity) (ScrollStyle, bool)

ControlScrollStyle returns the scrollbar style computed for a generated form control. Unlike NodeScrollStyle, it also supports controls without an id attribute.

func NodeScrollStyle

func NodeScrollStyle(world *ecs.World, owner ecs.Entity, id string) (ScrollStyle, bool)

NodeScrollStyle returns scrollbar styling computed for an element. It supports the standard scrollbar-width and scrollbar-color declarations plus the track/thumb overrides used by native UI widgets.

type ScrollbarPart

type ScrollbarPart struct {
	Area ecs.Entity
	Axis uint8
	Kind uint8
}

ScrollbarPart is one retained visual of a CSS overflow scrollbar. Axis is 0 for horizontal and 1 for vertical; Kind is track or thumb. The part is kept separate from UIScroll so input and painting can evolve independently while the entity identity remains stable across HTML syncs.

type SelectOption

type SelectOption struct {
	Value           string
	Label           string
	Disabled        bool
	Selected        bool
	DefaultSelected bool
	DirtySelected   bool
}

SelectOption is one authored option of an HTML select control.

type Surface

type Surface struct {
	Font *onixtext.Font
	// BoldFont is used for text whose computed font weight is 600 or heavier.
	BoldFont *onixtext.Font
	// Document transfers an independently owned DOM to the surface. Replacing
	// the pointer replaces the document; mutate retained nodes through Root.
	Document   *dom.Node
	Images     *Images
	CSS        string
	Value      string
	FontSize   float64
	DPI        float64
	StackIndex int
	Height     float32
	Width      float32
	// ReserveScrollbarSpace selects classic scrollbars, reducing the content viewport.
	ReserveScrollbarSpace bool
	PassThrough           bool
}

Surface is a retained HTML surface. Value may contain regular HTML and inline <style> elements. CSS contains an optional stylesheet applied to the value. Width and Height use UI pixels; zero resolves to the current viewport size.

func New

func New(value string) Surface

New creates an HTML component with browser-like default text metrics.

type SyncDiagnostics

type SyncDiagnostics struct {
	Path     SyncPath
	Fallback FallbackReason
}

SyncDiagnostics describes the last sync, including a stable full-update reason. Reading diagnostics does not invalidate the surface or allocate.

func Diagnostics

func Diagnostics(world *ecs.World, owner ecs.Entity) SyncDiagnostics

type SyncPath

type SyncPath string

SyncPath identifies the completed incremental update path.

const (
	SyncCached  SyncPath = "cached"
	SyncEvents  SyncPath = "events"
	SyncStyle   SyncPath = "style"
	SyncPartial SyncPath = "partial"
	SyncFull    SyncPath = "full"
)

type Template

type Template struct {
	Source string
	// contains filtered or unexported fields
}

Template is the immutable source of a component view. Its compiled DOM is reused by every component instance; mounting clones it before applying changes.

func NewDocumentTemplate added in v0.1.4

func NewDocumentTemplate(document *dom.Node) (Template, error)

NewDocumentTemplate takes ownership of a parsed document without serializing or parsing it again. The caller may retain read-only node references but must not mutate the document after this call. Embedded styles are extracted just as they are for source templates.

func NewTemplate

func NewTemplate(source string) Template

NewTemplate creates a component template from an HTML fragment.

type VNode

type VNode struct {
	Tag        string
	Text       string
	Attributes []VNodeAttribute
	Children   []VNode
	Key        uint64
}

VNode describes one keyed element child. Children may contain nested keyed elements and are reconciled in place with the same DOM identity rules.

func TextVNode

func TextVNode(key uint64, tag, text string) VNode

TextVNode creates a keyed text-bearing element node.

func VNodeElement

func VNodeElement(key uint64, tag string, attributes []VNodeAttribute, children []VNode) VNode

VNodeElement creates a keyed element with nested VNode children.

type VNodeAttribute

type VNodeAttribute struct {
	Name  string
	Value string
}

VNodeAttribute is one attribute on a keyed VNode child.

type View

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

View writes dynamic values into the component's next VDOM buffer. References come from data-ref attributes in the compiled template.

func (*View) AppendComponentChild

func (v *View) AppendComponentChild[P, S any](slot string, key uint64, definition *Definition[P, S], props P, state S) bool

AppendComponentChild appends a typed child directly to a View slot for this render. The slot owns its parameter buffers and reuses them on later renders. Call order determines child order; omitting a child on a render unmounts it.

func (*View) Attr

func (v *View) Attr(ref, name, value string) bool

Attr updates an element attribute binding identified by data-ref.

func (*View) Components

func (v *View) Components(slot string, nodes []ComponentVNode) bool

Components declares keyed child component instances rendered into a slot. Omitting a slot on a later render unmounts its previous children.

func (*View) Event

func (v *View) Event(ref string, kind EventKind) bool

Event enables a browser-style event binding identified by data-ref. Pointer clicks are delivered during input dispatch; native control events are delivered from the retained HTML event stream before the next render pass.

func (*View) Keyed

func (v *View) Keyed(ref string, nodes []VNode) bool

Keyed reconciles element children under a data-ref container. Existing DOM nodes are matched by Key and moved in place, preserving their DOM identity.

func (*View) PatchBindings

func (v *View) PatchBindings()

PatchBindings updates only the Text, Attr, RemoveAttr and Keyed bindings written by this render. Omitted bindings retain their ownership. Events and component lists require an ordinary render.

func (*View) RemoveAttr

func (v *View) RemoveAttr(ref, name string) bool

RemoveAttr removes an element attribute from a dynamic binding.

func (*View) Text

func (v *View) Text(ref, value string) bool

Text updates a text binding identified by data-ref.

Jump to

Keyboard shortcuts

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